Skip to content

Commit 00aded5

Browse files
Use IP_RECVDSTADDR in absence of IP_PKTINFO
On FreeBSD-like network stacks, the socket option IP_PKTINFO is unavailable, but the option IP_RECVDSTADDR can be used instead. This enables vsomeip for the new io-sock network stack on QNX 7.1+. Co-author: Eric Sjöström <[email protected]> @EriComic Change-Id: Ie348a09dabf9b48c5de9e5d2d7bf13c1e2973449
1 parent fd7758c commit 00aded5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

implementation/endpoints/src/udp_server_endpoint_impl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,13 @@ udp_server_endpoint_impl::set_multicast_option(
862862
int its_pktinfo_option(1);
863863
::setsockopt(multicast_socket_->native_handle(),
864864
(is_v4_ ? IPPROTO_IP : IPPROTO_IPV6),
865+
#if defined(IP_PKTINFO)
865866
(is_v4_ ? IP_PKTINFO : IPV6_RECVPKTINFO),
867+
#elif defined(IP_RECVDSTADDR)
868+
(is_v4_ ? IP_RECVDSTADDR : IPV6_RECVPKTINFO),
869+
#else
870+
#error "Platform not supported. Neither IP_PKTINFO nor IP_RECVDSTADDR is defined.";
871+
#endif
866872
&its_pktinfo_option, sizeof(its_pktinfo_option));
867873
#endif
868874

implementation/helper/boost/asio/detail/impl/socket_ops_ext.ipp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ signed_size_type recvfrom(socket_type s, buf* bufs, size_t count,
9696
cmsg != NULL;
9797
cmsg = CMSG_NXTHDR(&msg, cmsg))
9898
{
99+
#if defined(IP_PKTINFO)
99100
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_PKTINFO)
100101
continue;
101102

@@ -104,6 +105,18 @@ signed_size_type recvfrom(socket_type s, buf* bufs, size_t count,
104105
{
105106
da = boost::asio::ip::address_v4(ntohl(pi->ipi_addr.s_addr));
106107
}
108+
#elif defined(IP_RECVDSTADDR)
109+
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_RECVDSTADDR)
110+
continue;
111+
112+
struct in_addr *addr = (struct in_addr*) CMSG_DATA(cmsg);
113+
if (addr)
114+
{
115+
da = boost::asio::ip::address_v4(ntohl(addr->s_addr));
116+
}
117+
#else
118+
#error "Platform not supported. Neither IP_PKTINFO nor IP_RECVDSTADDR is defined.";
119+
#endif
107120
}
108121
}
109122
return result;

0 commit comments

Comments
 (0)