From e83fa01d8add031a844e0bcbb69831c2046c7cfa Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Wed, 9 Nov 2005 18:38:57 +0000 Subject: [PATCH] * add support for IP_SENDSRCADDR on freeBSD git-svn-id: file:///home/lennart/svn/public/avahi/trunk@945 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/socket.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/avahi-core/socket.c b/avahi-core/socket.c index a84a3d9..cd5241d 100644 --- a/avahi-core/socket.c +++ b/avahi-core/socket.c @@ -457,6 +457,9 @@ int avahi_send_dns_packet_ipv4(int fd, AvahiIfIndex interface, AvahiDnsPacket *p #ifdef IP_PKTINFO struct cmsghdr *cmsg; uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in_pktinfo))]; +#elif defined(IP_SENDSRCADDR) + struct cmsghdr *cmsg; + uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in_addr))]; #endif assert(fd >= 0); @@ -503,10 +506,29 @@ int avahi_send_dns_packet_ipv4(int fd, AvahiIfIndex interface, AvahiDnsPacket *p msg.msg_control = cmsg_data; msg.msg_controllen = sizeof(cmsg_data); } +#elif defined(IP_SENDSRCADDR) + if (src_address) { + struct in_addr *addr; + + memset(cmsg_data, 0, sizeof(cmsg_data)); + cmsg = (struct cmsghdr*) cmsg_data; + cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr)); + cmsg->cmsg_level = IPPROTO_IP; + cmsg->cmsg_type = IP_SENDSRCADDR; + + addr = (struct in_addr *)CMSG_DATA(cmsg); + addr->s_addr = src_address->address; + + msg.msg_control = cmsg_data; + msg.msg_controllen = sizeof(cmsg_data); + } #elif defined(IP_MULTICAST_IF) - if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &(src_address->address), sizeof(src_address->address)) < 0) { - avahi_log_warn("IP_MULTICAST_IF failed: %s", strerror(errno)); - return -1; + { + struct in_addr any = { INADDR_ANY }; + if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, src_address ? (const void*) &src_address->address : (const void*) &any, sizeof(struct in_addr)) < 0) { + avahi_log_warn("IP_MULTICAST_IF failed: %s", strerror(errno)); + return -1; + } } #elif defined(__GNUC__) #warning "FIXME: We need some code to set the outgoing interface/local address here if IP_PKTINFO/IP_MULTICAST_IF is not available" -- 2.39.5