Klasse NetworkAddressFactoryImpl
- Alle implementierten Schnittstellen:
NetworkAddressFactory
This implementation has been tested on Windows XP, Windows Vista, Mac OS X 10.8, and whatever kernel ships in Ubuntu 9.04. This implementation does not support IPv6.
- Autor:
- Christian Bauer, Kai Kreuzer - added multicast response port, Laurent Garnier - added new parameter to provide a list of network interfaces to consider
-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprotected final List<InetAddress> static final intstatic final intprotected intprotected final List<NetworkInterface> protected intVon Schnittstelle geerbte Felder org.jupnp.transport.spi.NetworkAddressFactory
SYSTEM_PROPERTY_NET_ADDRESSES, SYSTEM_PROPERTY_NET_IFACES -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungDefaults to an ephemeral port.NetworkAddressFactoryImpl(int streamListenPort, int multicastResponsePort) NetworkAddressFactoryImpl(int streamListenPort, int multicastResponsePort, String interfaces) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungprotected voidprotected voidgetAddressNetworkPrefixLength(InetAddress inetAddress) The caller mightremove()an address if initialization fails.protected InetAddressgetBindAddressInSubnetOf(InetAddress inetAddress) getBroadcastAddress(InetAddress inetAddress) byte[]getHardwareAddress(InetAddress inetAddress) protected List<InetAddress> getInetAddresses(NetworkInterface networkInterface) protected List<InterfaceAddress> getInterfaceAddresses(NetworkInterface networkInterface) getLocalAddress(NetworkInterface networkInterface, boolean isIPv6, InetAddress remoteAddress) Best-effort attempt finding a reachable local address for a given remote host.intintThe caller mightremove()an interface if initialization fails.intbooleanprotected booleanisInSubnet(byte[] ip, byte[] network, short prefix) protected booleanisUsableAddress(NetworkInterface networkInterface, InetAddress address) Validation of every discovered local address.protected booleanValidation of every discovered network interface.voidFor debugging, logs all "usable" network interface(s) details with INFO level.protected voidlogInterfaceInformation(NetworkInterface networkInterface) protected boolean
-
Felddetails
-
DEFAULT_TCP_HTTP_LISTEN_PORT
public static final int DEFAULT_TCP_HTTP_LISTEN_PORT- Siehe auch:
-
DEFAULT_MULTICAST_RESPONSE_LISTEN_PORT
public static final int DEFAULT_MULTICAST_RESPONSE_LISTEN_PORT- Siehe auch:
-
useInterfaces
-
useAddresses
-
networkInterfaces
-
bindAddresses
-
streamListenPort
protected int streamListenPort -
multicastResponsePort
protected int multicastResponsePort
-
-
Konstruktordetails
-
NetworkAddressFactoryImpl
Defaults to an ephemeral port.- Löst aus:
InitializationException
-
NetworkAddressFactoryImpl
public NetworkAddressFactoryImpl(int streamListenPort, int multicastResponsePort) throws InitializationException - Löst aus:
InitializationException
-
NetworkAddressFactoryImpl
public NetworkAddressFactoryImpl(int streamListenPort, int multicastResponsePort, String interfaces) throws InitializationException - Löst aus:
InitializationException
-
-
Methodendetails
-
requiresNetworkInterface
protected boolean requiresNetworkInterface()- Gibt zurück:
true(the default) if aMissingNetworkInterfaceExceptionshould be thrown
-
logInterfaceInformation
public void logInterfaceInformation()Beschreibung aus Schnittstelle kopiert:NetworkAddressFactoryFor debugging, logs all "usable" network interface(s) details with INFO level.- Angegeben von:
logInterfaceInformationin SchnittstelleNetworkAddressFactory
-
getMulticastGroup
- Angegeben von:
getMulticastGroupin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The UDP multicast group to join.
-
getMulticastPort
public int getMulticastPort()- Angegeben von:
getMulticastPortin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The UDP multicast port to listen on.
-
getMulticastResponsePort
public int getMulticastResponsePort()- Angegeben von:
getMulticastResponsePortin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The UDP port to listen on for search responses.
-
getStreamListenPort
public int getStreamListenPort()- Angegeben von:
getStreamListenPortin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The TCP (HTTP) stream request port to listen on.
-
getNetworkInterfaces
Beschreibung aus Schnittstelle kopiert:NetworkAddressFactoryThe caller mightremove()an interface if initialization fails.- Angegeben von:
getNetworkInterfacesin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The local network interfaces on which multicast groups will be joined.
-
getBindAddresses
Beschreibung aus Schnittstelle kopiert:NetworkAddressFactoryThe caller mightremove()an address if initialization fails.- Angegeben von:
getBindAddressesin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The local addresses of the network interfaces bound to sockets listening for unicast datagrams and TCP requests.
-
hasUsableNetwork
public boolean hasUsableNetwork()- Angegeben von:
hasUsableNetworkin SchnittstelleNetworkAddressFactory- Gibt zurück:
trueif there is at least one usable network interface and bind address.
-
getHardwareAddress
- Angegeben von:
getHardwareAddressin SchnittstelleNetworkAddressFactory- Parameter:
inetAddress- An address of a local network interface.- Gibt zurück:
- The MAC hardware address of the network interface or
nullif no hardware address could be obtained.
-
getBroadcastAddress
- Angegeben von:
getBroadcastAddressin SchnittstelleNetworkAddressFactory- Parameter:
inetAddress- An address of a local network interface.- Gibt zurück:
- The broadcast address of the network (interface) or
nullif no broadcast address could be obtained.
-
getAddressNetworkPrefixLength
- Angegeben von:
getAddressNetworkPrefixLengthin SchnittstelleNetworkAddressFactory- Gibt zurück:
- The network prefix length of this address or
null.
-
getLocalAddress
public InetAddress getLocalAddress(NetworkInterface networkInterface, boolean isIPv6, InetAddress remoteAddress) Beschreibung aus Schnittstelle kopiert:NetworkAddressFactoryBest-effort attempt finding a reachable local address for a given remote host.This 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.
- Angegeben von:
getLocalAddressin SchnittstelleNetworkAddressFactory- Parameter:
networkInterface- 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.- Gibt zurück:
- A local address that is reachable from the given remote address.
-
getInterfaceAddresses
-
getInetAddresses
-
getBindAddressInSubnetOf
-
isInSubnet
protected boolean isInSubnet(byte[] ip, byte[] network, short prefix) -
discoverNetworkInterfaces
- Löst aus:
InitializationException
-
isUsableNetworkInterface
Validation of every discovered network interface.Override this method to customize which network interfaces are used.
The given implementation ignores interfaces which are
- loopback (yes, we do not bind to lo0)
- down
- have no bound IP addresses
- named "vmnet*" (OS X VMWare does not properly stop interfaces when it quits)
- named "vnic*" (OS X Parallels interfaces should be ignored as well)
- named "vboxnet*" (OS X Virtual Box interfaces should be ignored as well)
- named "*virtual*" (VirtualBox interfaces, for example
- named "ppp*"
- Parameter:
iface- The interface to validate.- Gibt zurück:
- True if the given interface matches all validation criteria.
- Löst aus:
Exception- If any validation test failed with an un-recoverable error.
-
discoverBindAddresses
- Löst aus:
InitializationException
-
isUsableAddress
Validation of every discovered local address.Override this method to customize which network addresses are used.
The given implementation ignores addresses which are
- not IPv4
- the local loopback (yes, we ignore 127.0.0.1)
- Parameter:
networkInterface- The interface to validate.address- The address of this interface to validate.- Gibt zurück:
- True if the given address matches all validation criteria.
-
logInterfaceInformation
- Löst aus:
SocketException
-