summaryrefslogtreecommitdiffstats
path: root/avahi-core
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2005-11-09 18:38:57 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2005-11-09 18:38:57 +0000
commite83fa01d8add031a844e0bcbb69831c2046c7cfa (patch)
treed342e8c4e5151157eb22bae151a8edaa0a8cc8d8 /avahi-core
parentc9e524f6df52d531e13d55044a18f72437cf8274 (diff)
* add support for IP_SENDSRCADDR on freeBSD
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@945 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core')
-rw-r--r--avahi-core/socket.c28
1 files 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"