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,7 +822,9 @@ 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)
{
msg.msg_controllen = len;
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr)) for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO) if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
{ {
@@ -834,6 +837,7 @@ int tcp_interface(int fd, int af)
if_index = p.p->ipi_ifindex; if_index = p.p->ipi_ifindex;
} }
} }
}
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
else else
{ {
@@ -850,8 +854,9 @@ 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)
{ {
msg.msg_controllen = len;
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr)) 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)
{ {