com.adventnet.snmp.snmp2
Class SnmpIpAddress

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.SnmpVar
        |
        +--com.adventnet.snmp.snmp2.SnmpString
              |
              +--com.adventnet.snmp.snmp2.SnmpIpAddress
Direct Known Subclasses:
SnmpNetworkAddress

public class SnmpIpAddress
extends SnmpString

Class of SNMP IpAddress Variable - Sub-class of SnmpVar. This class can be used to created a SnmpVar object of type SnmpIpAddress. It also has methods to retrieve the value in different forms(eg. String, byte). Value is stored as String of length 4 with each lower byte corresponding to the raw IP address.

See Also:
Serialized Form

Field Summary
(package private)  java.lang.String ipAddr
           
 
Fields inherited from class com.adventnet.snmp.snmp2.SnmpString
byteValue, enc, s_emptyString, value
 
Fields inherited from class com.adventnet.snmp.snmp2.SnmpVar
Type, varbindErrorVal
 
Constructor Summary
(package private) SnmpIpAddress()
          Empty constructor
  SnmpIpAddress(byte[] b)
          Constructs a new SnmpIpAddress by accepting the raw IP address - 4 bytes.
  SnmpIpAddress(java.lang.String s)
          Constructs a new SnmpIpAddress with the specified host name or IP address as a string.
 
Method Summary
(package private)  int encode(byte[] buff, int space)
          ASN encoder
 java.lang.String getNumericValueAsString()
          This method will throw UnsupportedOperationException since this is not a numeric data type.
 java.lang.Object getVarObject()
          Returns the values of this SnmpIpAddress as a printable String object.
static java.lang.String netbToString(byte[] rawIpAddr)
          A converter from raw IP address (byte[]) to string.
(package private) static SnmpVar newInstance(byte[] b)
          Factory method for decode
 java.lang.String toHostName()
          To convert the object to a host name.
 java.lang.String toString()
          To convert the value of this SnmpIpAddress object to a printable string.
 java.lang.String toTagString()
          To convert the value of this SnmpIpAddress object to a printable string where the type is tagged before the value with a tag IpAddress:.
 java.lang.Object toValue()
          Returns the value of this SnmpIpAddress as a String object.
 
Methods inherited from class com.adventnet.snmp.snmp2.SnmpString
equals, toBytes, toByteString
 
Methods inherited from class com.adventnet.snmp.snmp2.SnmpVar
createVariable, getError, getType, getTypeString
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ipAddr

java.lang.String ipAddr
Constructor Detail

SnmpIpAddress

SnmpIpAddress()
Empty constructor

SnmpIpAddress

public SnmpIpAddress(java.lang.String s)
Constructs a new SnmpIpAddress with the specified host name or IP address as a string. This does not throw any exceptions. To ensure that a valid IpAddress is created, always try to use a dotted format ip address. Supplying host name to this constructor could result in delays caused by DNS lookups and in case a failure occurs then the toValue will return a null. If a 'null' parameter is passed as an argument to this constructor, then the object will be initialized with the IP-address "0.0.0.0".
Parameters:
s - host name or IP address as a string.

SnmpIpAddress

public SnmpIpAddress(byte[] b)
Constructs a new SnmpIpAddress by accepting the raw IP address - 4 bytes.
Parameters:
b - raw IP address - 4 bytes
Method Detail

newInstance

static SnmpVar newInstance(byte[] b)
Factory method for decode
Tags copied from class: SnmpString
Parameters:
b - The bytearray return The snmp variable

getVarObject

public java.lang.Object getVarObject()
Returns the values of this SnmpIpAddress as a printable String object. This method is the same as toString() Eg. Returns the IPAddress as x.x.x.x . Same as toString()
Overrides:
getVarObject in class SnmpString
Returns:
the value of the SnmpIpAddress as a printable string Object or 'null' in case of invalid IPAddress.

toValue

public java.lang.Object toValue()
Returns the value of this SnmpIpAddress as a String object. This does not return the string corresponding to the IPAddress ( that is returned by the toString method), but instead returns a 4-char String representing the four bytes comprising an IPAddress.
Overrides:
toValue in class SnmpString
Returns:
String Object Null if IPAddress is invalid. This happens only if object has been initialised with a wrong host name. This does not return the string corresponding to the IPAddress ( that is returned by the toString method), but instead returns a 4-char String representing the four bytes comprising an ipaddress.
See Also:
SnmpString.toValue(), SnmpIpAddress()

toString

public java.lang.String toString()
To convert the value of this SnmpIpAddress object to a printable string. This returns the dotted ipaddress string always.
Overrides:
toString in class SnmpString
Returns:
the value of this SnmpIpAddress as a printable string Object, or 'null' in case of invalid IPAddress.

toTagString

public java.lang.String toTagString()
To convert the value of this SnmpIpAddress object to a printable string where the type is tagged before the value with a tag IpAddress:. For e.g if the SnmpIpAddress has the value 127.0.0.1, then this method will return - IpAddress: 127.0.0.1 .
Overrides:
toTagString in class SnmpString
Returns:
the value of this SnmpIpAddress object as a printable string where the type is tagged before the value with a tag - IpAddress: .

toHostName

public java.lang.String toHostName()
To convert the object to a host name. In case of UnknownHostName or SecurityException, this will return the dotted ip address.
Returns:
Host name

encode

int encode(byte[] buff,
           int space)
     throws java.lang.ArrayIndexOutOfBoundsException
ASN encoder
Overrides:
encode in class SnmpString
Parameters:
buff - The buffer into which the value is to be encoded
space - The number of free bytes in the buffer
Returns:
The number of free bytes in the buffer
Throws:
java.lang.ArrayIndexOutOfBoundsException - When there is insufficient space in buffer

netbToString

public static java.lang.String netbToString(byte[] rawIpAddr)
A converter from raw IP address (byte[]) to string. This takes the IP address as a byte[] and returns as a string in the form x.x.x.x .
Parameters:
rawIpAddr - The IP Address as a byte[].
Returns:
The value of the IPAddress as a string in the form x.x.x.x .

getNumericValueAsString

public java.lang.String getNumericValueAsString()
This method will throw UnsupportedOperationException since this is not a numeric data type.
Overrides:
getNumericValueAsString in class SnmpString
Returns:
Nothing is returned since this method throws an exception.
Throws:
java.lang.UnsupportedOperationException - Since this is not a numeric data type.