add good bye messages
[project/mdnsd.git] / interface.c
index 1584c24..1b846d1 100644 (file)
@@ -38,6 +38,7 @@
 #include "util.h"
 #include "dns.h"
 #include "announce.h"
+#include "service.h"
 
 static int
 interface_send_packet4(struct interface *iface, struct iovec *iov, int iov_len)
@@ -378,6 +379,9 @@ reconnect_socket4(struct uloop_timeout *timeout)
                goto retry;
        }
 
+       if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->name, strlen(iface->name) < 0))
+               fprintf(stderr, "ioctl failed: SO_BINDTODEVICE\n");
+
        if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
                fprintf(stderr, "ioctl failed: SO_REUSEADDR\n");
 
@@ -419,6 +423,9 @@ reconnect_socket6(struct uloop_timeout *timeout)
                goto retry;
        }
 
+       if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->name, strlen(iface->name) < 0))
+               fprintf(stderr, "ioctl failed: SO_BINDTODEVICE\n");
+
        if (setsockopt(iface->fd.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0)
                fprintf(stderr, "ioctl failed: IPV6_UNICAST_HOPS\n");
 
@@ -578,4 +585,17 @@ int interface_add(const char *name)
        return !v4 && !v6;
 }
 
+void interface_shutdown(void)
+{
+       struct interface *iface;
+
+       vlist_for_each_element(&interfaces, iface, node)
+               if (iface->fd.fd > 0 && iface->multicast) {
+                       service_announce(iface, 0);
+                       service_reply_a(iface, 0);
+               }
+       vlist_for_each_element(&interfaces, iface, node)
+               interface_free(iface);
+}
+
 VLIST_TREE(interfaces, avl_strcmp, iface_update_cb, false, false);