Skip to content

Commit

Permalink
Use IP_RECVDSTADDR in absence of IP_PKTINFO
Browse files Browse the repository at this point in the history
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
  • Loading branch information
danielfr-haleytek committed Oct 3, 2024
1 parent fd7758c commit ee80f4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions implementation/endpoints/src/udp_server_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,13 @@ udp_server_endpoint_impl::set_multicast_option(
int its_pktinfo_option(1);
::setsockopt(multicast_socket_->native_handle(),
(is_v4_ ? IPPROTO_IP : IPPROTO_IPV6),
#if defined(IP_PKTINFO)
(is_v4_ ? IP_PKTINFO : IPV6_RECVPKTINFO),
#elif defined(IP_RECVDSTADDR)
(is_v4_ ? IP_RECVDSTADDR : IPV6_RECVPKTINFO),
#else
#error "Platform not supported. Neither IP_PKTINFO nor IP_RECVDSTADDR is defined.";
#endif
&its_pktinfo_option, sizeof(its_pktinfo_option));
#endif

Expand Down
13 changes: 13 additions & 0 deletions implementation/helper/boost/asio/detail/impl/socket_ops_ext.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ signed_size_type recvfrom(socket_type s, buf* bufs, size_t count,
cmsg != NULL;
cmsg = CMSG_NXTHDR(&msg, cmsg))
{
#if defined(IP_PKTINFO)
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_PKTINFO)
continue;

Expand All @@ -104,6 +105,18 @@ signed_size_type recvfrom(socket_type s, buf* bufs, size_t count,
{
da = boost::asio::ip::address_v4(ntohl(pi->ipi_addr.s_addr));
}
#elif defined(IP_RECVDSTADDR)
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_RECVDSTADDR)
continue;

struct in_addr *addr = (struct in_addr*) CMSG_DATA(cmsg);
if (addr)
{
da = boost::asio::ip::address_v4(ntohl(addr->s_addr));
}
#else
#error "Platform not supported. Neither IP_PKTINFO nor IP_RECVDSTADDR is defined.";
#endif
}
}
return result;
Expand Down

0 comments on commit ee80f4e

Please sign in to comment.