Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Native/Common/pal_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#cmakedefine01 HAVE_ECHO
#cmakedefine01 HAVE_ICANON
#cmakedefine01 HAVE_TCSANOW
#cmakedefine01 HAVE_IN_PKTINFO

// Mac OS X has stat64, but it is deprecated since plain stat now
// provides the same 64-bit aware struct when targeting OS X > 10.5
Expand Down
19 changes: 19 additions & 0 deletions src/Native/System.Native/pal_networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
#include <unistd.h>
#include <vector>

#if !HAVE_IN_PKTINFO
// On platforms, such as FreeBSD, where in_pktinfo
// is not available, fallback to custom definition
// with required members.
struct in_pktinfo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: an explanatory comment would be nice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.

{
in_addr ipi_addr;
};
#define IP_PKTINFO IP_RECVDSTADDR
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this instead of the typedef?

struct in_pktinfo
{
    in_addr ipi_addr;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really confusing me below that in_pktinfo has to be used completely differently than when typedef'ed here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguerrera, I like your approach. Thank you. I have defined the suggested struct.

#if !defined(IPV6_ADD_MEMBERSHIP) && defined(IPV6_JOIN_GROUP)
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#endif
Expand Down Expand Up @@ -1055,7 +1066,15 @@ static int32_t GetIPv4PacketInformation(cmsghdr* controlMessage, IPPacketInforma

auto* pktinfo = reinterpret_cast<in_pktinfo*>(CMSG_DATA(controlMessage));
ConvertInAddrToByteArray(&packetInfo->Address.Address[0], NUM_BYTES_IN_IPV4_ADDRESS, pktinfo->ipi_addr);
#if HAVE_IN_PKTINFO
packetInfo->InterfaceIndex = static_cast<int32_t>(pktinfo->ipi_ifindex);
#else
// TODO: Figure out how to get interface index with in_addr.
// One option is http://www.unix.com/man-page/freebsd/3/if_nametoindex
// which requires interface name to be known.
// Meanwhile:
packetInfo->InterfaceIndex = 0;
#endif

return 1;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Native/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,31 @@ include(CheckIncludeFiles)
include(CheckPrototypeDefinition)
include(CheckStructHasMember)
include(CheckSymbolExists)
include(CheckTypeSize)

#CMake does not include /usr/local/include into the include search path
#thus add it manually. This is required on FreeBSD.
include_directories(SYSTEM /usr/local/include)

# in_pktinfo: Find whether this struct exists
check_include_files(
linux/in.h
HAVE_LINUX_IN_H)

if (HAVE_LINUX_IN_H)
set (SOCKET_INCLUDES ${SOCKET_INCLUDES} linux/in.h)
else ()
set (SOCKET_INCLUDES ${SOCKET_INCLUDES} netinet/in.h)
endif ()

set(CMAKE_EXTRA_INCLUDE_FILES ${SOCKET_INCLUDES})
check_type_size(
"struct in_pktinfo"
HAVE_IN_PKTINFO
BUILTIN_TYPES_ONLY)
set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
# /in_pktinfo

check_include_files(
alloca.h
HAVE_ALLOCA_H)
Expand Down