diff options
author | Sebastien Estienne <sebastien.estienne@gmail.com> | 2005-10-12 22:41:44 +0000 |
---|---|---|
committer | Sebastien Estienne <sebastien.estienne@gmail.com> | 2005-10-12 22:41:44 +0000 |
commit | c722f4913cf03748a2f0937c6399dde3e1ac4abe (patch) | |
tree | 723600829e7f28c44558b6a46e3e8b6c561b7e6b /avahi-core/socket.c | |
parent | c6bf0e465bceac2ef0e5f3a3ba97ae1f8b251a40 (diff) |
* portability function for IP_PKTINFO
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@748 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/socket.c')
-rw-r--r-- | avahi-core/socket.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/avahi-core/socket.c b/avahi-core/socket.c index 7e1cdac..a555eaf 100644 --- a/avahi-core/socket.c +++ b/avahi-core/socket.c @@ -211,6 +211,36 @@ static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) { return 0; } +static int ip_pktinfo (int fd, int yes) +{ + int ret = -1; + +#if IP_PKTINFO + if ((ret = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes))) < 0) { + avahi_log_warn("IP_PKTINFO failed: %s", strerror(errno)); + } +#else +#ifdef IP_RECVINTERFACE + if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVINTERFACE, &yes, sizeof (yes))) < 0) { + avahi_log_warn("IP_RECVINTERFACE failed: %s", strerror(errno)); + } +#else +#ifdef IP_RECVIF + if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVIF, &yes, sizeof (yes))) < 0) { + avahi_log_warn("IP_RECVIF failed: %s", strerror(errno)); + } +#endif /* IP_RECVIF */ +#endif /* IP_RECVINTERFACE */ +#if defined (IP_RECVDSTADDR) /* && !defined(solaris) */ + if ((ret = setsockopt (fd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof (yes))) < 0) { + avahi_log_warn("IP_RECVDSTADDR failed: %s", strerror(errno)); + } +#endif /* IP_RECVDSTADDR */ +#endif /* IP_PKTINFO */ + + return (ret); +} + int avahi_open_socket_ipv4(int no_reuse) { struct sockaddr_in local; int fd = -1, ttl, yes, r; @@ -257,11 +287,10 @@ int avahi_open_socket_ipv4(int no_reuse) { } yes = 1; - if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) { - avahi_log_warn("IP_PKTINFO failed: %s", strerror(errno)); - goto fail; + if (ip_pktinfo (fd, yes) < 0) { + goto fail; } - + if (avahi_set_cloexec(fd) < 0) { avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno)); goto fail; @@ -673,11 +702,10 @@ int avahi_open_unicast_socket_ipv4(void) { } yes = 1; - if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) { - avahi_log_warn("IP_PKTINFO failed: %s", strerror(errno)); - goto fail; + if (ip_pktinfo (fd, yes) < 0) { + goto fail; } - + if (avahi_set_cloexec(fd) < 0) { avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno)); goto fail; |