public static string BuildAddress(this SocketAddressFamily family, Type rootType) { /* Guard against potentially parallel execution paths. We want unique * addresses regardless of where/when the request originated. */ lock (Sync) { var uuid = Guid.NewGuid(); // ReSharper disable once SwitchStatementMissingSomeCases switch (family) { case InProcess: return($"inproc://{uuid}"); case InterProcess: return($"ipc://pipe/{uuid}"); case IPv4: return($"tcp://127.0.0.1".WithPort(rootType)); case IPv6: return($"tcp://[::1]".WithPort(rootType)); case Unspecified: default: throw new ArgumentException($"Address invalid for family '{family}'", nameof(family)); } } }
private SocketAddressFamily VerifyFamily(SocketAddressFamily family) { if (new[] { Unspecified, ZeroTier }.Contains(family)) { throw new ArgumentException($"Family unsupported (for now): '{family}'", nameof(family)); } Report($"Running protocol tests for address family '{family}'."); return(family); }
internal unsafe DeviceAddress(pcap_addr *pcapAddress) { long num1 = *(long *)((IntPtr)pcapAddress + 8L); SocketAddressFamily socketAddressFamily = (SocketAddressFamily) * (ushort *)num1; switch (socketAddressFamily) { case SocketAddressFamily.Internet: if (num1 != 0L) { this._address = (SocketAddress) new IpV4SocketAddress((sockaddr *)num1); } ulong num2 = (ulong)*(long *)((IntPtr)pcapAddress + 16L); if ((long)num2 != 0L) { this._netmask = (SocketAddress) new IpV4SocketAddress((sockaddr *)num2); } ulong num3 = (ulong)*(long *)((IntPtr)pcapAddress + 24L); if ((long)num3 != 0L) { this._broadcast = (SocketAddress) new IpV4SocketAddress((sockaddr *)num3); } ulong num4 = (ulong)*(long *)((IntPtr)pcapAddress + 32L); if ((long)num4 == 0L) { break; } this._destination = (SocketAddress) new IpV4SocketAddress((sockaddr *)num4); break; case SocketAddressFamily.Internet6: if (num1 != 0L) { this._address = (SocketAddress) new IpV6SocketAddress((sockaddr *)num1); } ulong num5 = (ulong)*(long *)((IntPtr)pcapAddress + 16L); if ((long)num5 != 0L) { this._netmask = (SocketAddress) new IpV6SocketAddress((sockaddr *)num5); } ulong num6 = (ulong)*(long *)((IntPtr)pcapAddress + 24L); if ((long)num6 != 0L) { this._broadcast = (SocketAddress) new IpV6SocketAddress((sockaddr *)num6); } ulong num7 = (ulong)*(long *)((IntPtr)pcapAddress + 32L); if ((long)num7 == 0L) { break; } this._destination = (SocketAddress) new IpV6SocketAddress((sockaddr *)num7); break; default: throw new NotImplementedException("Device of family " + socketAddressFamily.ToString() + " is unsupported"); } }
public void ThatAddressMaintainsTheView(SocketAddressFamily family) { // Start from a sane baseline. var addy = new Address(); VerifyAddressSwitch(addy, (ushort)Unspecified); // TODO: TBD: a true combinatorics verification would be better, but this will do for now. // TODO: TBD: https://github.com/AArnott/Xunit.Combinatorial/issues/13 addy.Family = (ushort)family; VerifyAddressSwitch(addy); }
public void ThatEnumValuesAreCorrect(SocketAddressFamily family, ushort expected) { Assert.Equal(expected, (ushort)family); }
protected SocketAddress(ushort family) { this._family = (SocketAddressFamily)family; }
public static string BuildAddress <T>(this SocketAddressFamily family) => family.BuildAddress(typeof(T));
public Address(SocketAddressFamily family) : this((ushort)family) { }