summaryrefslogtreecommitdiffstats
path: root/avahi-core/socket.c
diff options
context:
space:
mode:
authorFederico Lucifredi <flucifredi@acm.org>2007-05-06 20:12:18 +0000
committerFederico Lucifredi <flucifredi@acm.org>2007-05-06 20:12:18 +0000
commit8a49fc26776c8b95ce299e69903198df7bbebe11 (patch)
treef16ed29141aff95792cf73e3c636efcd534bf2bd /avahi-core/socket.c
parent1fef746edf313d8fb1d8417a17d536a915ca69cd (diff)
parenta6a4c936ad8c9071b891bb19c4edf5779e027a19 (diff)
refreshing branch to latest release.
git-svn-id: file:///home/lennart/svn/public/avahi/branches/federico@1455 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/socket.c')
-rw-r--r--avahi-core/socket.c75
1 files changed, 65 insertions, 10 deletions
diff --git a/avahi-core/socket.c b/avahi-core/socket.c
index 90e1d74..61b5eb4 100644
--- a/avahi-core/socket.c
+++ b/avahi-core/socket.c
@@ -475,10 +475,10 @@ int avahi_send_dns_packet_ipv4(
struct iovec io;
#ifdef IP_PKTINFO
struct cmsghdr *cmsg;
- uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in_pktinfo))];
+ size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
#elif defined(IP_SENDSRCADDR)
struct cmsghdr *cmsg;
- uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in_addr))];
+ size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_addr)) / sizeof(size_t)) + 1];
#endif
assert(fd >= 0);
@@ -560,12 +560,19 @@ int avahi_send_dns_packet_ipv4(
return sendmsg_loop(fd, &msg, 0);
}
-int avahi_send_dns_packet_ipv6(int fd, AvahiIfIndex interface, AvahiDnsPacket *p, const AvahiIPv6Address *src_address, const AvahiIPv6Address *dst_address, uint16_t dst_port) {
+int avahi_send_dns_packet_ipv6(
+ int fd,
+ AvahiIfIndex interface,
+ AvahiDnsPacket *p,
+ const AvahiIPv6Address *src_address,
+ const AvahiIPv6Address *dst_address,
+ uint16_t dst_port) {
+
struct sockaddr_in6 sa;
struct msghdr msg;
struct iovec io;
struct cmsghdr *cmsg;
- uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in6_pktinfo))];
+ size_t cmsg_data[(CMSG_SPACE(sizeof(struct in6_pktinfo))/sizeof(size_t)) + 1];
assert(fd >= 0);
assert(p);
@@ -617,7 +624,14 @@ int avahi_send_dns_packet_ipv6(int fd, AvahiIfIndex interface, AvahiDnsPacket *p
return sendmsg_loop(fd, &msg, 0);
}
-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) {
+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) {
+
AvahiDnsPacket *p= NULL;
struct msghdr msg;
struct iovec io;
@@ -635,6 +649,11 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(int fd, AvahiIPv4Address *ret_src_add
goto fail;
}
+ if (ms < 0) {
+ avahi_log_warn("FIONREAD returned negative value.");
+ goto fail;
+ }
+
p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
io.iov_base = AVAHI_DNS_PACKET_DATA(p);
@@ -650,7 +669,14 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(int fd, AvahiIPv4Address *ret_src_add
msg.msg_flags = 0;
if ((l = recvmsg(fd, &msg, 0)) < 0) {
- avahi_log_warn("recvmsg(): %s", strerror(errno));
+ /* Linux returns EAGAIN when an invalid IP packet has been
+ recieved. We suppress warnings in this case because this might
+ create quite a bit of log traffic on machines with unstable
+ links. (See #60) */
+
+ if (errno != EAGAIN)
+ avahi_log_warn("recvmsg(): %s", strerror(errno));
+
goto fail;
}
@@ -714,7 +740,11 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(int fd, AvahiIPv4Address *ret_src_add
struct sockaddr_dl *sdl = (struct sockaddr_dl *) CMSG_DATA (cmsg);
if (ret_iface)
+#ifdef __sun
+ *ret_iface = *(uint_t*) sdl;
+#else
*ret_iface = (int) sdl->sdl_index;
+#endif
break;
}
@@ -747,7 +777,14 @@ fail:
return NULL;
}
-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) {
+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) {
+
AvahiDnsPacket *p = NULL;
struct msghdr msg;
struct iovec io;
@@ -764,6 +801,11 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(int fd, AvahiIPv6Address *ret_src_add
avahi_log_warn("ioctl(): %s", strerror(errno));
goto fail;
}
+
+ if (ms < 0) {
+ avahi_log_warn("FIONREAD returned negative value.");
+ goto fail;
+ }
p = avahi_dns_packet_new(ms + AVAHI_DNS_PACKET_EXTRA_SIZE);
@@ -781,7 +823,14 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(int fd, AvahiIPv6Address *ret_src_add
msg.msg_flags = 0;
if ((l = recvmsg(fd, &msg, 0)) < 0) {
- avahi_log_warn("recvmsg(): %s", strerror(errno));
+ /* Linux returns EAGAIN when an invalid IP packet has been
+ recieved. We suppress warnings in this case because this might
+ create quite a bit of log traffic on machines with unstable
+ links. (See #60) */
+
+ if (errno != EAGAIN)
+ avahi_log_warn("recvmsg(): %s", strerror(errno));
+
goto fail;
}
@@ -836,7 +885,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(int fd, AvahiIPv6Address *ret_src_add
assert(found_iface);
assert(found_ttl);
-
+
return p;
fail:
@@ -888,13 +937,19 @@ fail:
int avahi_open_unicast_socket_ipv6(void) {
struct sockaddr_in6 local;
- int fd = -1;
+ int fd = -1, yes;
if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
avahi_log_warn("socket() failed: %s", strerror(errno));
goto fail;
}
+ yes = 1;
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) {
+ avahi_log_warn("IPV6_V6ONLY failed: %s", strerror(errno));
+ goto fail;
+ }
+
memset(&local, 0, sizeof(local));
local.sin6_family = AF_INET6;