diff --git a/src/native/libs/System.Native/pal_interfaceaddresses.c b/src/native/libs/System.Native/pal_interfaceaddresses.c index e81e2110860b95..b05119512216b5 100644 --- a/src/native/libs/System.Native/pal_interfaceaddresses.c +++ b/src/native/libs/System.Native/pal_interfaceaddresses.c @@ -46,6 +46,13 @@ #include "ios/net/if_media.h" #endif +// SunOS defines both AF_LINK and AF_PACKET but AF_LINK is preferred. +// Using AF_PACKET on SunOS requires access to system-private headers. +// Use undef to keep all the changes here. +#if defined(TARGET_SUNOS) +#undef AF_PACKET +#endif + #if defined(AF_PACKET) #include #if HAVE_NETPACKET_PACKET_H diff --git a/src/native/libs/System.Native/pal_maphardwaretype.c b/src/native/libs/System.Native/pal_maphardwaretype.c index 2a9e78216074ae..fd7520da21bfe8 100644 --- a/src/native/libs/System.Native/pal_maphardwaretype.c +++ b/src/native/libs/System.Native/pal_maphardwaretype.c @@ -7,6 +7,13 @@ #include #include +// SunOS defines both AF_LINK and AF_PACKET but AF_LINK is preferred. +// Using AF_PACKET on SunOS requires access to system-private headers. +// Use undef to keep all the changes here. +#if defined(TARGET_SUNOS) +#undef AF_PACKET +#endif + #if defined(AF_PACKET) #if HAVE_NETPACKET_PACKET_H #include diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 3b460d4c4e8296..07ed77b7cf7b81 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -204,6 +204,11 @@ static bool TryConvertAddressFamilyPlatformToPal(sa_family_t platformAddressFami *palAddressFamily = AddressFamily_AF_PACKET; return true; #endif +#ifdef AF_LINK + case AF_LINK: + *palAddressFamily = AddressFamily_AF_LINK; + return true; +#endif #ifdef AF_CAN case AF_CAN: *palAddressFamily = AddressFamily_AF_CAN; @@ -241,6 +246,11 @@ static bool TryConvertAddressFamilyPalToPlatform(int32_t palAddressFamily, sa_fa *platformAddressFamily = AF_PACKET; return true; #endif +#ifdef AF_LINK + case AddressFamily_AF_LINK: + *platformAddressFamily = AF_LINK; + return true; +#endif #ifdef AF_CAN case AddressFamily_AF_CAN: *platformAddressFamily = AF_CAN; @@ -2546,6 +2556,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = palProtocolType; return true; #endif +#ifdef AF_LINK + case AddressFamily_AF_LINK: + *platformProtocolType = palProtocolType; + return true; +#endif #if HAVE_LINUX_CAN_H case AddressFamily_AF_CAN: switch (palProtocolType) @@ -2685,6 +2700,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = platformProtocolType; return true; #endif +#ifdef AF_LINK + case AddressFamily_AF_LINK: + *palProtocolType = platformProtocolType; + return true; +#endif #if HAVE_LINUX_CAN_H case AddressFamily_AF_CAN: switch (platformProtocolType) diff --git a/src/native/libs/System.Native/pal_networking.h b/src/native/libs/System.Native/pal_networking.h index c393a3dbad4619..2a42329fc02fe1 100644 --- a/src/native/libs/System.Native/pal_networking.h +++ b/src/native/libs/System.Native/pal_networking.h @@ -66,6 +66,7 @@ typedef enum AddressFamily_AF_UNIX = 1, // System.Net.AddressFamily.Unix AddressFamily_AF_INET = 2, // System.Net.AddressFamily.InterNetwork AddressFamily_AF_INET6 = 23, // System.Net.AddressFamily.InterNetworkV6 + AddressFamily_AF_LINK = 13, // System.Net.AddressFamily.DataLink AddressFamily_AF_PACKET = 65536, // System.Net.AddressFamily.Packet AddressFamily_AF_CAN = 65537, // System.Net.AddressFamily.ControllerAreaNetwork } AddressFamily;