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
33 #include <sys/ioctl.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
44 #include <net/if_dl.h>
51 #include "addr-util.h"
53 /* this is a portability hack */
54 #ifndef IPV6_ADD_MEMBERSHIP
55 #ifdef IPV6_JOIN_GROUP
56 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
60 #ifndef IPV6_DROP_MEMBERSHIP
61 #ifdef IPV6_LEAVE_GROUP
62 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
66 static void mdns_mcast_group_ipv4(struct sockaddr_in *ret_sa) {
69 memset(ret_sa, 0, sizeof(struct sockaddr_in));
70 ret_sa->sin_family = AF_INET;
71 ret_sa->sin_port = htons(AVAHI_MDNS_PORT);
72 inet_pton(AF_INET, AVAHI_IPV4_MCAST_GROUP, &ret_sa->sin_addr);
75 static void mdns_mcast_group_ipv6(struct sockaddr_in6 *ret_sa) {
78 memset(ret_sa, 0, sizeof(struct sockaddr_in6));
79 ret_sa->sin6_family = AF_INET6;
80 ret_sa->sin6_port = htons(AVAHI_MDNS_PORT);
81 inet_pton(AF_INET6, AVAHI_IPV6_MCAST_GROUP, &ret_sa->sin6_addr);
84 static void ipv4_address_to_sockaddr(struct sockaddr_in *ret_sa, const AvahiIPv4Address *a, uint16_t port) {
89 memset(ret_sa, 0, sizeof(struct sockaddr_in));
90 ret_sa->sin_family = AF_INET;
91 ret_sa->sin_port = htons(port);
92 memcpy(&ret_sa->sin_addr, a, sizeof(AvahiIPv4Address));
95 static void ipv6_address_to_sockaddr(struct sockaddr_in6 *ret_sa, const AvahiIPv6Address *a, uint16_t port) {
100 memset(ret_sa, 0, sizeof(struct sockaddr_in6));
101 ret_sa->sin6_family = AF_INET6;
102 ret_sa->sin6_port = htons(port);
103 memcpy(&ret_sa->sin6_addr, a, sizeof(AvahiIPv6Address));
106 int avahi_mdns_mcast_join_ipv4(int fd, const AvahiIPv4Address *a, int idx, int join) {
107 #ifdef HAVE_STRUCT_IP_MREQN
108 struct ip_mreqn mreq;
112 struct sockaddr_in sa;
118 memset(&mreq, 0, sizeof(mreq));
119 #ifdef HAVE_STRUCT_IP_MREQN
120 mreq.imr_ifindex = idx;
121 mreq.imr_address.s_addr = a->address;
123 mreq.imr_interface.s_addr = a->address;
125 mdns_mcast_group_ipv4(&sa);
126 mreq.imr_multiaddr = sa.sin_addr;
128 /* Some network drivers have issues with dropping membership of
129 * mcast groups when the iface is down, but don't allow rejoining
130 * when it comes back up. This is an ugly workaround */
132 setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
134 if (setsockopt(fd, IPPROTO_IP, join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
135 avahi_log_warn("%s failed: %s", join ? "IP_ADD_MEMBERSHIP" : "IP_DROP_MEMBERSHIP", strerror(errno));
142 int avahi_mdns_mcast_join_ipv6(int fd, const AvahiIPv6Address *a, int idx, int join) {
143 struct ipv6_mreq mreq6;
144 struct sockaddr_in6 sa6;
150 memset(&mreq6, 0, sizeof(mreq6));
151 mdns_mcast_group_ipv6 (&sa6);
152 mreq6.ipv6mr_multiaddr = sa6.sin6_addr;
153 mreq6.ipv6mr_interface = idx;
156 setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6));
158 if (setsockopt(fd, IPPROTO_IPV6, join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
159 avahi_log_warn("%s failed: %s", join ? "IPV6_ADD_MEMBERSHIP" : "IPV6_DROP_MEMBERSHIP", strerror(errno));
166 static int reuseaddr(int fd) {
170 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
171 avahi_log_warn("SO_REUSEADDR failed: %s", strerror(errno));
177 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) {
178 avahi_log_warn("SO_REUSEPORT failed: %s", strerror(errno));
186 static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) {
192 if (bind(fd, sa, l) < 0) {
194 if (errno != EADDRINUSE) {
195 avahi_log_warn("bind() failed: %s", strerror(errno));
199 avahi_log_warn("*** WARNING: Detected another %s mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***",
200 sa->sa_family == AF_INET ? "IPv4" : "IPv6");
202 /* Try again, this time with SO_REUSEADDR set */
203 if (reuseaddr(fd) < 0)
206 if (bind(fd, sa, l) < 0) {
207 avahi_log_warn("bind() failed: %s", strerror(errno));
212 /* We enable SO_REUSEADDR afterwards, to make sure that the
213 * user may run other mDNS implementations if he really
216 if (reuseaddr(fd) < 0)
223 static int ipv4_pktinfo(int fd) {
228 if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
229 avahi_log_warn("IP_PKTINFO failed: %s", strerror(errno));
234 #ifdef IP_RECVINTERFACE
236 if (setsockopt (fd, IPPROTO_IP, IP_RECVINTERFACE, &yes, sizeof(yes)) < 0) {
237 avahi_log_warn("IP_RECVINTERFACE failed: %s", strerror(errno));
240 #elif defined(IP_RECVIF)
242 if (setsockopt (fd, IPPROTO_IP, IP_RECVIF, &yes, sizeof(yes)) < 0) {
243 avahi_log_warn("IP_RECVIF failed: %s", strerror(errno));
248 #ifdef IP_RECVDSTADDR
250 if (setsockopt (fd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof(yes)) < 0) {
251 avahi_log_warn("IP_RECVDSTADDR failed: %s", strerror(errno));
256 #endif /* IP_PKTINFO */
260 if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
261 avahi_log_warn("IP_RECVTTL failed: %s", strerror(errno));
269 static int ipv6_pktinfo(int fd) {
272 #ifdef IPV6_RECVPKTINFO
274 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0) {
275 avahi_log_warn("IPV6_RECVPKTINFO failed: %s", strerror(errno));
278 #elif defined(IPV6_PKTINFO)
280 if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
281 avahi_log_warn("IPV6_PKTINFO failed: %s", strerror(errno));
288 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPS, &yes, sizeof(yes)) < 0) {
289 avahi_log_warn("IPV6_RECVHOPS failed: %s", strerror(errno));
292 #elif defined(IPV6_RECVHOPLIMIT)
294 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &yes, sizeof(yes)) < 0) {
295 avahi_log_warn("IPV6_RECVHOPLIMIT failed: %s", strerror(errno));
298 #elif defined(IPV6_HOPLIMIT)
300 if (setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
301 avahi_log_warn("IPV6_HOPLIMIT failed: %s", strerror(errno));
309 int avahi_open_socket_ipv4(int no_reuse) {
310 struct sockaddr_in local;
311 int fd = -1, r, ittl;
314 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
315 avahi_log_warn("socket() failed: %s", strerror(errno));
320 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
321 avahi_log_warn("IP_MULTICAST_TTL failed: %s", strerror(errno));
326 if (setsockopt(fd, IPPROTO_IP, IP_TTL, &ittl, sizeof(ittl)) < 0) {
327 avahi_log_warn("IP_TTL failed: %s", strerror(errno));
332 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &cyes, sizeof(cyes)) < 0) {
333 avahi_log_warn("IP_MULTICAST_LOOP failed: %s", strerror(errno));
337 memset(&local, 0, sizeof(local));
338 local.sin_family = AF_INET;
339 local.sin_port = htons(AVAHI_MDNS_PORT);
342 r = bind(fd, (struct sockaddr*) &local, sizeof(local));
344 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local));
349 if (ipv4_pktinfo (fd) < 0)
352 if (avahi_set_cloexec(fd) < 0) {
353 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
357 if (avahi_set_nonblock(fd) < 0) {
358 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
371 int avahi_open_socket_ipv6(int no_reuse) {
372 struct sockaddr_in6 sa, local;
376 mdns_mcast_group_ipv6(&sa);
378 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
379 avahi_log_warn("socket() failed: %s", strerror(errno));
384 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
385 avahi_log_warn("IPV6_MULTICAST_HOPS failed: %s", strerror(errno));
390 if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
391 avahi_log_warn("IPV6_UNICAST_HOPS failed: %s", strerror(errno));
396 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) {
397 avahi_log_warn("IPV6_V6ONLY failed: %s", strerror(errno));
402 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
403 avahi_log_warn("IPV6_MULTICAST_LOOP failed: %s", strerror(errno));
407 memset(&local, 0, sizeof(local));
408 local.sin6_family = AF_INET6;
409 local.sin6_port = htons(AVAHI_MDNS_PORT);
412 r = bind(fd, (struct sockaddr*) &local, sizeof(local));
414 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local));
419 if (ipv6_pktinfo(fd) < 0)
422 if (avahi_set_cloexec(fd) < 0) {
423 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
427 if (avahi_set_nonblock(fd) < 0) {
428 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
441 static int sendmsg_loop(int fd, struct msghdr *msg, int flags) {
447 if (sendmsg(fd, msg, flags) >= 0)
450 if (errno != EAGAIN) {
451 avahi_log_debug("sendmsg() failed: %s", strerror(errno));
455 if (avahi_wait_for_write(fd) < 0)
462 int avahi_send_dns_packet_ipv4(int fd, AvahiIfIndex interface, AvahiDnsPacket *p, const AvahiIPv4Address *src_address, const AvahiIPv4Address *dst_address, uint16_t dst_port) {
463 struct sockaddr_in sa;
467 struct cmsghdr *cmsg;
468 size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
469 #elif defined(IP_SENDSRCADDR)
470 struct cmsghdr *cmsg;
471 size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_addr)) / sizeof(size_t)) + 1];
476 assert(avahi_dns_packet_check_valid(p) >= 0);
477 assert(!dst_address || dst_port > 0);
480 mdns_mcast_group_ipv4(&sa);
482 ipv4_address_to_sockaddr(&sa, dst_address, dst_port);
484 memset(&io, 0, sizeof(io));
485 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
486 io.iov_len = p->size;
488 memset(&msg, 0, sizeof(msg));
490 msg.msg_namelen = sizeof(sa);
494 msg.msg_control = NULL;
495 msg.msg_controllen = 0;
498 if (interface > 0 || src_address) {
499 struct in_pktinfo *pkti;
501 memset(cmsg_data, 0, sizeof(cmsg_data));
502 cmsg = (struct cmsghdr*) cmsg_data;
503 cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
504 cmsg->cmsg_level = IPPROTO_IP;
505 cmsg->cmsg_type = IP_PKTINFO;
507 pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
510 pkti->ipi_ifindex = interface;
513 pkti->ipi_spec_dst.s_addr = src_address->address;
515 msg.msg_control = cmsg_data;
516 msg.msg_controllen = sizeof(cmsg_data);
518 #elif defined(IP_SENDSRCADDR)
520 struct in_addr *addr;
522 memset(cmsg_data, 0, sizeof(cmsg_data));
523 cmsg = (struct cmsghdr*) cmsg_data;
524 cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
525 cmsg->cmsg_level = IPPROTO_IP;
526 cmsg->cmsg_type = IP_SENDSRCADDR;
528 addr = (struct in_addr *)CMSG_DATA(cmsg);
529 addr->s_addr = src_address->address;
531 msg.msg_control = cmsg_data;
532 msg.msg_controllen = sizeof(cmsg_data);
534 #elif defined(IP_MULTICAST_IF)
536 struct in_addr any = { INADDR_ANY };
537 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, src_address ? (const void*) &src_address->address : (const void*) &any, sizeof(struct in_addr)) < 0) {
538 avahi_log_warn("IP_MULTICAST_IF failed: %s", strerror(errno));
542 #elif defined(__GNUC__)
543 #warning "FIXME: We need some code to set the outgoing interface/local address here if IP_PKTINFO/IP_MULTICAST_IF is not available"
546 return sendmsg_loop(fd, &msg, 0);
549 int avahi_send_dns_packet_ipv6(int fd, AvahiIfIndex interface, AvahiDnsPacket *p, const AvahiIPv6Address *src_address, const AvahiIPv6Address *dst_address, uint16_t dst_port) {
550 struct sockaddr_in6 sa;
553 struct cmsghdr *cmsg;
554 size_t cmsg_data[(CMSG_SPACE(sizeof(struct in6_pktinfo))/sizeof(size_t)) + 1];
558 assert(avahi_dns_packet_check_valid(p) >= 0);
559 assert(!dst_address || dst_port > 0);
562 mdns_mcast_group_ipv6(&sa);
564 ipv6_address_to_sockaddr(&sa, dst_address, dst_port);
566 memset(&io, 0, sizeof(io));
567 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
568 io.iov_len = p->size;
570 memset(&msg, 0, sizeof(msg));
572 msg.msg_namelen = sizeof(sa);
577 if (interface > 0 || src_address) {
578 struct in6_pktinfo *pkti;
580 memset(cmsg_data, 0, sizeof(cmsg_data));
581 cmsg = (struct cmsghdr*) cmsg_data;
582 cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
583 cmsg->cmsg_level = IPPROTO_IPV6;
584 cmsg->cmsg_type = IPV6_PKTINFO;
586 pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
589 pkti->ipi6_ifindex = interface;
592 memcpy(&pkti->ipi6_addr, src_address->address, sizeof(src_address->address));
594 msg.msg_control = cmsg_data;
595 msg.msg_controllen = sizeof(cmsg_data);
597 msg.msg_control = NULL;
598 msg.msg_controllen = 0;
601 return sendmsg_loop(fd, &msg, 0);
604 AvahiDnsPacket *avahi_recv_dns_packet_ipv4(int fd, AvahiIPv4Address *ret_src_address, uint16_t *ret_src_port, AvahiIPv4Address *ret_dst_address, AvahiIfIndex *ret_iface, uint8_t *ret_ttl) {
605 AvahiDnsPacket *p= NULL;
608 size_t aux[1024 / sizeof(size_t)]; /* for alignment on ia64 ! */
610 struct cmsghdr *cmsg;
613 struct sockaddr_in sa;
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_namelen = sizeof(sa);
632 msg.msg_control = aux;
633 msg.msg_controllen = sizeof(aux);
636 if ((l = recvmsg(fd, &msg, 0)) < 0) {
637 avahi_log_warn("recvmsg(): %s", strerror(errno));
641 if (sa.sin_addr.s_addr == INADDR_ANY) {
642 /* Linux 2.4 behaves very strangely sometimes! */
646 assert(!(msg.msg_flags & MSG_CTRUNC));
647 assert(!(msg.msg_flags & MSG_TRUNC));
649 p->size = (size_t) l;
652 *ret_src_port = avahi_port_from_sockaddr((struct sockaddr*) &sa);
654 if (ret_src_address) {
656 avahi_address_from_sockaddr((struct sockaddr*) &sa, &a);
657 *ret_src_address = a.data.ipv4;
664 *ret_iface = AVAHI_IF_UNSPEC;
666 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
668 if (cmsg->cmsg_level == IPPROTO_IP) {
670 switch (cmsg->cmsg_type) {
676 *ret_ttl = (uint8_t) (*(int *) CMSG_DATA(cmsg));
682 struct in_pktinfo *i = (struct in_pktinfo*) CMSG_DATA(cmsg);
685 *ret_iface = (int) i->ipi_ifindex;
688 ret_dst_address->address = i->ipi_addr.s_addr;
698 struct sockaddr_dl *sdl = (struct sockaddr_dl *) CMSG_DATA (cmsg);
701 *ret_iface = (int) sdl->sdl_index;
707 #ifdef IP_RECVDSTADDR
710 memcpy(&ret_dst_address->address, CMSG_DATA (cmsg), 4);
717 avahi_log_warn("Unhandled cmsg_type : %d", cmsg->cmsg_type);
729 avahi_dns_packet_free(p);
734 AvahiDnsPacket *avahi_recv_dns_packet_ipv6(int fd, AvahiIPv6Address *ret_src_address, uint16_t *ret_src_port, AvahiIPv6Address *ret_dst_address, AvahiIfIndex *ret_iface, uint8_t *ret_ttl) {
735 AvahiDnsPacket *p = NULL;
738 size_t aux[1024 / sizeof(size_t)];
741 struct cmsghdr *cmsg;
742 int found_ttl = 0, found_iface = 0;
743 struct sockaddr_in6 sa;
747 if (ioctl(fd, FIONREAD, &ms) < 0) {
748 avahi_log_warn("ioctl(): %s", strerror(errno));
752 p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
754 io.iov_base = AVAHI_DNS_PACKET_DATA(p);
755 io.iov_len = p->max_size;
757 memset(&msg, 0, sizeof(msg));
758 msg.msg_name = (struct sockaddr*) &sa;
759 msg.msg_namelen = sizeof(sa);
763 msg.msg_control = aux;
764 msg.msg_controllen = sizeof(aux);
767 if ((l = recvmsg(fd, &msg, 0)) < 0) {
768 avahi_log_warn("recvmsg(): %s", strerror(errno));
772 assert(!(msg.msg_flags & MSG_CTRUNC));
773 assert(!(msg.msg_flags & MSG_TRUNC));
775 p->size = (size_t) l;
778 *ret_src_port = avahi_port_from_sockaddr((struct sockaddr*) &sa);
780 if (ret_src_address) {
782 avahi_address_from_sockaddr((struct sockaddr*) &sa, &a);
783 *ret_src_address = a.data.ipv6;
786 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
788 if (cmsg->cmsg_level == IPPROTO_IPV6) {
790 switch (cmsg->cmsg_type) {
795 *ret_ttl = (uint8_t) (*(int *) CMSG_DATA(cmsg));
802 struct in6_pktinfo *i = (struct in6_pktinfo*) CMSG_DATA(cmsg);
805 *ret_iface = i->ipi6_ifindex;
808 memcpy(ret_dst_address->address, i->ipi6_addr.s6_addr, 16);
815 avahi_log_warn("Unhandled cmsg_type : %d", cmsg->cmsg_type);
828 avahi_dns_packet_free(p);
833 int avahi_open_unicast_socket_ipv4(void) {
834 struct sockaddr_in local;
837 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
838 avahi_log_warn("socket() failed: %s", strerror(errno));
842 memset(&local, 0, sizeof(local));
843 local.sin_family = AF_INET;
845 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
846 avahi_log_warn("bind() failed: %s", strerror(errno));
850 if (ipv4_pktinfo(fd) < 0) {
854 if (avahi_set_cloexec(fd) < 0) {
855 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
859 if (avahi_set_nonblock(fd) < 0) {
860 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
873 int avahi_open_unicast_socket_ipv6(void) {
874 struct sockaddr_in6 local;
877 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
878 avahi_log_warn("socket() failed: %s", strerror(errno));
882 memset(&local, 0, sizeof(local));
883 local.sin6_family = AF_INET6;
885 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
886 avahi_log_warn("bind() failed: %s", strerror(errno));
890 if (ipv6_pktinfo(fd) < 0)
893 if (avahi_set_cloexec(fd) < 0) {
894 avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
898 if (avahi_set_nonblock(fd) < 0) {
899 avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));