Tidy code.

This commit is contained in:
Simon Kelley
2016-03-16 19:00:45 +00:00
parent 4caa86dd7d
commit 529b030228

View File

@@ -810,10 +810,11 @@ int tcp_interface(int fd, int af)
int opt = 1; int opt = 1;
struct cmsghdr *cmptr; struct cmsghdr *cmptr;
struct msghdr msg; struct msghdr msg;
socklen_t len;
/* use mshdr do that the CMSDG_* macros are available */ /* use mshdr so that the CMSDG_* macros are available */
msg.msg_control = daemon->packet; msg.msg_control = daemon->packet;
msg.msg_controllen = daemon->packet_buff_sz; msg.msg_controllen = len = daemon->packet_buff_sz;
/* we overwrote the buffer... */ /* we overwrote the buffer... */
daemon->srv_save = NULL; daemon->srv_save = NULL;
@@ -821,18 +822,21 @@ int tcp_interface(int fd, int af)
if (af == AF_INET) if (af == AF_INET)
{ {
if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)) != -1 && if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)) != -1 &&
getsockopt(fd, IPPROTO_IP, IP_PKTOPTIONS, msg.msg_control, (socklen_t *)&msg.msg_controllen) != -1) getsockopt(fd, IPPROTO_IP, IP_PKTOPTIONS, msg.msg_control, &len) != -1)
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr)) {
if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO) msg.msg_controllen = len;
{ for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
union { if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
unsigned char *c; {
struct in_pktinfo *p; union {
} p; unsigned char *c;
struct in_pktinfo *p;
p.c = CMSG_DATA(cmptr); } p;
if_index = p.p->ipi_ifindex;
} p.c = CMSG_DATA(cmptr);
if_index = p.p->ipi_ifindex;
}
}
} }
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
else else
@@ -850,9 +854,10 @@ int tcp_interface(int fd, int af)
#endif #endif
if (set_ipv6pktinfo(fd) && if (set_ipv6pktinfo(fd) &&
getsockopt(fd, IPPROTO_IPV6, PKTOPTIONS, msg.msg_control, (socklen_t *)&msg.msg_controllen) != -1) getsockopt(fd, IPPROTO_IPV6, PKTOPTIONS, msg.msg_control, &len) != -1)
{ {
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr)) msg.msg_controllen = len;
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo) if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
{ {
union { union {