xatonum.h: add comment
[oweals/busybox.git] / networking / dnsd.c
index fd2f421d71a85ec8926727ea47b9970b848ae6c1..8f01d5c06f2b0738cc28fb422deb4d2810777821 100644 (file)
@@ -17,7 +17,8 @@
  * the first porting of oao' scdns to busybox also.
  */
 
-#include "busybox.h"
+#include <syslog.h>
+#include "libbb.h"
 
 //#define DEBUG 1
 #define DEBUG 0
@@ -114,7 +115,6 @@ static void undot(uint8_t * rip)
  * Presently the dot is copied into name without
  * converting to a length/string substring for that label.
  */
-
 static int getfileentry(FILE * fp, struct dns_entry *s)
 {
        unsigned int a,b,c,d;
@@ -238,12 +238,12 @@ static int process_packet(uint8_t * buf)
        head = (struct dns_head *)buf;
        if (head->nquer == 0) {
                bb_error_msg("no queries");
-               retunr -1;
+               return -1;
        }
 
        if (head->flags & 0x8000) {
                bb_error_msg("ignoring response packet");
-               retunr -1;
+               return -1;
        }
 
        from = (void *)&head[1];        //  start of query string
@@ -328,7 +328,7 @@ static void interrupt(int x)
        exit(2);
 }
 
-int dnsd_main(int argc, char **argv);
+int dnsd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int dnsd_main(int argc, char **argv)
 {
        const char *listen_interface = "0.0.0.0";
@@ -338,7 +338,7 @@ int dnsd_main(int argc, char **argv)
        uint16_t port = 53;
        uint8_t buf[MAX_PACK_LEN];
 
-       getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
+       getopt32(argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
        //if (option_mask32 & 0x1) // -i
        //if (option_mask32 & 0x2) // -c
        if (option_mask32 & 0x4) // -t
@@ -353,12 +353,8 @@ int dnsd_main(int argc, char **argv)
        }
 
        if (OPT_daemon) {
-#ifdef BB_NOMMU
-               if (!re_execed)
-                       vfork_daemon_rexec(1, 0, argv);
-#else
-               xdaemon(1, 0);
-#endif
+               bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
+               openlog(applet_name, LOG_PID, LOG_DAEMON);
                logmode = LOGMODE_SYSLOG;
        }
 
@@ -379,7 +375,7 @@ int dnsd_main(int argc, char **argv)
        xbind(udps, &lsa->sa, lsa->len);
        /* xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? */
        bb_info_msg("Accepting UDP packets on %s",
-                       xmalloc_sockaddr2dotted(&lsa->sa, lsa->len));
+                       xmalloc_sockaddr2dotted(&lsa->sa));
 
        while (1) {
                int r;
@@ -401,4 +397,5 @@ int dnsd_main(int argc, char **argv)
                        continue;
                sendto(udps, buf, r, 0, &lsa->sa, fromlen);
        }
+       return 0;
 }