public static unsafe void SetAddressFamily(byte[] buffer, AddressFamily family)
{
+ if ((int)(family) > (int)AddressFamily.Max)
+ {
+ // For legacy values up to AddressFamily.Max, family maps directly to Winsock value.
+ // Other values will need mapping if/when supported.
+ // Currently, that is Netlink, Packet and ControllerAreaNetwork, neither of them supported on Windows.
+ throw new PlatformNotSupportedException();
+ }
+
#if BIGENDIAN
buffer[0] = unchecked((byte)((int)family >> 8));
buffer[1] = unchecked((byte)((int)family));
Assert.Equal(expected, sa.ToString());
}
- [ActiveIssue(37997, TestPlatforms.AnyUnix)]
- [Theory] // recombine into ToString_Expected_Success when #37997 is fixed
- [InlineData((AddressFamily)12345, -1, false, "12345:32:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}")]
- public static void ToString_UnknownFamily_Success(AddressFamily family, int size, bool fillBytes, string expected) =>
- ToString_Expected_Success(family, size, fillBytes, expected);
+ [Theory]
+ [InlineData((AddressFamily)12345, -1)]
+ [InlineData((AddressFamily)12345, 16)]
+ public static void ToString_UnknownFamily_Throws(AddressFamily family, int size)
+ {
+ Assert.Throws<PlatformNotSupportedException>(() => size >= 0 ? new SocketAddress(family, size) : new SocketAddress(family));
+ }
+
+ [Theory]
+ [InlineData(AddressFamily.Packet)]
+ [InlineData(AddressFamily.Netlink)]
+ [InlineData(AddressFamily.ControllerAreaNetwork)]
+ [PlatformSpecific(~TestPlatforms.Linux)]
+ public static void ToString_UnsupportedFamily_Throws(AddressFamily family)
+ {
+ Assert.Throws<PlatformNotSupportedException>(() => new SocketAddress(family));
+ }
+
+ [Theory]
+ [InlineData(AddressFamily.Packet)]
+ [InlineData(AddressFamily.ControllerAreaNetwork)]
+ [PlatformSpecific(TestPlatforms.Linux)]
+ public static void ToString_LinuxSpecificFamily_Success(AddressFamily family)
+ {
+ SocketAddress sa = new SocketAddress(family);
+ Assert.Equal(family, sa.Family);
+ }
+
+ [Fact]
+ [PlatformSpecific(TestPlatforms.Windows)]
+ public static void ToString_AllFamilies_Success()
+ {
+ foreach (AddressFamily family in Enum.GetValues(typeof(AddressFamily)))
+ {
+ if ((int)family > (int)AddressFamily.Max)
+ {
+ // Skip Linux specific protocols.
+ continue;
+ }
+
+ var sa = new SocketAddress(family);
+ Assert.NotNull(sa.ToString());
+ }
+ }
}
}