]> git.meshlink.io Git - catta/commitdiff
* add support for IP_SENDSRCADDR on freeBSD
authorSebastien Estienne <sebastien.estienne@gmail.com>
Wed, 9 Nov 2005 18:38:57 +0000 (18:38 +0000)
committerSebastien Estienne <sebastien.estienne@gmail.com>
Wed, 9 Nov 2005 18:38:57 +0000 (18:38 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@945 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/socket.c

index a84a3d9a87ed1da720b2f933046cee03bace8322..cd5241df8d3aa9334152d8b5b01999c66da0f777 100644 (file)
@@ -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"