4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
37 #include <sys/ioctl.h>
41 #include <net/if_dl.h>
49 /* this is a portability hack */
50 #ifndef IPV6_ADD_MEMBERSHIP
51 #ifdef IPV6_JOIN_GROUP
52 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
56 #ifndef IPV6_DROP_MEMBERSHIP
57 #ifdef IPV6_LEAVE_GROUP
58 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
62 static void mdns_mcast_group_ipv4(struct sockaddr_in *ret_sa) {
65 memset(ret_sa, 0, sizeof(struct sockaddr_in));
66 ret_sa->sin_family = AF_INET;
67 ret_sa->sin_port = htons(AVAHI_MDNS_PORT);
68 inet_pton(AF_INET, AVAHI_IPV4_MCAST_GROUP, &ret_sa->sin_addr);
71 static void mdns_mcast_group_ipv6(struct sockaddr_in6 *ret_sa) {
74 memset(ret_sa, 0, sizeof(struct sockaddr_in6));
75 ret_sa->sin6_family = AF_INET6;
76 ret_sa->sin6_port = htons(AVAHI_MDNS_PORT);
77 inet_pton(AF_INET6, AVAHI_IPV6_MCAST_GROUP, &ret_sa->sin6_addr);
80 static void ipv4_address_to_sockaddr(struct sockaddr_in *ret_sa, const AvahiIPv4Address *a, uint16_t port) {
85 memset(ret_sa, 0, sizeof(struct sockaddr_in));
86 ret_sa->sin_family = AF_INET;
87 ret_sa->sin_port = htons(port);
88 memcpy(&ret_sa->sin_addr, a, sizeof(AvahiIPv4Address));
91 static void ipv6_address_to_sockaddr(struct sockaddr_in6 *ret_sa, const AvahiIPv6Address *a, uint16_t port) {
96 memset(ret_sa, 0, sizeof(struct sockaddr_in6));
97 ret_sa->sin6_family = AF_INET6;
98 ret_sa->sin6_port = htons(port);
99 memcpy(&ret_sa->sin6_addr, a, sizeof(AvahiIPv6Address));
102 int avahi_mdns_mcast_join_ipv4(int fd, int idx) {
103 /* FIXME: sebest : we must factorize this part of the code */
104 struct sockaddr_in sa;
105 #ifdef HAVE_STRUCT_IP_MREQN
106 struct ip_mreqn mreq;
108 memset(&mreq, 0, sizeof(mreq));
109 mreq.imr_ifindex = idx;
114 memset(&mreq, 0, sizeof(mreq));
116 if ((!if_indextoname(idx, ifreq.ifr_name))) {
117 avahi_log_warn("if_indextoname failed: %s", strerror(errno));
121 if (ioctl(fd, SIOCGIFADDR, &ifreq) < 0) {
122 avahi_log_warn("SIOCGIFADDR failed: %s", strerror(errno));
126 memcpy(&mreq.imr_interface,
127 &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr,
128 sizeof(struct in_addr));
130 mdns_mcast_group_ipv4 (&sa);
131 mreq.imr_multiaddr = sa.sin_addr;
133 if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
134 avahi_log_warn("IP_ADD_MEMBERSHIP failed: %s", strerror(errno));
141 int avahi_mdns_mcast_join_ipv6(int fd, int idx) {
142 struct ipv6_mreq mreq6;
143 struct sockaddr_in6 sa6;
145 mdns_mcast_group_ipv6 (&sa6);
147 memset(&mreq6, 0, sizeof(mreq6));
148 mreq6.ipv6mr_multiaddr = sa6.sin6_addr;
149 mreq6.ipv6mr_interface = idx;
151 if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
152 avahi_log_warn("IPV6_ADD_MEMBERSHIP failed: %s", strerror(errno));
159 int avahi_mdns_mcast_leave_ipv4(int fd, int idx) {
160 /* FIXME: sebest : we must factorize this part of the code */
161 struct sockaddr_in sa;
162 #ifdef HAVE_STRUCT_IP_MREQN
163 struct ip_mreqn mreq;
165 memset(&mreq, 0, sizeof(mreq));
166 mreq.imr_ifindex = idx;
171 memset(&mreq, 0, sizeof(mreq));
173 if ((!if_indextoname(idx, ifreq.ifr_name))) {
174 avahi_log_warn("if_indextoname failed: %s", strerror(errno));
178 if (ioctl(fd, SIOCGIFADDR, &ifreq) < 0) {
179 avahi_log_warn("SIOCGIFADDR failed: %s", strerror(errno));
183 memcpy(&mreq.imr_interface,
184 &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr,
185 sizeof(struct in_addr));
187 mdns_mcast_group_ipv4 (&sa);
188 mreq.imr_multiaddr = sa.sin_addr;
190 if (setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
191 avahi_log_warn("IP_DROP_MEMBERSHIP failed: %s", strerror(errno));
198 int avahi_mdns_mcast_leave_ipv6(int fd, int idx) {
199 struct ipv6_mreq mreq6;
200 struct sockaddr_in6 sa6;
202 mdns_mcast_group_ipv6 (&sa6);
204 memset(&mreq6, 0, sizeof(mreq6));
205 mreq6.ipv6mr_multiaddr = sa6.sin6_addr;
206 mreq6.ipv6mr_interface = idx;
208 if (setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
209 avahi_log_warn("IPV6_DROP_MEMBERSHIP failed: %s", strerror(errno));
216 static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) {
223 if (bind(fd, sa, l) < 0) {
225 if (errno != EADDRINUSE) {
226 avahi_log_warn("bind() failed: %s", strerror(errno));
230 avahi_log_warn("*** WARNING: Detected another %s mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***",
231 sa->sa_family == AF_INET ? "IPv4" : "IPv6");
233 /* Try again, this time with SO_REUSEADDR set */
235 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
236 avahi_log_warn("SO_REUSEADDR failed: %s", strerror(errno));
240 if (bind(fd, sa, l) < 0) {
241 avahi_log_warn("bind() failed: %s", strerror(errno));
246 /* We enable SO_REUSEADDR afterwards, to make sure that the
247 * user may run other mDNS implementations if he really
251 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
252 avahi_log_warn("SO_REUSEADDR failed: %s", strerror(errno));
260 static int ip_pktinfo (int fd, int yes)
265 if ((ret = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes))) < 0) {
266 avahi_log_warn("IP_PKTINFO failed: %s", strerror(errno));
269 #ifdef IP_RECVINTERFACE
270 if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVINTERFACE, &yes, sizeof (yes))) < 0) {
271 avahi_log_warn("IP_RECVINTERFACE failed: %s", strerror(errno));
275 if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVIF, &yes, sizeof (yes))) < 0) {
276 avahi_log_warn("IP_RECVIF failed: %s", strerror(errno));
278 #endif /* IP_RECVIF */
279 #endif /* IP_RECVINTERFACE */
280 #if defined (IP_RECVDSTADDR) /* && !defined(solaris) */
281 if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof (yes))) < 0) {
282 avahi_log_warn("IP_RECVDSTADDR failed: %s", strerror(errno));
284 #endif /* IP_RECVDSTADDR */
285 #endif /* IP_PKTINFO */
290 int avahi_open_socket_ipv4(int no_reuse) {
291 struct sockaddr_in local;
292 int fd = -1, ttl, yes, r;
294 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
295 avahi_log_warn("socket() failed: %s", strerror(errno));
300 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
301 avahi_log_warn("IP_MULTICAST_TTL failed: %s", strerror(errno));
306 if (setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) {
307 avahi_log_warn("IP_TTL failed: %s", strerror(errno));
312 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
313 avahi_log_warn("IP_MULTICAST_LOOP failed: %s", strerror(errno));
317 memset(&local, 0, sizeof(local));
318 local.sin_family = AF_INET;
319 local.sin_port = htons(AVAHI_MDNS_PORT);
322 r = bind(fd, (struct sockaddr*) &local, sizeof(local));
324 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local));
330 if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
331 avahi_log_warn("IP_RECVTTL failed: %s", strerror(errno));
336 if (ip_pktinfo (fd, yes) < 0) {
340 if (avahi_set_cloexec(fd) < 0) {
341 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
345 if (avahi_set_nonblock(fd) < 0) {
346 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
359 int avahi_open_socket_ipv6(int no_reuse) {
360 struct sockaddr_in6 sa, local;
361 int fd = -1, ttl, yes, r;
363 mdns_mcast_group_ipv6(&sa);
365 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
366 avahi_log_warn("socket() failed: %s", strerror(errno));
371 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
372 avahi_log_warn("IPV6_MULTICAST_HOPS failed: %s", strerror(errno));
377 if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
378 avahi_log_warn("IPV6_UNICAST_HOPS failed: %s", strerror(errno));
383 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) {
384 avahi_log_warn("IPV6_V6ONLY failed: %s", strerror(errno));
389 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
390 avahi_log_warn("IPV6_MULTICAST_LOOP failed: %s", strerror(errno));
394 memset(&local, 0, sizeof(local));
395 local.sin6_family = AF_INET6;
396 local.sin6_port = htons(AVAHI_MDNS_PORT);
399 r = bind(fd, (struct sockaddr*) &local, sizeof(local));
401 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local));
408 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPS, &yes, sizeof(yes)) < 0) {
409 avahi_log_warn("IPV6_RECVHOPS failed: %s", strerror(errno));
412 #elif IPV6_RECVHOPLIMIT
414 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &yes, sizeof(yes)) < 0) {
415 avahi_log_warn("IPV6_RECVHOPLIMIT failed: %s", strerror(errno));
420 if (setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
421 avahi_log_warn("IPV6_HOPLIMIT failed: %s", strerror(errno));
426 #ifdef IPV6_RECVPKTINFO
428 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0) {
429 avahi_log_warn("IPV6_RECVPKTINFO failed: %s", strerror(errno));
434 if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
435 avahi_log_warn("IPV6_PKTINFO failed: %s", strerror(errno));
440 if (avahi_set_cloexec(fd) < 0) {
441 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
445 if (avahi_set_nonblock(fd) < 0) {
446 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
459 static int sendmsg_loop(int fd, struct msghdr *msg, int flags) {
465 if (sendmsg(fd, msg, flags) >= 0)
468 if (errno != EAGAIN) {
469 avahi_log_debug("sendmsg() failed: %s", strerror(errno));
473 if (avahi_wait_for_write(fd) < 0)
480 int avahi_send_dns_packet_ipv4(int fd, int interface, AvahiDnsPacket *p, const AvahiIPv4Address *a, uint16_t port) {
481 struct sockaddr_in sa;
484 struct cmsghdr *cmsg;
486 uint8_t cmsg_data[sizeof(struct cmsghdr) + sizeof(struct in_pktinfo)];
488 uint8_t cmsg_data[sizeof(struct cmsghdr) + sizeof(struct sockaddr_dl)];
489 #elif IP_RECVINTERFACE
490 uint8_t cmsg_data[sizeof(struct cmsghdr) + sizeof(u_short)];
495 assert(avahi_dns_packet_check_valid(p) >= 0);
496 assert(!a || port > 0);
499 mdns_mcast_group_ipv4(&sa);
501 ipv4_address_to_sockaddr(&sa, a, port);
503 memset(&io, 0, sizeof(io));
504 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
505 io.iov_len = p->size;
507 memset(&msg, 0, sizeof(msg));
509 msg.msg_namelen = sizeof(sa);
514 if (interface >= 0) {
516 memset(cmsg_data, 0, sizeof(cmsg_data));
517 cmsg = (struct cmsghdr*) cmsg_data;
518 cmsg->cmsg_len = sizeof(cmsg_data);
519 cmsg->cmsg_level = IPPROTO_IP;
522 struct in_pktinfo *pkti;
524 cmsg->cmsg_type = IP_PKTINFO;
525 pkti = (struct in_pktinfo*) (cmsg_data + sizeof(struct cmsghdr));
526 pkti->ipi_ifindex = interface;
530 struct sockaddr_dl *sdl;
532 cmsg->cmsg_type = IP_RECVIF;
533 sdl = (struct sockaddr_dl*) (cmsg_data + sizeof(struct cmsghdr));
534 sdl->sdl_index = interface;
536 #elif IP_RECVINTERFACE
540 cmsg->cmsg_type = IP_RECVINTERFACE;
541 i = (u_short *) (cmsg_data + sizeof(struct cmsghdr));
542 memcpy(&i, CMSG_DATA (cmsg), sizeof(u_short));
545 msg.msg_control = cmsg_data;
546 msg.msg_controllen = sizeof(cmsg_data);
548 msg.msg_control = NULL;
549 msg.msg_controllen = 0;
552 return sendmsg_loop(fd, &msg, 0);
555 int avahi_send_dns_packet_ipv6(int fd, int interface, AvahiDnsPacket *p, const AvahiIPv6Address *a, uint16_t port) {
556 struct sockaddr_in6 sa;
559 struct cmsghdr *cmsg;
560 uint8_t cmsg_data[sizeof(struct cmsghdr) + sizeof(struct in6_pktinfo)];
564 assert(avahi_dns_packet_check_valid(p) >= 0);
567 mdns_mcast_group_ipv6(&sa);
569 ipv6_address_to_sockaddr(&sa, a, port);
571 memset(&io, 0, sizeof(io));
572 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
573 io.iov_len = p->size;
576 memset(&msg, 0, sizeof(msg));
578 msg.msg_namelen = sizeof(sa);
583 if (interface >= 0) {
584 struct in6_pktinfo *pkti;
586 memset(cmsg_data, 0, sizeof(cmsg_data));
587 cmsg = (struct cmsghdr*) cmsg_data;
588 cmsg->cmsg_len = sizeof(cmsg_data);
589 cmsg->cmsg_level = IPPROTO_IPV6;
590 cmsg->cmsg_type = IPV6_PKTINFO;
592 pkti = (struct in6_pktinfo*) (cmsg_data + sizeof(struct cmsghdr));
593 pkti->ipi6_ifindex = interface;
595 msg.msg_control = cmsg_data;
596 msg.msg_controllen = sizeof(cmsg_data);
598 msg.msg_control = NULL;
599 msg.msg_controllen = 0;
602 return sendmsg_loop(fd, &msg, 0);
605 AvahiDnsPacket* avahi_recv_dns_packet_ipv4(int fd, struct sockaddr_in *ret_sa, AvahiIPv4Address *ret_dest_address, int *ret_iface, uint8_t* ret_ttl) {
606 AvahiDnsPacket *p= NULL;
611 struct cmsghdr *cmsg;
612 int found_ttl = 0, found_iface = 0, found_addr = 0;
617 if (ioctl(fd, FIONREAD, &ms) < 0) {
618 avahi_log_warn("ioctl(): %s", strerror(errno));
622 p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
624 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
625 io.iov_len = p->max_size;
627 memset(&msg, 0, sizeof(msg));
629 msg.msg_name = ret_sa;
630 msg.msg_namelen = sizeof(struct sockaddr_in);
637 msg.msg_control = aux;
638 msg.msg_controllen = sizeof(aux);
641 if ((l = recvmsg(fd, &msg, 0)) < 0) {
642 avahi_log_warn("recvmsg(): %s", strerror(errno));
646 if (ret_sa && ret_sa->sin_addr.s_addr == INADDR_ANY) {
647 /* Linux 2.4 behaves very strangely sometimes! */
649 /*avahi_hexdump(AVAHI_DNS_PACKET_DATA(p), l); */
653 assert(!(msg.msg_flags & MSG_CTRUNC));
654 assert(!(msg.msg_flags & MSG_TRUNC));
655 p->size = (size_t) l;
660 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
662 if (cmsg->cmsg_level == IPPROTO_IP) {
663 switch (cmsg->cmsg_type) {
669 *ret_ttl = (uint8_t) (*(int *) CMSG_DATA(cmsg));
675 struct in_pktinfo *i = (struct in_pktinfo*) CMSG_DATA(cmsg);
678 *ret_iface = (int) i->ipi_ifindex;
680 if (ret_dest_address)
681 ret_dest_address->address = i->ipi_addr.s_addr;
682 found_addr = found_iface = 1;
688 struct sockaddr_dl *sdl = (struct sockaddr_dl *) CMSG_DATA (cmsg);
691 *ret_iface = (int) sdl->sdl_index;
696 #ifdef IP_RECVDSTADDR
698 if (ret_dest_address)
699 memcpy (&ret_dest_address->address, CMSG_DATA (cmsg), 4);
704 avahi_log_warn("Unhandled cmsg_type : %d",cmsg->cmsg_type);
718 avahi_dns_packet_free(p);
723 AvahiDnsPacket* avahi_recv_dns_packet_ipv6(int fd, struct sockaddr_in6 *ret_sa, AvahiIPv6Address *ret_dest_address, int *ret_iface, uint8_t* ret_ttl) {
724 AvahiDnsPacket *p = NULL;
731 struct cmsghdr *cmsg;
732 int found_ttl = 0, found_iface = 0;
736 if (ioctl(fd, FIONREAD, &ms) < 0) {
737 avahi_log_warn("ioctl(): %s", strerror(errno));
741 p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
743 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
744 io.iov_len = p->max_size;
746 memset(&msg, 0, sizeof(msg));
748 msg.msg_name = ret_sa;
749 msg.msg_namelen = sizeof(struct sockaddr_in6);
757 msg.msg_control = aux;
758 msg.msg_controllen = sizeof(aux);
761 if ((l = recvmsg(fd, &msg, 0)) < 0) {
762 avahi_log_warn("recvmsg(): %s", strerror(errno));
766 p->size = (size_t) l;
771 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
772 if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_HOPLIMIT) {
775 *ret_ttl = (uint8_t) (*(int *) CMSG_DATA(cmsg));
780 if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
781 struct in6_pktinfo *i = (struct in6_pktinfo*) CMSG_DATA(cmsg);
784 *ret_iface = i->ipi6_ifindex;
786 if (ret_dest_address)
787 memcpy(ret_dest_address->address, i->ipi6_addr.s6_addr, 16);
799 avahi_dns_packet_free(p);
804 int avahi_open_unicast_socket_ipv4(void) {
805 struct sockaddr_in local;
808 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
809 avahi_log_warn("socket() failed: %s", strerror(errno));
813 memset(&local, 0, sizeof(local));
814 local.sin_family = AF_INET;
816 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
817 avahi_log_warn("bind() failed: %s", strerror(errno));
822 if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
823 avahi_log_warn("IP_RECVTTL failed: %s", strerror(errno));
828 if (ip_pktinfo (fd, yes) < 0) {
832 if (avahi_set_cloexec(fd) < 0) {
833 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
837 if (avahi_set_nonblock(fd) < 0) {
838 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
851 int avahi_open_unicast_socket_ipv6(void) {
852 struct sockaddr_in6 local;
855 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
856 avahi_log_warn("socket() failed: %s", strerror(errno));
860 memset(&local, 0, sizeof(local));
861 local.sin6_family = AF_INET6;
863 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
864 avahi_log_warn("bind() failed: %s", strerror(errno));
870 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPS, &yes, sizeof(yes)) < 0) {
871 avahi_log_warn("IPV6_RECVHOPS failed: %s", strerror(errno));
874 #elif IPV6_RECVHOPLIMIT
876 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &yes, sizeof(yes)) < 0) {
877 avahi_log_warn("IPV6_RECVHOPLIMIT failed: %s", strerror(errno));
882 if (setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
883 avahi_log_warn("IPV6_HOPLIMIT failed: %s", strerror(errno));
888 #ifdef IPV6_RECVPKTINFO
890 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0) {
891 avahi_log_warn("IPV6_RECVPKTINFO failed: %s", strerror(errno));
896 if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
897 avahi_log_warn("IPV6_PKTINFO failed: %s", strerror(errno));
902 if (avahi_set_cloexec(fd) < 0) {
903 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
907 if (avahi_set_nonblock(fd) < 0) {
908 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));