Klasse NetworkAddressFactoryImpl

java.lang.Object
org.jupnp.transport.impl.NetworkAddressFactoryImpl
Alle implementierten Schnittstellen:
NetworkAddressFactory

public class NetworkAddressFactoryImpl extends Object implements NetworkAddressFactory
Default implementation of network interface and address configuration/discovery.

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
  • 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

      protected final Set<String> useInterfaces
    • useAddresses

      protected final Set<String> useAddresses
    • networkInterfaces

      protected final List<NetworkInterface> networkInterfaces
    • bindAddresses

      protected final List<InetAddress> bindAddresses
    • streamListenPort

      protected int streamListenPort
    • multicastResponsePort

      protected int multicastResponsePort
  • Konstruktordetails

  • Methodendetails

    • requiresNetworkInterface

      protected boolean requiresNetworkInterface()
      Gibt zurück:
      true (the default) if a MissingNetworkInterfaceException should be thrown
    • logInterfaceInformation

      public void logInterfaceInformation()
      Beschreibung aus Schnittstelle kopiert: NetworkAddressFactory
      For debugging, logs all "usable" network interface(s) details with INFO level.
      Angegeben von:
      logInterfaceInformation in Schnittstelle NetworkAddressFactory
    • getMulticastGroup

      public InetAddress getMulticastGroup()
      Angegeben von:
      getMulticastGroup in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      The UDP multicast group to join.
    • getMulticastPort

      public int getMulticastPort()
      Angegeben von:
      getMulticastPort in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      The UDP multicast port to listen on.
    • getMulticastResponsePort

      public int getMulticastResponsePort()
      Angegeben von:
      getMulticastResponsePort in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      The UDP port to listen on for search responses.
    • getStreamListenPort

      public int getStreamListenPort()
      Angegeben von:
      getStreamListenPort in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      The TCP (HTTP) stream request port to listen on.
    • getNetworkInterfaces

      public Iterator<NetworkInterface> getNetworkInterfaces()
      Beschreibung aus Schnittstelle kopiert: NetworkAddressFactory
      The caller might remove() an interface if initialization fails.
      Angegeben von:
      getNetworkInterfaces in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      The local network interfaces on which multicast groups will be joined.
    • getBindAddresses

      public Iterator<InetAddress> getBindAddresses()
      Beschreibung aus Schnittstelle kopiert: NetworkAddressFactory
      The caller might remove() an address if initialization fails.
      Angegeben von:
      getBindAddresses in Schnittstelle NetworkAddressFactory
      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:
      hasUsableNetwork in Schnittstelle NetworkAddressFactory
      Gibt zurück:
      true if there is at least one usable network interface and bind address.
    • getHardwareAddress

      public byte[] getHardwareAddress(InetAddress inetAddress)
      Angegeben von:
      getHardwareAddress in Schnittstelle NetworkAddressFactory
      Parameter:
      inetAddress - An address of a local network interface.
      Gibt zurück:
      The MAC hardware address of the network interface or null if no hardware address could be obtained.
    • getBroadcastAddress

      public InetAddress getBroadcastAddress(InetAddress inetAddress)
      Angegeben von:
      getBroadcastAddress in Schnittstelle NetworkAddressFactory
      Parameter:
      inetAddress - An address of a local network interface.
      Gibt zurück:
      The broadcast address of the network (interface) or null if no broadcast address could be obtained.
    • getAddressNetworkPrefixLength

      public Short getAddressNetworkPrefixLength(InetAddress inetAddress)
      Angegeben von:
      getAddressNetworkPrefixLength in Schnittstelle NetworkAddressFactory
      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: NetworkAddressFactory
      Best-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:
      getLocalAddress in Schnittstelle NetworkAddressFactory
      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

      protected List<InterfaceAddress> getInterfaceAddresses(NetworkInterface networkInterface)
    • getInetAddresses

      protected List<InetAddress> getInetAddresses(NetworkInterface networkInterface)
    • getBindAddressInSubnetOf

      protected InetAddress getBindAddressInSubnetOf(InetAddress inetAddress)
    • isInSubnet

      protected boolean isInSubnet(byte[] ip, byte[] network, short prefix)
    • discoverNetworkInterfaces

      protected void discoverNetworkInterfaces() throws InitializationException
      Löst aus:
      InitializationException
    • isUsableNetworkInterface

      protected boolean isUsableNetworkInterface(NetworkInterface iface) throws Exception
      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

      protected void discoverBindAddresses() throws InitializationException
      Löst aus:
      InitializationException
    • isUsableAddress

      protected boolean isUsableAddress(NetworkInterface networkInterface, InetAddress address)
      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

      protected void logInterfaceInformation(NetworkInterface networkInterface) throws SocketException
      Löst aus:
      SocketException