Don't call dns_reply_a from service_reply
[project/mdnsd.git] / util.c
diff --git a/util.c b/util.c
index 0c4a4ee..63f1612 100644 (file)
--- a/util.c
+++ b/util.c
@@ -16,8 +16,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
-#include <linux/if.h>
-#include <linux/sockios.h>
 #include <arpa/inet.h>
 
 #include <unistd.h>
 #include <signal.h>
 
 #include <libubox/uloop.h>
+#include <libubox/utils.h>
 
 #include "dns.h"
 #include "util.h"
 
+uint8_t mdns_buf[MDNS_BUF_LEN];
 int debug = 0;
 
-static void
-signal_shutdown(int signal)
-{
-       uloop_end();
-}
-
-void
-signal_setup(void)
-{
-       signal(SIGPIPE, SIG_IGN);
-       signal(SIGTERM, signal_shutdown);
-       signal(SIGKILL, signal_shutdown);
-}
+char mdns_hostname[HOSTNAME_LEN];
+char mdns_hostname_local[HOSTNAME_LEN + 6];
 
 uint32_t
 rand_time_delta(uint32_t t)
@@ -72,24 +61,23 @@ rand_time_delta(uint32_t t)
        return val;
 }
 
-char*
-get_hostname(void)
+void get_hostname(void)
 {
-       static struct utsname utsname;
+       struct utsname utsname;
+
+       mdns_hostname[0] = 0;
+       mdns_hostname_local[0] = 0;
 
        if (uname(&utsname) < 0)
-               return NULL;
+               return;
 
-       return utsname.nodename;
+       snprintf(mdns_hostname, sizeof(mdns_hostname), "%s", utsname.nodename);
+       snprintf(mdns_hostname_local, sizeof(mdns_hostname_local), "%s.local", utsname.nodename);
 }
 
-void*
-memdup(const void *d, int l)
+time_t monotonic_time(void)
 {
-       void *r = malloc(l);
-       if (!r)
-               return NULL;
-       memcpy(r, d, l);
-       return r;
+       struct timespec ts;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+       return ts.tv_sec;
 }
-