#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)
int
interface_send_packet(struct interface *iface, struct iovec *iov, int iov_len)
{
+ if (debug > 1) {
+ fprintf(stderr, "TX ipv%d: %s\n", iface->v6 * 2 + 4, iface->name);
+ fprintf(stderr, " multicast: %d\n", iface->multicast);
+ }
+
if (iface->v6)
return interface_send_packet6(iface, iov, iov_len);
if (debug > 1) {
char buf[256];
- fprintf(stderr, "iface: %s\n", iface->name);
- fprintf(stderr, " v6: %d\n", iface->v6);
+ fprintf(stderr, "RX ipv4: %s\n", iface->name);
fprintf(stderr, " multicast: %d\n", iface->multicast);
inet_ntop(AF_INET, &from.sin_addr, buf, 256);
fprintf(stderr, " src %s:%d\n", buf, from.sin_port);
if (inp->ipi_ifindex != iface->ifindex)
fprintf(stderr, "invalid iface index %d != %d\n", ifindex, iface->ifindex);
else
- dns_handle_packet(iface, buffer, len, 0);
+ dns_handle_packet(iface, (struct sockaddr *) &from, from.sin_port, buffer, len);
}
static void
if (debug > 1) {
char buf[256];
- fprintf(stderr, "iface: %s\n", iface->name);
- fprintf(stderr, " v6: %d\n", iface->v6);
+ fprintf(stderr, "RX ipv6: %s\n", iface->name);
fprintf(stderr, " multicast: %d\n", iface->multicast);
inet_ntop(AF_INET6, &from.sin6_addr, buf, 256);
fprintf(stderr, " src %s:%d\n", buf, from.sin6_port);
if (inp->ipi6_ifindex != iface->ifindex)
fprintf(stderr, "invalid iface index %d != %d\n", ifindex, iface->ifindex);
else
- dns_handle_packet(iface, buffer, len, 0);
+ dns_handle_packet(iface, (struct sockaddr *) &from, from.sin6_port, buffer, len);
}
static int
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");
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");
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_close(iface);
+}
+
VLIST_TREE(interfaces, avl_strcmp, iface_update_cb, false, false);