public class NetworkAddressFactoryImpl extends Object implements NetworkAddressFactory
| Modifier and Type | Field and Description |
|---|---|
protected List<InetAddress> |
bindAddresses |
static int |
DEFAULT_MULTICAST_RESPONSE_LISTEN_PORT |
static int |
DEFAULT_TCP_HTTP_LISTEN_PORT |
protected int |
multicastResponsePort |
protected List<NetworkInterface> |
networkInterfaces |
protected int |
streamListenPort |
protected Set<String> |
useAddresses |
protected Set<String> |
useInterfaces |
SYSTEM_PROPERTY_NET_ADDRESSES, SYSTEM_PROPERTY_NET_IFACES| Constructor and Description |
|---|
NetworkAddressFactoryImpl()
Defaults to an ephemeral port.
|
NetworkAddressFactoryImpl(int streamListenPort,
int multicastResponsePort) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
discoverBindAddresses() |
protected void |
discoverNetworkInterfaces() |
Short |
getAddressNetworkPrefixLength(InetAddress inetAddress) |
Iterator<InetAddress> |
getBindAddresses()
The caller might
remove() an address if initialization fails. |
protected InetAddress |
getBindAddressInSubnetOf(InetAddress inetAddress) |
InetAddress |
getBroadcastAddress(InetAddress inetAddress) |
byte[] |
getHardwareAddress(InetAddress inetAddress) |
protected List<InetAddress> |
getInetAddresses(NetworkInterface networkInterface) |
protected List<InterfaceAddress> |
getInterfaceAddresses(NetworkInterface networkInterface) |
InetAddress |
getLocalAddress(NetworkInterface networkInterface,
boolean isIPv6,
InetAddress remoteAddress)
Best-effort attempt finding a reachable local address for a given remote host.
|
InetAddress |
getMulticastGroup() |
int |
getMulticastPort() |
int |
getMulticastResponsePort() |
Iterator<NetworkInterface> |
getNetworkInterfaces()
The caller might
remove() an interface if initialization fails. |
int |
getStreamListenPort() |
boolean |
hasUsableNetwork() |
protected boolean |
isInSubnet(byte[] ip,
byte[] network,
short prefix) |
protected boolean |
isUsableAddress(NetworkInterface networkInterface,
InetAddress address)
Validation of every discovered local address.
|
protected boolean |
isUsableNetworkInterface(NetworkInterface iface)
Validation of every discovered network interface.
|
void |
logInterfaceInformation()
For debugging, logs all "usable" network interface(s) details with INFO level.
|
protected void |
logInterfaceInformation(NetworkInterface networkInterface) |
protected boolean |
requiresNetworkInterface() |
public static final int DEFAULT_TCP_HTTP_LISTEN_PORT
public static final int DEFAULT_MULTICAST_RESPONSE_LISTEN_PORT
protected final List<NetworkInterface> networkInterfaces
protected final List<InetAddress> bindAddresses
protected int streamListenPort
protected int multicastResponsePort
public NetworkAddressFactoryImpl()
throws InitializationException
InitializationExceptionpublic NetworkAddressFactoryImpl(int streamListenPort,
int multicastResponsePort)
throws InitializationException
InitializationExceptionprotected boolean requiresNetworkInterface()
true (the default) if a MissingNetworkInterfaceException should be thrownpublic void logInterfaceInformation()
NetworkAddressFactorylogInterfaceInformation in interface NetworkAddressFactorypublic InetAddress getMulticastGroup()
getMulticastGroup in interface NetworkAddressFactorypublic int getMulticastPort()
getMulticastPort in interface NetworkAddressFactorypublic int getMulticastResponsePort()
getMulticastResponsePort in interface NetworkAddressFactorypublic int getStreamListenPort()
getStreamListenPort in interface NetworkAddressFactorypublic Iterator<NetworkInterface> getNetworkInterfaces()
NetworkAddressFactoryremove() an interface if initialization fails.getNetworkInterfaces in interface NetworkAddressFactorypublic Iterator<InetAddress> getBindAddresses()
NetworkAddressFactoryremove() an address if initialization fails.getBindAddresses in interface NetworkAddressFactorypublic boolean hasUsableNetwork()
hasUsableNetwork in interface NetworkAddressFactorytrue if there is at least one usable network interface and bind address.public byte[] getHardwareAddress(InetAddress inetAddress)
getHardwareAddress in interface NetworkAddressFactoryinetAddress - An address of a local network interface.null if no
hardware address could be obtained.public InetAddress getBroadcastAddress(InetAddress inetAddress)
getBroadcastAddress in interface NetworkAddressFactoryinetAddress - An address of a local network interface.null if no
broadcast address could be obtained.public Short getAddressNetworkPrefixLength(InetAddress inetAddress)
getAddressNetworkPrefixLength in interface NetworkAddressFactorynull.public InetAddress getLocalAddress(NetworkInterface networkInterface, boolean isIPv6, InetAddress remoteAddress)
NetworkAddressFactoryThis method is called whenever a multicast datagram has been received. We need to be able to communicate with the sender using UDP unicast and we need to tell the sender how we are reachable with TCP requests. We need a local address that is in the same subnet as the senders address, that is reachable from the senders point of view.
getLocalAddress in interface NetworkAddressFactorynetworkInterface - The network interface to examine.isIPv6 - True if the given remote address is an IPv6 address.remoteAddress - The remote address for which to find a local address in the same subnet.protected List<InterfaceAddress> getInterfaceAddresses(NetworkInterface networkInterface)
protected List<InetAddress> getInetAddresses(NetworkInterface networkInterface)
protected InetAddress getBindAddressInSubnetOf(InetAddress inetAddress)
protected boolean isInSubnet(byte[] ip,
byte[] network,
short prefix)
protected void discoverNetworkInterfaces()
throws InitializationException
InitializationExceptionprotected boolean isUsableNetworkInterface(NetworkInterface iface) throws Exception
Override this method to customize which network interfaces are used.
The given implementation ignores interfaces which are
iface - The interface to validate.Exception - If any validation test failed with an un-recoverable error.protected void discoverBindAddresses()
throws InitializationException
InitializationExceptionprotected boolean isUsableAddress(NetworkInterface networkInterface, InetAddress address)
Override this method to customize which network addresses are used.
The given implementation ignores addresses which are
networkInterface - The interface to validate.address - The address of this interface to validate.protected void logInterfaceInformation(NetworkInterface networkInterface) throws SocketException
SocketExceptionCopyright © 2023 jUPnP.org. All rights reserved.