+#define BUFSIZE 1023
+static int serveConnection (int conn)
+{
+ char buf[ BUFSIZE + 1 ];
+ int n_read;
+
+ while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
+
+ int pri = (LOG_USER | LOG_NOTICE);
+ char line[ BUFSIZE + 1 ];
+ unsigned char c;
+
+ char *p = buf, *q = line;
+
+ buf[ n_read - 1 ] = '\0';
+
+ while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
+ if (c == '<') {
+ /* Parse the magic priority number. */
+ pri = 0;
+ while (isdigit (*(++p))) {
+ pri = 10 * pri + (*p - '0');
+ }
+ if (pri & ~(LOG_FACMASK | LOG_PRIMASK)){
+ pri = (LOG_USER | LOG_NOTICE);
+ }
+ } else if (c == '\n') {
+ *q++ = ' ';
+ } else if (iscntrl (c) && (c < 0177)) {
+ *q++ = '^';
+ *q++ = c ^ 0100;
+ } else {
+ *q++ = c;
+ }
+ p++;
+ }
+ *q = '\0';
+ /* Now log it */
+ logMessage (pri, line);
+ }
+ return (0);
+}
+
+
+#ifdef BB_FEATURE_REMOTE_LOG
+static void init_RemoteLog (void){
+
+ struct sockaddr_in remoteaddr;
+ struct hostent *hostinfo;
+ int len = sizeof(remoteaddr);
+
+ bzero(&remoteaddr, len);
+
+ remotefd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (remotefd < 0) {
+ fatalError("syslogd: cannot create socket\n");
+ }
+
+ hostinfo = (struct hostent *) gethostbyname(RemoteHost);
+
+ if (!hostinfo) {
+ fatalError("syslogd: cannot resolve remote host name [%s]\n", RemoteHost);
+ }
+
+ remoteaddr.sin_family = AF_INET;
+ remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
+ remoteaddr.sin_port = htons(RemotePort);
+
+ /*
+ Since we are using UDP sockets, connect just sets the default host and port
+ for future operations
+ */
+ if ( 0 != (connect(remotefd, (struct sockaddr *) &remoteaddr, len))){
+ fatalError("syslogd: cannot connect to remote host %s:%d\n", RemoteHost, RemotePort);
+ }
+
+}
+#endif
+