tuwien.auto.eicl.struct.eibnetip.util

Class HPAI


public class HPAI
extends java.lang.Object

This class is the implementation of the EIBnet/IP Host Protocol Address Information (HPAI) structure. HPAI is used to describe a server/client end point. Its structure varies according to the used underlying protocol. This class is implemented for IPv4.

Constructor Summary

HPAI(byte[] _Data)
Creates an HPAI instance from its byte array representation.
HPAI(int _PortNumber)
Creates a new HPAI object for the local host.

Method Summary

byte[]
getAddress()
Returns the IP network address in byte format (big endian).
String
getAddressString()
Offers the IP network address in dot notation as string.
String
getDescription()
Offers a human readable host description consisting of IP address and port
static InetAddress
getLocalIP()
Allows to retrieve the IP address that is used for the local host.
int
getPort()
Returns the port as integer
InetSocketAddress
getSocketAddress()
Returns the IP address and port number as an InetSocketAddress object.
short
getStructLength()
Retrieves the structure size.
static void
setLocalIP(InetAddress ia)
Allows to set the IP address to be used for the local host.
byte[]
toByteArray()
Converts the HPAI to its byte array representation.

Constructor Details

HPAI

public HPAI(byte[] _Data)
            throws EICLException
Creates an HPAI instance from its byte array representation.
Parameters:
_Data - The HPAI as byte array.
Throws:
EICLException - If the host protocol in the parsed structure is another than IPv4.

HPAI

public HPAI(int _PortNumber)
            throws EICLException
Creates a new HPAI object for the local host. The IP address is determined automatically. Since there does not seem to be a way to access routing information in a portable manner, the automatic detection fails when more than one network interface is installed on the local host. In this case, one of them is chosen at random. The result of the autodetection process can be retrieved at any time via getLocalIP() and can be overridden using the setLocalIP(InetAddress) method.
Parameters:
_PortNumber - the local port to be used in the HPAI
Throws:
EICLException -

Method Details

getAddress

public byte[] getAddress()
Returns the IP network address in byte format (big endian).
Returns:
the IP address

getAddressString

public String getAddressString()
Offers the IP network address in dot notation as string.
Returns:
The IPv4 addresss as string

getDescription

public String getDescription()
Offers a human readable host description consisting of IP address and port
Returns:
A human readable host description.

getLocalIP

public static InetAddress getLocalIP()
Allows to retrieve the IP address that is used for the local host.
Returns:
The IP address used by the HPAI(int) constructor.

getPort

public int getPort()
Returns the port as integer
Returns:
The port contained in HPAI

getSocketAddress

public InetSocketAddress getSocketAddress()
Returns the IP address and port number as an InetSocketAddress object.
Returns:
The hostdescription as InetSocketaAddress

getStructLength

public short getStructLength()
Retrieves the structure size.
Returns:
the structure length

setLocalIP

public static void setLocalIP(InetAddress ia)
Allows to set the IP address to be used for the local host. This is only necessary when the address is not correctly detected automatically.
Parameters:
ia - The IP address to be used by the HPAI(int) constructor.

toByteArray

public byte[] toByteArray()
            throws EICLException
Converts the HPAI to its byte array representation.
Returns:
the byte array representation of the HPAI
Throws:
EICLException - if the conversion fails