}
#endif
- private const int NativeErrorToSocketErrorCount = 41;
+ private const int NativeErrorToSocketErrorCount = 42;
private const int SocketErrorToNativeErrorCount = 40;
// No Interop.Errors are included for the following SocketErrors, as there's no good mapping:
{ Interop.Error.ENOTCONN, SocketError.NotConnected },
{ Interop.Error.ENOTSOCK, SocketError.NotSocket },
{ Interop.Error.ENOTSUP, SocketError.OperationNotSupported },
+ { Interop.Error.EPERM, SocketError.AccessDenied },
{ Interop.Error.EPIPE, SocketError.Shutdown },
{ Interop.Error.EPFNOSUPPORT, SocketError.ProtocolFamilyNotSupported },
{ Interop.Error.EPROTONOSUPPORT, SocketError.ProtocolNotSupported },
// SocketError.IOPending also maps closest to EINPROGRESS. As such, roundtripping won't necessarily provide the original value 100% of the time,
// but it's the best we can do given the mismatch between Interop.Error and SocketError.
- { SocketError.AccessDenied, Interop.Error.EACCES},
+ { SocketError.AccessDenied, Interop.Error.EACCES}, // could also have been EPERM
{ SocketError.AddressAlreadyInUse, Interop.Error.EADDRINUSE },
{ SocketError.AddressNotAvailable, Interop.Error.EADDRNOTAVAIL },
{ SocketError.AddressFamilyNotSupported, Interop.Error.EAFNOSUPPORT },
};
private static bool SupportsRawSockets => AdminHelpers.IsProcessElevated();
+ private static bool NotSupportsRawSockets => !SupportsRawSockets;
[OuterLoop] // TODO: Issue #11345
[Theory, MemberData(nameof(DualModeSuccessInputs))]
[InlineData(AddressFamily.InterNetworkV6, ProtocolType.Udp)]
[InlineData(AddressFamily.InterNetworkV6, ProtocolType.IcmpV6)]
[ConditionalTheory(nameof(SupportsRawSockets))]
- public void Ctor_Raw_Success(AddressFamily addressFamily, ProtocolType protocolType)
+ public void Ctor_Raw_Supported_Success(AddressFamily addressFamily, ProtocolType protocolType)
{
using (new Socket(addressFamily, SocketType.Raw, protocolType))
{
}
}
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ [InlineData(AddressFamily.InterNetwork, ProtocolType.Tcp)]
+ [InlineData(AddressFamily.InterNetwork, ProtocolType.Udp)]
+ [InlineData(AddressFamily.InterNetwork, ProtocolType.Icmp)]
+ [InlineData(AddressFamily.InterNetworkV6, ProtocolType.Tcp)]
+ [InlineData(AddressFamily.InterNetworkV6, ProtocolType.Udp)]
+ [InlineData(AddressFamily.InterNetworkV6, ProtocolType.IcmpV6)]
+ [ConditionalTheory(nameof(NotSupportsRawSockets))]
+ public void Ctor_Raw_NotSupported_ExpectedError(AddressFamily addressFamily, ProtocolType protocolType)
+ {
+ SocketException e = Assert.Throws<SocketException>(() => new Socket(addressFamily, SocketType.Raw, protocolType));
+ Assert.Contains(e.SocketErrorCode, new[] { SocketError.AccessDenied, SocketError.ProtocolNotSupported });
+ }
+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Sockets are still inheritable on netfx: https://github.com/dotnet/corefx/pull/32903")]
[Theory]
[InlineData(true, 0)] // Accept