#include <ifaddrs.h>
#endif
#endif
-
+#ifdef AF_CAN
+#include <linux/can.h>
+#endif
#if HAVE_KQUEUE
#if KEVENT_HAS_VOID_UDATA
static void* GetKeventUdata(uintptr_t udata)
case AF_INET6:
*palAddressFamily = AddressFamily_AF_INET6;
return true;
-
+#ifdef AF_NETLINK
+ case AF_NETLINK:
+ *palAddressFamily = AddressFamily_AF_NETLINK;
+ return true;
+#endif
+#ifdef AF_PACKET
+ case AF_PACKET:
+ *palAddressFamily = AddressFamily_AF_PACKET;
+ return true;
+#endif
+#ifdef AF_CAN
+ case AF_CAN:
+ *palAddressFamily = AddressFamily_AF_CAN;
+ return true;
+#endif
default:
*palAddressFamily = platformAddressFamily;
return false;
case AddressFamily_AF_INET6:
*platformAddressFamily = AF_INET6;
return true;
-
+#ifdef AF_PACKET
+ case AddressFamily_AF_PACKET:
+ *platformAddressFamily = AF_PACKET;
+ return true;
+#endif
+#ifdef AF_CAN
+ case AddressFamily_AF_CAN:
+ *platformAddressFamily = AF_CAN;
+ return true;
+#endif
default:
*platformAddressFamily = (sa_family_t)palAddressFamily;
return false;
}
}
-static bool TryConvertProtocolTypePalToPlatform(int32_t palProtocolType, int* platformProtocolType)
+static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_t palProtocolType, int* platformProtocolType)
{
assert(platformProtocolType != NULL);
- switch (palProtocolType)
+ switch(palAddressFamily)
{
- case ProtocolType_PT_UNSPECIFIED:
- *platformProtocolType = 0;
+#ifdef AF_PACKET
+ case AddressFamily_AF_PACKET:
+ // protocol is the IEEE 802.3 protocol number in network order.
+ *platformProtocolType = palProtocolType;
return true;
+#endif
+#ifdef AF_CAN
+ case AddressFamily_AF_CAN:
+ switch (palProtocolType)
+ {
+ case ProtocolType_PT_UNSPECIFIED:
+ *platformProtocolType = 0;
+ return true;
- case ProtocolType_PT_ICMP:
- *platformProtocolType = IPPROTO_ICMP;
- return true;
+ case ProtocolType_PT_RAW:
+ *platformProtocolType = CAN_RAW;
+ return true;
- case ProtocolType_PT_TCP:
- *platformProtocolType = IPPROTO_TCP;
- return true;
+ default:
+ *platformProtocolType = (int)palProtocolType;
+ return false;
+ }
+#endif
+ case AddressFamily_AF_INET:
+ switch (palProtocolType)
+ {
+ case ProtocolType_PT_UNSPECIFIED:
+ *platformProtocolType = 0;
+ return true;
- case ProtocolType_PT_UDP:
- *platformProtocolType = IPPROTO_UDP;
- return true;
+ case ProtocolType_PT_ICMP:
+ *platformProtocolType = IPPROTO_ICMP;
+ return true;
- case ProtocolType_PT_ICMPV6:
- *platformProtocolType = IPPROTO_ICMPV6;
- return true;
+ case ProtocolType_PT_TCP:
+ *platformProtocolType = IPPROTO_TCP;
+ return true;
+
+ case ProtocolType_PT_UDP:
+ *platformProtocolType = IPPROTO_UDP;
+ return true;
+
+ case ProtocolType_PT_IGMP:
+ *platformProtocolType = IPPROTO_IGMP;
+ return true;
+
+ case ProtocolType_PT_RAW:
+ *platformProtocolType = IPPROTO_RAW;
+ return true;
+
+ default:
+ *platformProtocolType = (int)palProtocolType;
+ return false;
+ }
+
+ case AddressFamily_AF_INET6:
+ switch (palProtocolType)
+ {
+ case ProtocolType_PT_UNSPECIFIED:
+ *platformProtocolType = 0;
+ return true;
+
+ case ProtocolType_PT_ICMPV6:
+ case ProtocolType_PT_ICMP:
+ *platformProtocolType = IPPROTO_ICMPV6;
+ return true;
+
+ case ProtocolType_PT_TCP:
+ *platformProtocolType = IPPROTO_TCP;
+ return true;
+
+ case ProtocolType_PT_UDP:
+ *platformProtocolType = IPPROTO_UDP;
+ return true;
+
+ case ProtocolType_PT_IGMP:
+ *platformProtocolType = IPPROTO_IGMP;
+ return true;
+
+ case ProtocolType_PT_RAW:
+ *platformProtocolType = IPPROTO_RAW;
+ return true;
+
+ case ProtocolType_PT_DSTOPTS:
+ *platformProtocolType = IPPROTO_DSTOPTS;
+ return true;
+
+ case ProtocolType_PT_NONE:
+ *platformProtocolType = IPPROTO_NONE;
+ return true;
+
+ case ProtocolType_PT_ROUTING:
+ *platformProtocolType = IPPROTO_ROUTING;
+ return true;
+
+ case ProtocolType_PT_FRAGMENT:
+ *platformProtocolType = IPPROTO_FRAGMENT;
+ return true;
+
+ default:
+ *platformProtocolType = (int)palProtocolType;
+ return false;
+ }
default:
- *platformProtocolType = (int)palProtocolType;
- return false;
+ switch (palProtocolType)
+ {
+ case ProtocolType_PT_UNSPECIFIED:
+ *platformProtocolType = 0;
+ return true;
+ default:
+ *platformProtocolType = (int)palProtocolType;
+ return false;
+ }
}
}
return Error_EPROTOTYPE;
}
- if (!TryConvertProtocolTypePalToPlatform(protocolType, &platformProtocolType))
+ if (!TryConvertProtocolTypePalToPlatform(addressFamily, protocolType, &platformProtocolType))
{
*createdSocket = -1;
return Error_EPROTONOSUPPORT;
*/
typedef enum
{
- AddressFamily_AF_UNSPEC = 0, // System.Net.AddressFamily.Unspecified
- 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_UNSPEC = 0, // System.Net.AddressFamily.Unspecified
+ 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_NETLINK = 30, // System.Net.AddressFamily.Netlink
+ AddressFamily_AF_PACKET = 31, // System.Net.AddressFamily.Packet
+ AddressFamily_AF_CAN = 32, // System.Net.AddressFamily.ControllerAreaNetwork
} AddressFamily;
/*
ProtocolType_PT_TCP = 6, // System.Net.ProtocolType.Tcp
ProtocolType_PT_UDP = 17, // System.Net.ProtocolType.Udp
ProtocolType_PT_ICMPV6 = 58, // System.Net.ProtocolType.IcmpV6
+ ProtocolType_PT_RAW = 255, // System.Net.ProtocolType.Raw
+ ProtocolType_PT_IGMP = 2, // System.Net.ProtocolType.Igmp
+ ProtocolType_PT_NONE = 59, // System.Net.ProtocolType.IPv6NoNextHeader
+ ProtocolType_PT_DSTOPTS = 60, // System.Net.ProtocolType.IPv6DestinationOptions
+ ProtocolType_PT_ROUTING = 43, // System.Net.ProtocolType.IPv6RoutingHeader
+ ProtocolType_PT_FRAGMENT = 44, // System.Net.ProtocolType.IPv6FragmentHeader
} ProtocolType;
typedef enum
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics;
+using System.IO;
+using System.IO.Pipes;
+using System.Threading.Tasks;
+using Microsoft.DotNet.RemoteExecutor;
+using Xunit;
+
+namespace System.Net.Sockets.Tests
+{
+ public partial class CreateSocket
+ {
+ [Theory]
+ [InlineData(AddressFamily.Netlink)]
+ [InlineData(AddressFamily.Packet)]
+ [InlineData(AddressFamily.ControllerAreaNetwork)]
+ [PlatformSpecific(~TestPlatforms.Linux)]
+ public void Ctor_Netcoreapp_Throws(AddressFamily addressFamily)
+ {
+ // All protocols are Linux specific and throw on other platforms
+ Assert.Throws<SocketException>(() => new Socket(addressFamily, SocketType.Raw, 0));
+ }
+
+ [Theory]
+ [InlineData(AddressFamily.Netlink)]
+ [InlineData(AddressFamily.Packet)]
+ [InlineData(AddressFamily.ControllerAreaNetwork)]
+ [PlatformSpecific(TestPlatforms.Linux)]
+ public void Ctor_Netcoreapp_Success(AddressFamily addressFamily)
+ {
+ Socket s = null;
+ try
+ {
+ s = new Socket(addressFamily, SocketType.Raw, ProtocolType.Raw);
+ }
+ catch (SocketException e) when (e.SocketErrorCode == SocketError.AccessDenied ||
+ e.SocketErrorCode == SocketError.ProtocolNotSupported ||
+ e.SocketErrorCode == SocketError.AddressFamilyNotSupported)
+ {
+ // Ignore. We may not have privilege or protocol modules are not loaded.
+ return;
+ }
+ s.Close();
+ }
+ }
+}