Lines Matching refs:fd
107 int avahi_mdns_mcast_join_ipv4(int fd, const AvahiIPv4Address *a, int idx, int join) { in avahi_mdns_mcast_join_ipv4() argument
115 assert(fd >= 0); in avahi_mdns_mcast_join_ipv4()
133 setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); in avahi_mdns_mcast_join_ipv4()
135 …if (setsockopt(fd, IPPROTO_IP, join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq))… in avahi_mdns_mcast_join_ipv4()
143 int avahi_mdns_mcast_join_ipv6(int fd, const AvahiIPv6Address *a, int idx, int join) { in avahi_mdns_mcast_join_ipv6() argument
147 assert(fd >= 0); in avahi_mdns_mcast_join_ipv6()
157 setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)); in avahi_mdns_mcast_join_ipv6()
159 …if (setsockopt(fd, IPPROTO_IPV6, join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP, &mreq6, sizeof… in avahi_mdns_mcast_join_ipv6()
167 static int reuseaddr(int fd) { in reuseaddr() argument
171 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { in reuseaddr()
178 if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) { in reuseaddr()
187 static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) { in bind_with_warn() argument
189 assert(fd >= 0); in bind_with_warn()
193 if (bind(fd, sa, l) < 0) { in bind_with_warn()
204 if (reuseaddr(fd) < 0) in bind_with_warn()
207 if (bind(fd, sa, l) < 0) { in bind_with_warn()
217 if (reuseaddr(fd) < 0) in bind_with_warn()
224 static int ipv4_pktinfo(int fd) { in ipv4_pktinfo() argument
229 if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) { in ipv4_pktinfo()
237 if (setsockopt (fd, IPPROTO_IP, IP_RECVINTERFACE, &yes, sizeof(yes)) < 0) { in ipv4_pktinfo()
243 if (setsockopt (fd, IPPROTO_IP, IP_RECVIF, &yes, sizeof(yes)) < 0) { in ipv4_pktinfo()
251 if (setsockopt (fd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof(yes)) < 0) { in ipv4_pktinfo()
261 if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) { in ipv4_pktinfo()
270 static int ipv6_pktinfo(int fd) { in ipv6_pktinfo() argument
275 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0) { in ipv6_pktinfo()
281 if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) { in ipv6_pktinfo()
289 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPS, &yes, sizeof(yes)) < 0) { in ipv6_pktinfo()
295 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &yes, sizeof(yes)) < 0) { in ipv6_pktinfo()
301 if (setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) { in ipv6_pktinfo()
312 int fd = -1, r, ittl; in avahi_open_socket_ipv4() local
315 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { in avahi_open_socket_ipv4()
321 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) { in avahi_open_socket_ipv4()
327 if (setsockopt(fd, IPPROTO_IP, IP_TTL, &ittl, sizeof(ittl)) < 0) { in avahi_open_socket_ipv4()
333 if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &cyes, sizeof(cyes)) < 0) { in avahi_open_socket_ipv4()
343 r = bind(fd, (struct sockaddr*) &local, sizeof(local)); in avahi_open_socket_ipv4()
345 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local)); in avahi_open_socket_ipv4()
350 if (ipv4_pktinfo (fd) < 0) in avahi_open_socket_ipv4()
353 if (avahi_set_cloexec(fd) < 0) { in avahi_open_socket_ipv4()
358 if (avahi_set_nonblock(fd) < 0) { in avahi_open_socket_ipv4()
363 return fd; in avahi_open_socket_ipv4()
366 if (fd >= 0) in avahi_open_socket_ipv4()
367 close(fd); in avahi_open_socket_ipv4()
374 int fd = -1, yes, r; in avahi_open_socket_ipv6() local
379 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { in avahi_open_socket_ipv6()
385 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0) { in avahi_open_socket_ipv6()
391 if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0) { in avahi_open_socket_ipv6()
397 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) { in avahi_open_socket_ipv6()
403 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) { in avahi_open_socket_ipv6()
413 r = bind(fd, (struct sockaddr*) &local, sizeof(local)); in avahi_open_socket_ipv6()
415 r = bind_with_warn(fd, (struct sockaddr*) &local, sizeof(local)); in avahi_open_socket_ipv6()
420 if (ipv6_pktinfo(fd) < 0) in avahi_open_socket_ipv6()
423 if (avahi_set_cloexec(fd) < 0) { in avahi_open_socket_ipv6()
428 if (avahi_set_nonblock(fd) < 0) { in avahi_open_socket_ipv6()
433 return fd; in avahi_open_socket_ipv6()
436 if (fd >= 0) in avahi_open_socket_ipv6()
437 close(fd); in avahi_open_socket_ipv6()
442 static int sendmsg_loop(int fd, struct msghdr *msg, int flags) { in sendmsg_loop() argument
443 assert(fd >= 0); in sendmsg_loop()
448 if (sendmsg(fd, msg, flags) >= 0) in sendmsg_loop()
463 if (avahi_wait_for_write(fd) < 0) in sendmsg_loop()
471 int fd, in avahi_send_dns_packet_ipv4() argument
489 assert(fd >= 0); in avahi_send_dns_packet_ipv4()
536 …if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, src_address ? &src_address->address : &any, sizeof… in avahi_send_dns_packet_ipv4()
561 return sendmsg_loop(fd, &msg, 0); in avahi_send_dns_packet_ipv4()
565 int fd, in avahi_send_dns_packet_ipv6() argument
578 assert(fd >= 0); in avahi_send_dns_packet_ipv6()
623 return sendmsg_loop(fd, &msg, 0); in avahi_send_dns_packet_ipv6()
627 int fd, in avahi_recv_dns_packet_ipv4() argument
644 assert(fd >= 0); in avahi_recv_dns_packet_ipv4()
646 if (ioctl(fd, FIONREAD, &ms) < 0) { in avahi_recv_dns_packet_ipv4()
670 if ((l = recvmsg(fd, &msg, 0)) < 0) { in avahi_recv_dns_packet_ipv4()
788 int fd, in avahi_recv_dns_packet_ipv6() argument
805 assert(fd >= 0); in avahi_recv_dns_packet_ipv6()
807 if (ioctl(fd, FIONREAD, &ms) < 0) { in avahi_recv_dns_packet_ipv6()
832 if ((l = recvmsg(fd, &msg, 0)) < 0) { in avahi_recv_dns_packet_ipv6()
912 int fd = -1; in avahi_open_unicast_socket_ipv4() local
914 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { in avahi_open_unicast_socket_ipv4()
922 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) { in avahi_open_unicast_socket_ipv4()
927 if (ipv4_pktinfo(fd) < 0) { in avahi_open_unicast_socket_ipv4()
931 if (avahi_set_cloexec(fd) < 0) { in avahi_open_unicast_socket_ipv4()
936 if (avahi_set_nonblock(fd) < 0) { in avahi_open_unicast_socket_ipv4()
941 return fd; in avahi_open_unicast_socket_ipv4()
944 if (fd >= 0) in avahi_open_unicast_socket_ipv4()
945 close(fd); in avahi_open_unicast_socket_ipv4()
952 int fd = -1, yes; in avahi_open_unicast_socket_ipv6() local
954 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { in avahi_open_unicast_socket_ipv6()
960 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) { in avahi_open_unicast_socket_ipv6()
968 if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) { in avahi_open_unicast_socket_ipv6()
973 if (ipv6_pktinfo(fd) < 0) in avahi_open_unicast_socket_ipv6()
976 if (avahi_set_cloexec(fd) < 0) { in avahi_open_unicast_socket_ipv6()
981 if (avahi_set_nonblock(fd) < 0) { in avahi_open_unicast_socket_ipv6()
986 return fd; in avahi_open_unicast_socket_ipv6()
989 if (fd >= 0) in avahi_open_unicast_socket_ipv6()
990 close(fd); in avahi_open_unicast_socket_ipv6()