Remove code for protocols we don't properly support. (Most of this could
[oweals/busybox.git] / networking / dnsd.c
index 433b124430c696ba4b7b09e679a22686116e21be..b9d022170808f709357f01a7d7c171ec75880059 100644 (file)
@@ -1,9 +1,11 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Mini DNS server implementation for busybox
  *
  * Copyright (C) 2005 Roberto A. Foglietta (me@roberto.foglietta.name)
  * Copyright (C) 2005 Odd Arild Olsen (oao at fibula dot no)
  * Copyright (C) 2003 Paul Sheer
+ *
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  *
  * Odd Arild Olsen started out with the sheerdns [1] of Paul Sheer and rewrote
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <ctype.h>
-#include "libbb.h"
+#include "busybox.h"
 
 static char *fileconf = "/etc/dnsd.conf";
 #define LOCK_FILE       "/var/run/dnsd.lock"
 #define LOG_FILE        "/var/log/dnsd.log"
 
-#define  MAX_HOST_LEN 16        // longest host name allowed is 15
-#define IP_STRING_LEN 18        // .xxx.xxx.xxx.xxx\0
+enum {
+       MAX_HOST_LEN = 16,      // longest host name allowed is 15
+       IP_STRING_LEN = 18,     // .xxx.xxx.xxx.xxx\0
 
 //must be strlen('.in-addr.arpa') larger than IP_STRING_LEN
-static const int MAX_NAME_LEN = (IP_STRING_LEN + 13);
+       MAX_NAME_LEN = (IP_STRING_LEN + 13),
 
 /* Cannot get bigger packets than 512 per RFC1035
    In practice this can be set considerably smaller:
@@ -39,12 +42,13 @@ static const int MAX_NAME_LEN = (IP_STRING_LEN + 13);
    ttl(4B) + rlen(2B) + r (MAX_NAME_LEN =21B) +
    2*querystring (2 MAX_NAME_LEN= 42B), all together 90 Byte
 */
-static const int MAX_PACK_LEN = 512 + 1;
+       MAX_PACK_LEN = 512 + 1,
 
-#define  DEFAULT_TTL 30;        // increase this when not testing?
+       DEFAULT_TTL = 30,       // increase this when not testing?
 
-static const int REQ_A = 1;
-static const int REQ_PTR = 12;
+       REQ_A = 1,
+       REQ_PTR = 12
+};
 
 struct dns_repl {              // resource record, add 0 or 1 to accepted dns_msg in resp
        uint16_t rlen;
@@ -202,8 +206,7 @@ listen_socket(char *iface_addr, int listen_port)
        char msg[100];
        int s;
        int yes = 1;
-       if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
-               bb_perror_msg_and_die("socket() failed");
+       s = bb_xsocket(PF_INET, SOCK_DGRAM, 0);
 #ifdef SO_REUSEADDR
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0)
                bb_perror_msg_and_die("setsockopt() failed");
@@ -213,9 +216,8 @@ listen_socket(char *iface_addr, int listen_port)
        a.sin_family = AF_INET;
        if (!inet_aton(iface_addr, &a.sin_addr))
                bb_perror_msg_and_die("bad iface address");
-       if (bind(s, (struct sockaddr *)&a, sizeof(a)) < 0)
-               bb_perror_msg_and_die("bind() failed");
-       listen(s, 50);
+       bb_xbind(s, (struct sockaddr *)&a, sizeof(a));
+       listen(s, 50); /* bb_xlisten? */
        sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
                iface_addr, (int)listen_port);
        log_message(LOG_FILE, msg);
@@ -406,9 +408,7 @@ int dnsd_main(int argc, char **argv)
                /* reexec for vfork() do continue parent */
                vfork_daemon_rexec(1, 0, argc, argv, "-d");
 #else                                                  /* uClinux */
-               if (daemon(1, 0) < 0) {
-                       bb_perror_msg_and_die("daemon");
-               }
+               bb_xdaemon(1, 0);
 #endif                                                 /* uClinuvx */
 
        dnsentryinit(is_verbose());