fix potential null pointer deref when packets are forged
[project/mdnsd.git] / main.c
diff --git a/main.c b/main.c
index f07b9e6..f559c19 100644 (file)
--- a/main.c
+++ b/main.c
@@ -25,7 +25,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/nameser.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/nameser.h>
-#include <asm/byteorder.h>
 
 #include <libubus.h>
 #include <libubox/uloop.h>
 
 #include <libubus.h>
 #include <libubox/uloop.h>
 #include "announce.h"
 #include "interface.h"
 
 #include "announce.h"
 #include "interface.h"
 
-char *iface_name = "eth0";
+static void
+signal_shutdown(int signal)
+{
+       uloop_end();
+}
 
 int
 main(int argc, char **argv)
 {
        int ch, ttl;
 
 
 int
 main(int argc, char **argv)
 {
        int ch, ttl;
 
+       uloop_init();
+
        while ((ch = getopt(argc, argv, "t:i:d")) != -1) {
                switch (ch) {
                case 't':
        while ((ch = getopt(argc, argv, "t:i:d")) != -1) {
                switch (ch) {
                case 't':
@@ -58,22 +63,16 @@ main(int argc, char **argv)
                        debug++;
                        break;
                case 'i':
                        debug++;
                        break;
                case 'i':
-                       iface_name = optarg;
+                       interface_add(optarg);
                        break;
                        break;
+               default:
+                       return -1;
                }
        }
 
                }
        }
 
-       if (!iface_name)
-               return -1;
-
-       uloop_init();
-
-       if (interface_add(iface_name)) {
-               fprintf(stderr, "Failed to add interface %s\n", iface_name);
-               return -1;
-       }
-
-       signal_setup();
+       signal(SIGPIPE, SIG_IGN);
+       signal(SIGTERM, signal_shutdown);
+       signal(SIGKILL, signal_shutdown);
 
        if (cache_init())
                return -1;
 
        if (cache_init())
                return -1;