summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Lucifredi <flucifredi@acm.org>2008-01-05 23:59:33 +0000
committerFederico Lucifredi <flucifredi@acm.org>2008-01-05 23:59:33 +0000
commit8e0acbabb161a63891b490498dec142960f2959f (patch)
tree391ade572a7a5f61a488f466e532bbc0a0d13347
parentfdd4aa4f08dc06c2ccca28cf90010be8cc9d60f2 (diff)
purged stray tabs, slaughtered loose whitespace.
git-svn-id: file:///home/lennart/svn/public/avahi/branches/federico@1676 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-core/socket.c176
1 files changed, 88 insertions, 88 deletions
diff --git a/avahi-core/socket.c b/avahi-core/socket.c
index 61b5eb4..67d6974 100644
--- a/avahi-core/socket.c
+++ b/avahi-core/socket.c
@@ -2,7 +2,7 @@
/***
This file is part of avahi.
-
+
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
@@ -157,7 +157,7 @@ int avahi_mdns_mcast_join_ipv6(int fd, const AvahiIPv6Address *a, int idx, int j
if (join)
setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6));
-
+
if (setsockopt(fd, IPPROTO_IPV6, join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
avahi_log_warn("%s failed: %s", join ? "IPV6_ADD_MEMBERSHIP" : "IPV6_DROP_MEMBERSHIP", strerror(errno));
return -1;
@@ -174,7 +174,7 @@ static int reuseaddr(int fd) {
avahi_log_warn("SO_REUSEADDR failed: %s", strerror(errno));
return -1;
}
-
+
#ifdef SO_REUSEPORT
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) {
@@ -182,30 +182,30 @@ static int reuseaddr(int fd) {
return -1;
}
#endif
-
+
return 0;
}
static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) {
-
+
assert(fd >= 0);
assert(sa);
assert(l > 0);
-
+
if (bind(fd, sa, l) < 0) {
if (errno != EADDRINUSE) {
avahi_log_warn("bind() failed: %s", strerror(errno));
return -1;
}
-
+
avahi_log_warn("*** WARNING: Detected another %s mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***",
sa->sa_family == AF_INET ? "IPv4" : "IPv6");
/* Try again, this time with SO_REUSEADDR set */
if (reuseaddr(fd) < 0)
return -1;
-
+
if (bind(fd, sa, l) < 0) {
avahi_log_warn("bind() failed: %s", strerror(errno));
return -1;
@@ -215,7 +215,7 @@ static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) {
/* We enable SO_REUSEADDR afterwards, to make sure that the
* user may run other mDNS implementations if he really
* wants. */
-
+
if (reuseaddr(fd) < 0)
return -1;
}
@@ -225,7 +225,7 @@ static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) {
static int ipv4_pktinfo(int fd) {
int yes;
-
+
#ifdef IP_PKTINFO
yes = 1;
if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
@@ -233,7 +233,7 @@ static int ipv4_pktinfo(int fd) {
return -1;
}
#else
-
+
#ifdef IP_RECVINTERFACE
yes = 1;
if (setsockopt (fd, IPPROTO_IP, IP_RECVINTERFACE, &yes, sizeof(yes)) < 0) {
@@ -247,7 +247,7 @@ static int ipv4_pktinfo(int fd) {
return -1;
}
#endif
-
+
#ifdef IP_RECVDSTADDR
yes = 1;
if (setsockopt (fd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof(yes)) < 0) {
@@ -255,7 +255,7 @@ static int ipv4_pktinfo(int fd) {
return -1;
}
#endif
-
+
#endif /* IP_PKTINFO */
#ifdef IP_RECVTTL
@@ -271,7 +271,7 @@ static int ipv4_pktinfo(int fd) {
static int ipv6_pktinfo(int fd) {
int yes;
-
+
#ifdef IPV6_RECVPKTINFO
yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0) {
@@ -313,12 +313,12 @@ int avahi_open_socket_ipv4(int no_reuse) {
struct sockaddr_in local;
int fd = -1, r, ittl;
uint8_t ttl, cyes;
-
+
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
avahi_log_warn("socket() failed: %s", strerror(errno));
goto fail;
}
-
+
ttl = 255;
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
avahi_log_warn("IP_MULTICAST_TTL failed: %s", strerror(errno));
@@ -330,13 +330,13 @@ int avahi_open_socket_ipv4(int no_reuse) {
avahi_log_warn("IP_TTL failed: %s", strerror(errno));
goto fail;
}
-
+
cyes = 1;
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &cyes, sizeof(cyes)) < 0) {
avahi_log_warn("IP_MULTICAST_LOOP failed: %s", strerror(errno));
goto fail;
}
-
+
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_port = htons(AVAHI_MDNS_PORT);
@@ -356,7 +356,7 @@ int avahi_open_socket_ipv4(int no_reuse) {
avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
goto fail;
}
-
+
if (avahi_set_nonblock(fd) < 0) {
avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
goto fail;
@@ -377,12 +377,12 @@ int avahi_open_socket_ipv6(int no_reuse) {
int ttl;
mdns_mcast_group_ipv6(&sa);
-
+
if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
avahi_log_warn("socket() failed: %s", strerror(errno));
goto fail;
}
-
+
ttl = 255;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
avahi_log_warn("IPV6_MULTICAST_HOPS failed: %s", strerror(errno));
@@ -394,7 +394,7 @@ int avahi_open_socket_ipv6(int no_reuse) {
avahi_log_warn("IPV6_UNICAST_HOPS 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));
@@ -410,7 +410,7 @@ int avahi_open_socket_ipv6(int no_reuse) {
memset(&local, 0, sizeof(local));
local.sin6_family = AF_INET6;
local.sin6_port = htons(AVAHI_MDNS_PORT);
-
+
if (no_reuse)
r = bind(fd, (struct sockaddr*) &local, sizeof(local));
else
@@ -421,12 +421,12 @@ int avahi_open_socket_ipv6(int no_reuse) {
if (ipv6_pktinfo(fd) < 0)
goto fail;
-
+
if (avahi_set_cloexec(fd) < 0) {
avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
goto fail;
}
-
+
if (avahi_set_nonblock(fd) < 0) {
avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
goto fail;
@@ -446,15 +446,15 @@ static int sendmsg_loop(int fd, struct msghdr *msg, int flags) {
assert(msg);
for (;;) {
-
+
if (sendmsg(fd, msg, flags) >= 0)
break;
-
+
if (errno != EAGAIN) {
avahi_log_debug("sendmsg() failed: %s", strerror(errno));
return -1;
}
-
+
if (avahi_wait_for_write(fd) < 0)
return -1;
}
@@ -469,7 +469,7 @@ int avahi_send_dns_packet_ipv4(
const AvahiIPv4Address *src_address,
const AvahiIPv4Address *dst_address,
uint16_t dst_port) {
-
+
struct sockaddr_in sa;
struct msghdr msg;
struct iovec io;
@@ -507,11 +507,11 @@ int avahi_send_dns_packet_ipv4(
#ifdef IP_PKTINFO
if (interface > 0 || src_address) {
struct in_pktinfo *pkti;
-
+
memset(cmsg_data, 0, sizeof(cmsg_data));
msg.msg_control = cmsg_data;
msg.msg_controllen = sizeof(cmsg_data);
-
+
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
cmsg->cmsg_level = IPPROTO_IP;
@@ -531,27 +531,27 @@ int avahi_send_dns_packet_ipv4(
if (src_address) {
struct in_addr *addr;
- memset(cmsg_data, 0, sizeof(cmsg_data));
- msg.msg_control = cmsg_data;
- msg.msg_controllen = sizeof(cmsg_data);
-
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
- cmsg->cmsg_level = IPPROTO_IP;
- cmsg->cmsg_type = IP_SENDSRCADDR;
-
- addr = (struct in_addr *)CMSG_DATA(cmsg);
- addr->s_addr = src_address->address;
+ memset(cmsg_data, 0, sizeof(cmsg_data));
+ msg.msg_control = cmsg_data;
+ msg.msg_controllen = sizeof(cmsg_data);
- msg.msg_controllen = cmsg->cmsg_len;
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
+ cmsg->cmsg_level = IPPROTO_IP;
+ cmsg->cmsg_type = IP_SENDSRCADDR;
+
+ addr = (struct in_addr *)CMSG_DATA(cmsg);
+ addr->s_addr = src_address->address;
+
+ msg.msg_controllen = cmsg->cmsg_len;
}
#elif defined(IP_MULTICAST_IF)
{
- struct in_addr any = { INADDR_ANY };
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, src_address ? (const void*) &src_address->address : (const void*) &any, sizeof(struct in_addr)) < 0) {
- avahi_log_warn("IP_MULTICAST_IF failed: %s", strerror(errno));
- return -1;
- }
+ struct in_addr any = { INADDR_ANY };
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, src_address ? (const void*) &src_address->address : (const void*) &any, sizeof(struct in_addr)) < 0) {
+ avahi_log_warn("IP_MULTICAST_IF failed: %s", strerror(errno));
+ return -1;
+ }
}
#elif defined(__GNUC__)
#warning "FIXME: We need some code to set the outgoing interface/local address here if IP_PKTINFO/IP_MULTICAST_IF is not available"
@@ -567,7 +567,7 @@ int avahi_send_dns_packet_ipv6(
const AvahiIPv6Address *src_address,
const AvahiIPv6Address *dst_address,
uint16_t dst_port) {
-
+
struct sockaddr_in6 sa;
struct msghdr msg;
struct iovec io;
@@ -601,12 +601,12 @@ int avahi_send_dns_packet_ipv6(
memset(cmsg_data, 0, sizeof(cmsg_data));
msg.msg_control = cmsg_data;
msg.msg_controllen = sizeof(cmsg_data);
-
+
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;
-
+
pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
if (interface > 0)
@@ -614,13 +614,13 @@ int avahi_send_dns_packet_ipv6(
if (src_address)
memcpy(&pkti->ipi6_addr, src_address->address, sizeof(src_address->address));
-
+
msg.msg_controllen = cmsg->cmsg_len;
} else {
msg.msg_control = NULL;
msg.msg_controllen = 0;
}
-
+
return sendmsg_loop(fd, &msg, 0);
}
@@ -631,7 +631,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
AvahiIPv4Address *ret_dst_address,
AvahiIfIndex *ret_iface,
uint8_t *ret_ttl) {
-
+
AvahiDnsPacket *p= NULL;
struct msghdr msg;
struct iovec io;
@@ -658,7 +658,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
io.iov_base = AVAHI_DNS_PACKET_DATA(p);
io.iov_len = p->max_size;
-
+
memset(&msg, 0, sizeof(msg));
msg.msg_name = &sa;
msg.msg_namelen = sizeof(sa);
@@ -667,7 +667,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
msg.msg_control = aux;
msg.msg_controllen = sizeof(aux);
msg.msg_flags = 0;
-
+
if ((l = recvmsg(fd, &msg, 0)) < 0) {
/* Linux returns EAGAIN when an invalid IP packet has been
recieved. We suppress warnings in this case because this might
@@ -704,11 +704,11 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
if (ret_iface)
*ret_iface = AVAHI_IF_UNSPEC;
-
+
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
-
+
if (cmsg->cmsg_level == IPPROTO_IP) {
-
+
switch (cmsg->cmsg_type) {
#ifdef IP_RECVTTL
case IP_RECVTTL:
@@ -722,23 +722,23 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
#ifdef IP_PKTINFO
case IP_PKTINFO: {
struct in_pktinfo *i = (struct in_pktinfo*) CMSG_DATA(cmsg);
-
+
if (ret_iface)
*ret_iface = (int) i->ipi_ifindex;
-
+
if (ret_dst_address)
ret_dst_address->address = i->ipi_addr.s_addr;
-
+
found_addr = 1;
break;
}
#endif
-
+
#ifdef IP_RECVIF
case IP_RECVIF: {
struct sockaddr_dl *sdl = (struct sockaddr_dl *) CMSG_DATA (cmsg);
-
+
if (ret_iface)
#ifdef __sun
*ret_iface = *(uint_t*) sdl;
@@ -749,16 +749,16 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv4(
break;
}
#endif
-
+
#ifdef IP_RECVDSTADDR
case IP_RECVDSTADDR:
if (ret_dst_address)
memcpy(&ret_dst_address->address, CMSG_DATA (cmsg), 4);
-
+
found_addr = 1;
break;
#endif
-
+
default:
avahi_log_warn("Unhandled cmsg_type : %d", cmsg->cmsg_type);
break;
@@ -784,7 +784,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(
AvahiIPv6Address *ret_dst_address,
AvahiIfIndex *ret_iface,
uint8_t *ret_ttl) {
-
+
AvahiDnsPacket *p = NULL;
struct msghdr msg;
struct iovec io;
@@ -806,22 +806,22 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(
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);
io.iov_len = p->max_size;
-
+
memset(&msg, 0, sizeof(msg));
msg.msg_name = (struct sockaddr*) &sa;
msg.msg_namelen = sizeof(sa);
-
+
msg.msg_iov = &io;
msg.msg_iovlen = 1;
msg.msg_control = aux;
msg.msg_controllen = sizeof(aux);
msg.msg_flags = 0;
-
+
if ((l = recvmsg(fd, &msg, 0)) < 0) {
/* Linux returns EAGAIN when an invalid IP packet has been
recieved. We suppress warnings in this case because this might
@@ -830,13 +830,13 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(
if (errno != EAGAIN)
avahi_log_warn("recvmsg(): %s", strerror(errno));
-
+
goto fail;
}
assert(!(msg.msg_flags & MSG_CTRUNC));
assert(!(msg.msg_flags & MSG_TRUNC));
-
+
p->size = (size_t) l;
if (ret_src_port)
@@ -860,22 +860,22 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(
*ret_ttl = (uint8_t) (*(int *) CMSG_DATA(cmsg));
found_ttl = 1;
-
+
break;
case IPV6_PKTINFO: {
struct in6_pktinfo *i = (struct in6_pktinfo*) CMSG_DATA(cmsg);
-
+
if (ret_iface)
*ret_iface = i->ipi6_ifindex;
-
+
if (ret_dst_address)
memcpy(ret_dst_address->address, i->ipi6_addr.s6_addr, 16);
found_iface = 1;
break;
}
-
+
default:
avahi_log_warn("Unhandled cmsg_type : %d", cmsg->cmsg_type);
break;
@@ -885,7 +885,7 @@ AvahiDnsPacket *avahi_recv_dns_packet_ipv6(
assert(found_iface);
assert(found_ttl);
-
+
return p;
fail:
@@ -898,15 +898,15 @@ fail:
int avahi_open_unicast_socket_ipv4(void) {
struct sockaddr_in local;
int fd = -1;
-
+
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
avahi_log_warn("socket() failed: %s", strerror(errno));
goto fail;
}
-
+
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
-
+
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
avahi_log_warn("bind() failed: %s", strerror(errno));
goto fail;
@@ -920,7 +920,7 @@ int avahi_open_unicast_socket_ipv4(void) {
avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
goto fail;
}
-
+
if (avahi_set_nonblock(fd) < 0) {
avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
goto fail;
@@ -938,12 +938,12 @@ fail:
int avahi_open_unicast_socket_ipv6(void) {
struct sockaddr_in6 local;
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));
@@ -952,7 +952,7 @@ int avahi_open_unicast_socket_ipv6(void) {
memset(&local, 0, sizeof(local));
local.sin6_family = AF_INET6;
-
+
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
avahi_log_warn("bind() failed: %s", strerror(errno));
goto fail;
@@ -960,12 +960,12 @@ int avahi_open_unicast_socket_ipv6(void) {
if (ipv6_pktinfo(fd) < 0)
goto fail;
-
+
if (avahi_set_cloexec(fd) < 0) {
avahi_log_warn("FD_CLOEXEC failed: %s", strerror(errno));
goto fail;
}
-
+
if (avahi_set_nonblock(fd) < 0) {
avahi_log_warn("O_NONBLOCK failed: %s", strerror(errno));
goto fail;