Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.teleal.cling.transport.impl
Class NetworkAddressFactoryImpl

    java.lang.Object
      org.teleal.cling.transport.impl.NetworkAddressFactoryImpl

All Implemented Interfaces:
  NetworkAddressFactory

    public class NetworkAddressFactoryImpl

extends Object
implements NetworkAddressFactory

Default implementation of network interface and address configuration/discovery.

Author:
  Christian Bauer

Field Summary
`protected List<InetAddress>` | `bindAddresses`
`static int` | `DEFAULT_TCP_HTTP_LISTEN_PORT`
`protected List<NetworkInterface>` | `networkInterfaces`
`protected int` | `streamListenPort`
`protected Set<String>` | `useAddresses`
`protected Set<String>` | `useInterfaces`

Fields inherited from interface org.teleal.cling.transport.spi.NetworkAddressFactory
`SYSTEM_PROPERTY_NET_ADDRESSES, SYSTEM_PROPERTY_NET_IFACES`

Constructor Summary
`NetworkAddressFactoryImpl()` Defaults to an ephemeral port.
`NetworkAddressFactoryImpl(int streamListenPort)`

Method Summary
`protected void` | `discoverBindAddresses()`
`protected void` | `discoverNetworkInterfaces()`
`InetAddress[]` | `getBindAddresses()`
`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()`
`NetworkInterface[]` | `getNetworkInterfaces()`
`int` | `getStreamListenPort()`
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_TCP_HTTP_LISTEN_PORT

    public static final int DEFAULT_TCP_HTTP_LISTEN_PORT

See Also:
  Constant Field Values

### useInterfaces

    protected Set<String> useInterfaces

### useAddresses

    protected Set<String> useAddresses

### networkInterfaces

    protected List<NetworkInterface> networkInterfaces

### bindAddresses

    protected List<InetAddress> bindAddresses

### streamListenPort

    protected int streamListenPort

Constructor Detail

### NetworkAddressFactoryImpl

    public NetworkAddressFactoryImpl()
                              throws InitializationException

  Defaults to an ephemeral port.

  Throws:
    `InitializationException`

### NetworkAddressFactoryImpl

    public NetworkAddressFactoryImpl(int streamListenPort)
                              throws InitializationException

Throws:
  `InitializationException`

Method Detail

### getMulticastGroup

    public InetAddress getMulticastGroup()

  Specified by:
    `getMulticastGroup` in interface `NetworkAddressFactory`
  Returns:
    The UDP multicast group to join.

### getMulticastPort

    public int getMulticastPort()

  Specified by:
    `getMulticastPort` in interface `NetworkAddressFactory`
  Returns:
    The UDP multicast port to listen on.

### getStreamListenPort

    public int getStreamListenPort()

  Specified by:
    `getStreamListenPort` in interface `NetworkAddressFactory`
  Returns:
    The TCP (HTTP) stream request port to listen on.

### getNetworkInterfaces

    public NetworkInterface[] getNetworkInterfaces()

  Specified by:
    `getNetworkInterfaces` in interface `NetworkAddressFactory`
  Returns:
    The local network interfaces on which multicast groups will be joined.

### getBindAddresses

    public InetAddress[] getBindAddresses()

  Specified by:
    `getBindAddresses` in interface `NetworkAddressFactory`
  Returns:
    The local addresses of the network interfaces bound to sockets listening for unicast datagrams and TCP requests.

### getHardwareAddress

    public byte[] getHardwareAddress(InetAddress inetAddress)

  Specified by:
    `getHardwareAddress` in interface `NetworkAddressFactory`
  Parameters:
    `inetAddress` - An address of a local network interface.
  Returns:
    The MAC hardware address of the network interface or `null` if no hardware address could be obtained.

### getBroadcastAddress

    public InetAddress getBroadcastAddress(InetAddress inetAddress)

  Specified by:
    `getBroadcastAddress` in interface `NetworkAddressFactory`
  Parameters:
    `inetAddress` - An address of a local network interface.
  Returns:
    The broadcast address of the network (interface) or `null` if no broadcast address could be obtained.

### getLocalAddress

    public InetAddress getLocalAddress(NetworkInterface networkInterface,
                                       boolean isIPv6,
                                       InetAddress remoteAddress)

  Description copied from interface: `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.

  Specified by:
    `getLocalAddress` in interface `NetworkAddressFactory`
  Parameters:
    `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.
  Returns:
    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

  Throws:
    `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 "ppp*"
  - not supporting multicast

  Parameters:
    `iface` - The interface to validate.
  Returns:
    True if the given interface matches all validation criteria.
  Throws:
    `Exception` - If any validation test failed with an un-recoverable error.

### discoverBindAddresses

    protected void discoverBindAddresses()
                                  throws InitializationException

  Throws:
    `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)

  Parameters:
    `networkInterface` - The interface to validate.
    `address` - The address of this interface to validate.
  Returns:
    True if the given address matches all validation criteria.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 Teleal GmbH, Switzerland. All Rights Reserved.