Skip to content

Commit

Permalink
only use IPV6_PKTINFO if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Nov 6, 2015
1 parent cade45b commit 948216e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions iputils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ bool HarvestDestinationAddress(struct msghdr* msgh, ComboAddress* destination)
}
#endif

#if defined(IPV6_PKTINFO)
if ((cmsg->cmsg_level == IPPROTO_IPV6) && (cmsg->cmsg_type == IPV6_PKTINFO)) {
struct in6_pktinfo *i = (struct in6_pktinfo *) CMSG_DATA(cmsg);
destination->sin6.sin6_addr = i->ipi6_addr;
destination->sin4.sin_family = AF_INET6;
return true;
}
#endif
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour
struct cmsghdr *cmsg = NULL;

if(source->sin4.sin_family == AF_INET6) {
#ifdef IPV6_PKTINFO
struct in6_pktinfo *pkt;

msgh->msg_control = cmsgbuf;
Expand All @@ -671,6 +672,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour
memset(pkt, 0, sizeof(*pkt));
pkt->ipi6_addr = source->sin6.sin6_addr;
msgh->msg_controllen = cmsg->cmsg_len; // makes valgrind happy and is slightly better style
#endif
}
else {
#ifdef IP_PKTINFO
Expand Down

0 comments on commit 948216e

Please sign in to comment.