OpenNMS API 1.2.3

org.opennms.protocols.ip
Class IPv4Address

java.lang.Object
  extended byorg.opennms.protocols.ip.IPv4Address
All Implemented Interfaces:
java.io.Serializable

public class IPv4Address
extends java.lang.Object
implements java.io.Serializable

Represents an Internet Protocol version 4 address. An IPv4 address is a 32-bit address that can be considered four eight bit octets. Each octet represents a number in the range of [0..256). A string representation is a dotted decimal address in the form of "xxx.xxx.xxx.xxx" where xxx is a single octet. The main purpose of the class is to represent an IPv4 Address without the associated lookup baggage in the java.net.InetAddress class.

Author:
Brian Weaver <weave@oculan.com>
See Also:
Serialized Form

Field Summary
private  byte[] m_addr
           
(package private) static long serialVersionUID
           
 
Constructor Summary
IPv4Address()
          Constructs a new IPv4Address object.
IPv4Address(byte[] addr)
          Constructs a new object based on the value stored in the passed array.
IPv4Address(java.net.InetAddress addr)
          Creates a new IPv4Address from the passed InetAddress object.
IPv4Address(int ipv4Addr)
          Constructs a new address object based on the 32-bit passed value.
IPv4Address(IPv4Address second)
          Constructs a new address object based upon the value of the first object.
IPv4Address(java.lang.String ipv4Addr)
          Creates a new object by decomposing the passed string into it four components.
 
Method Summary
static java.lang.String addressToString(byte[] buf)
          Converts the passed IPv4 address buffer to a dotted decimal IP address string.
static java.lang.String addressToString(int ipv4Addr)
          Converts the passed 32-bit IPv4 address to a dotted decimal IP address string.
private static int byteToInt(byte b)
          Converts a byte to an integer, treating the byte as unsigned.
private  byte[] dup(byte[] src)
          Duplicates the array of bytes.
 boolean equals(java.lang.Object obj)
          Test to determine if the passed object is equal to self.
 int getAddress()
          Returns the 32-bit IPv4 address.
 byte[] getAddressBytes()
          Returns the IPv4 address in the form of an array of 4 bytes
 void setAddress(byte[] addr)
          Sets the object based on the value stored in the passed array.
 void setAddress(java.net.InetAddress addr)
          Sets the IPv4Address from the passed InetAddress object.
 void setAddress(int ipv4Addr)
          Sets the address object based on the 32-bit passed value.
 void setAddress(IPv4Address second)
          Sets the current address based upon the value of the passed object.
 void setAddress(java.lang.String ipv4Addr)
          Sets the object by decomposing the passed string into it four components.
 java.lang.String toString()
          Converts the object to a string and returns the string to the caller.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

m_addr

private byte[] m_addr
Constructor Detail

IPv4Address

public IPv4Address()
Constructs a new IPv4Address object. The default value for the object is "0.0.0.0"


IPv4Address

public IPv4Address(IPv4Address second)
Constructs a new address object based upon the value of the first object.

Parameters:
second - The object to copy the address from.

IPv4Address

public IPv4Address(byte[] addr)
Constructs a new object based on the value stored in the passed array. An IPv4 Address is 32-bits in length, thus the array must have exactly 4 elements.

Parameters:
addr - The IPv4Address data
Throws:
java.lang.IllegalArgumentException - Thrown if the passed buffer is not in the correct format for an IPv4Address.

IPv4Address

public IPv4Address(int ipv4Addr)
Constructs a new address object based on the 32-bit passed value. The 32-bit integer is split into four eight bit values that represent the IPv4 address.

Parameters:
ipv4Addr - The 32-bit IP address.

IPv4Address

public IPv4Address(java.lang.String ipv4Addr)
Creates a new object by decomposing the passed string into it four components. The string must be in the format of "xxx.xxx.xxx.xxx" where xxx is in the range of [0..256).

Parameters:
ipv4Addr - The dotted decimal address.
Throws:
java.lang.IllegalArgumentException - Thrown if the string is a malformed dotted decimal address.

IPv4Address

public IPv4Address(java.net.InetAddress addr)
Creates a new IPv4Address from the passed InetAddress object.

Parameters:
addr - The Internet Address containing the IPv4 address.
Method Detail

dup

private byte[] dup(byte[] src)
Duplicates the array of bytes.

Parameters:
src - The source bytes to duplicate.
Returns:
The duplicated array of bytes.

byteToInt

private static int byteToInt(byte b)
Converts a byte to an integer, treating the byte as unsigned.

Parameters:
b - The byte to convert.
Returns:
The converted value.

addressToString

public static java.lang.String addressToString(int ipv4Addr)
Converts the passed 32-bit IPv4 address to a dotted decimal IP address string.

Parameters:
ipv4Addr - The 32-bit address
Returns:
The dotted decimal address in the format "xxx.xxx.xxx.xxx" where 0 <= xxx < 256

addressToString

public static java.lang.String addressToString(byte[] buf)
Converts the passed IPv4 address buffer to a dotted decimal IP address string.

Parameters:
buf - The 4 byte buffer
Returns:
The dotted decimal address in the format "xxx.xxx.xxx.xxx" where 0 <= xxx < 256
Throws:
java.lang.IllegalArgumentException - Thrown if the buffer is not exactly 4 bytes in length.

getAddress

public int getAddress()
Returns the 32-bit IPv4 address.

Returns:
32-bit IPv4 address

getAddressBytes

public byte[] getAddressBytes()
Returns the IPv4 address in the form of an array of 4 bytes

Returns:
the IPv4 address bytes

setAddress

public void setAddress(IPv4Address second)
Sets the current address based upon the value of the passed object.

Parameters:
second - The new address.

setAddress

public void setAddress(byte[] addr)
Sets the object based on the value stored in the passed array. An IPv4 Address is 32-bits in length, thus the array must have exactly 4 elements.

Parameters:
addr - The IPv4Address data
Throws:
java.lang.IllegalArgumentException - Thrown if the passed buffer is not in the correct format for an IPv4Address.

setAddress

public void setAddress(int ipv4Addr)
Sets the address object based on the 32-bit passed value. The 32-bit integer is split into four eight bit values that represent the IPv4 address.

Parameters:
ipv4Addr - The 32-bit IP address.

setAddress

public void setAddress(java.lang.String ipv4Addr)
Sets the object by decomposing the passed string into it four components. The string must be in the format of "xxx.xxx.xxx.xxx" where xxx is in the range of [0..256).

Parameters:
ipv4Addr - The dotted decimal address.
Throws:
java.lang.IllegalArgumentException - Thrown if the string is a malformed dotted decimal address.

setAddress

public void setAddress(java.net.InetAddress addr)
Sets the IPv4Address from the passed InetAddress object.

Parameters:
addr - The Internet Address containing the IPv4 address.

equals

public boolean equals(java.lang.Object obj)
Test to determine if the passed object is equal to self. The object may be an Integer, String, or IPv4Address. If the object is a String then it must be in the dotted decimal string format.

Parameters:
obj - The object to use in the comparison.
Returns:
True if equal, false if not equal.

toString

public java.lang.String toString()
Converts the object to a string and returns the string to the caller.

Returns:
The dotted decimal string for the address

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.