public TCPIPDestinationSource(Core core) { this.core = core; listenPort = core.Settings.TcpListenPort; // XXX: Use NetworkManager to support IP changes, // etc. without restarting Meshwork. var addresses = core.Platform.GetInterfaceAddresses(); foreach (var address in addresses) { // Ignore loopback. if (IPAddress.IsLoopback(address.Address)) { continue; } // Only include addresses of the correct type. if (this is TCPIPv4DestinationSource && address.Address.AddressFamily != AddressFamily.InterNetwork) { continue; } if (this is TCPIPv6DestinationSource && address.Address.AddressFamily != AddressFamily.InterNetworkV6) { continue; } // XXX: Check for firewall. For now, we assume true because 99.99% of the // world is behind a NAT, the remaining 0.01% probably know what they are doing. var isOpenExternally = !Common.Utils.IsInternalIP(address.Address); IDestination destination = null; if (this is TCPIPv6DestinationSource) { var ip = address.Address; ip.ScopeId = 0; destination = (IDestination)Activator.CreateInstance(DestinationType, core, address.IPv6PrefixLength, ip, (uint)listenPort, isOpenExternally); } else { destination = (IDestination)Activator.CreateInstance(DestinationType, core, address.Address, (uint)listenPort, isOpenExternally); } destinations.Add(destination); DestinationAdded?.Invoke(destination); } }
protected TCPIPDestinationSource(AddressFamily addressFamily) { ListenPort = Core.Settings.TcpListenPort; // XXX: Use NetworkManager to support IP changes, // etc. without restarting Meshwork. foreach (InterfaceAddress address in Core.OS.GetInterfaceAddresses() .Where(i => !IPAddress.IsLoopback(i.Address) && i.Address.AddressFamily == addressFamily)) { IDestination destination = CreateDestination(address, ListenPort, address.Address.IsInternalIP()); destinations.Add(destination); DestinationAdded?.Invoke(this, new DestinationEventArgs(destination)); } }