org.dhcp4java
Class DHCPOption

java.lang.Object
  extended by org.dhcp4java.DHCPOption
All Implemented Interfaces:
java.io.Serializable

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

Class for manipulating DHCP options (used internally).

Version:
0.99 Immutable object.
Author:
Stephan Hadinger
See Also:
Serialized Form

Constructor Summary
DHCPOption(byte code, byte[] value)
          Constructor for DHCPOption.
DHCPOption(byte code, byte[] value, boolean mirror)
          Constructor for DHCPOption.
 
Method Summary
static java.util.Map<java.lang.Byte,java.lang.String> agentOptionsToMap(byte[] buf)
          Converts DHO_DHCP_AGENT_OPTIONS (82) option type to a LinkedMap.
static java.lang.String agentOptionsToString(byte[] buf)
          Converts DHO_DHCP_AGENT_OPTIONS (82) option type to a printable string
static byte[] agentOptionToRaw(java.util.Map<java.lang.Byte,java.lang.String> map)
          Converts Map to DHO_DHCP_AGENT_OPTIONS (82) option.
 void append(java.lang.StringBuilder buffer)
          Appends to this string builder a detailed string representation of the DHCP datagram.
 DHCPOption applyOption(DHCPPacket request)
          Get the option value based on the context, i.e. the client's request.
static byte[] byte2Bytes(byte val)
          Type converters.
 boolean equals(java.lang.Object o)
          returns true if two DHCPOption objects are equal, i.e. have same code and same value.
 byte getCode()
          Return the code field (byte).
static java.lang.Class getOptionFormat(byte code)
          Returns the type of the option based on the option code.
 byte[] getValue()
           
 byte getValueAsByte()
          Returns a DHCP Option as Byte format.
 byte[] getValueAsBytes()
          Returns a DHCP Option as Byte array format.
 java.net.InetAddress getValueAsInetAddr()
          Returns a DHCP Option as InetAddress format.
 java.net.InetAddress[] getValueAsInetAddrs()
          Returns a DHCP Option as InetAddress array format.
 int getValueAsInt()
          Returns a DHCP Option as Integer format.
 java.lang.Integer getValueAsNum()
          Returns a DHCP Option as Integer format, but is usable for any numerical type: int, short or byte.
 short getValueAsShort()
          Returns a DHCP Option as Short format.
 short[] getValueAsShorts()
          Returns a DHCP Option as Short array format.
 java.lang.String getValueAsString()
          Returns a DHCP Option as String format.
 byte[] getValueFast()
           
 int hashCode()
          Returns hashcode.
static byte[] inetAddress2Bytes(java.net.InetAddress val)
           
static byte[] inetAddresses2Bytes(java.net.InetAddress[] val)
           
static byte[] int2Bytes(int val)
           
 boolean isMirror()
          Returns whether the option is marked as "mirror", meaning it should mirror the option value in the client request.
static boolean isOptionAsByte(byte code)
           
static boolean isOptionAsBytes(byte code)
           
static boolean isOptionAsInetAddr(byte code)
           
static boolean isOptionAsInetAddrs(byte code)
           
static boolean isOptionAsInt(byte code)
           
static boolean isOptionAsShort(byte code)
           
static boolean isOptionAsShorts(byte code)
           
static boolean isOptionAsString(byte code)
           
static void main(java.lang.String[] args)
           
static DHCPOption newOptionAsByte(byte code, byte val)
          Creates a DHCP Option as Byte format.
static DHCPOption newOptionAsInetAddress(byte code, java.net.InetAddress val)
          Sets a DHCP Option as InetAddress format.
static DHCPOption newOptionAsInetAddresses(byte code, java.net.InetAddress[] val)
          Creates a DHCP Option as InetAddress array format.
static DHCPOption newOptionAsInt(byte code, int val)
          Creates a DHCP Option as Integer format.
static DHCPOption newOptionAsShort(byte code, short val)
          Creates a DHCP Option as Short format.
static DHCPOption newOptionAsShorts(byte code, short[] arr)
          Creates a DHCP Options as Short[] format.
static DHCPOption newOptionAsString(byte code, java.lang.String val)
          Creates a DHCP Option as String format.
static DHCPOption parseNewOption(byte code, java.lang.Class format, java.lang.String value)
          Parse an option from a pure string representation.
static byte[] short2Bytes(short val)
           
static java.lang.Class string2Class(java.lang.String className)
          Simple method for converting from string to supported class format.
static byte[] stringListToUserClass(java.util.List<java.lang.String> list)
          Converts this list of strings to a DHO_USER_CLASS (77) option.
 java.lang.String toString()
          Returns a detailed string representation of the DHCP datagram.
static java.util.List<java.lang.String> userClassToList(byte[] buf)
          Convert DHO_USER_CLASS (77) option to a List.
static java.lang.String userClassToString(byte[] buf)
          Converts DHO_USER_CLASS (77) option to a printable string
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DHCPOption

public DHCPOption(byte code,
                  byte[] value,
                  boolean mirror)
Constructor for DHCPOption.

Note: you must not prefix the value by a length-byte. The length prefix will be added automatically by the API.

If value is null it is considered as an empty option. If you add an empty option to a DHCPPacket, it removes the option from the packet.

This constructor adds a parameter to mark the option as "mirror". See comments above.

Parameters:
code - DHCP option code
value - DHCP option value as a byte array.

DHCPOption

public DHCPOption(byte code,
                  byte[] value)
Constructor for DHCPOption. This is the default constructor.

Note: you must not prefix the value by a length-byte. The length prefix will be added automatically by the API.

If value is null it is considered as an empty option. If you add an empty option to a DHCPPacket, it removes the option from the packet.

Parameters:
code - DHCP option code
value - DHCP option value as a byte array.
Method Detail

getCode

public byte getCode()
Return the code field (byte).

Returns:
code field

equals

public boolean equals(java.lang.Object o)
returns true if two DHCPOption objects are equal, i.e. have same code and same value.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns hashcode.

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

getValue

public byte[] getValue()
Returns:
option value, can be null.

getValueFast

public byte[] getValueFast()
Returns:
option value, never null. Minimal value is byte[0].

isMirror

public boolean isMirror()
Returns whether the option is marked as "mirror", meaning it should mirror the option value in the client request.

To be used only in servers.

Returns:
is the option marked is mirror?

isOptionAsByte

public static final boolean isOptionAsByte(byte code)

newOptionAsByte

public static DHCPOption newOptionAsByte(byte code,
                                         byte val)
Creates a DHCP Option as Byte format.

This method is only allowed for the following option codes:

 DHO_IP_FORWARDING(19)
 DHO_NON_LOCAL_SOURCE_ROUTING(20)
 DHO_DEFAULT_IP_TTL(23)
 DHO_ALL_SUBNETS_LOCAL(27)
 DHO_PERFORM_MASK_DISCOVERY(29)
 DHO_MASK_SUPPLIER(30)
 DHO_ROUTER_DISCOVERY(31)
 DHO_TRAILER_ENCAPSULATION(34)
 DHO_IEEE802_3_ENCAPSULATION(36)
 DHO_DEFAULT_TCP_TTL(37)
 DHO_TCP_KEEPALIVE_GARBAGE(39)
 DHO_NETBIOS_NODE_TYPE(46)
 DHO_DHCP_OPTION_OVERLOAD(52)
 DHO_DHCP_MESSAGE_TYPE(53)
 DHO_AUTO_CONFIGURE(116)
 

Parameters:
code - the option code.
val - the value
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

getValueAsByte

public byte getValueAsByte()
                    throws java.lang.IllegalArgumentException
Returns a DHCP Option as Byte format. This method is only allowed for the following option codes:
 DHO_IP_FORWARDING(19)
 DHO_NON_LOCAL_SOURCE_ROUTING(20)
 DHO_DEFAULT_IP_TTL(23)
 DHO_ALL_SUBNETS_LOCAL(27)
 DHO_PERFORM_MASK_DISCOVERY(29)
 DHO_MASK_SUPPLIER(30)
 DHO_ROUTER_DISCOVERY(31)
 DHO_TRAILER_ENCAPSULATION(34)
 DHO_IEEE802_3_ENCAPSULATION(36)
 DHO_DEFAULT_TCP_TTL(37)
 DHO_TCP_KEEPALIVE_GARBAGE(39)
 DHO_NETBIOS_NODE_TYPE(46)
 DHO_DHCP_OPTION_OVERLOAD(52)
 DHO_DHCP_MESSAGE_TYPE(53)
 DHO_AUTO_CONFIGURE(116)
 

Returns:
the option value, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

isOptionAsShort

public static final boolean isOptionAsShort(byte code)

getValueAsShort

public short getValueAsShort()
                      throws java.lang.IllegalArgumentException
Returns a DHCP Option as Short format.

This method is only allowed for the following option codes:

 DHO_BOOT_SIZE(13)
 DHO_MAX_DGRAM_REASSEMBLY(22)
 DHO_INTERFACE_MTU(26)
 DHO_DHCP_MAX_MESSAGE_SIZE(57)
 

Returns:
the option value, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

isOptionAsInt

public static final boolean isOptionAsInt(byte code)

getValueAsInt

public int getValueAsInt()
                  throws java.lang.IllegalArgumentException
Returns a DHCP Option as Integer format.

This method is only allowed for the following option codes:

 DHO_TIME_OFFSET(2)
 DHO_PATH_MTU_AGING_TIMEOUT(24)
 DHO_ARP_CACHE_TIMEOUT(35)
 DHO_TCP_KEEPALIVE_INTERVAL(38)
 DHO_DHCP_LEASE_TIME(51)
 DHO_DHCP_RENEWAL_TIME(58)
 DHO_DHCP_REBINDING_TIME(59)
 

Returns:
the option value, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

getValueAsNum

public java.lang.Integer getValueAsNum()
                                throws java.lang.IllegalArgumentException
Returns a DHCP Option as Integer format, but is usable for any numerical type: int, short or byte.

There is no check on the option

Returns:
the option value null if option is not present, or wrong number of bytes.
Throws:
java.lang.IllegalArgumentException

isOptionAsInetAddr

public static final boolean isOptionAsInetAddr(byte code)

getValueAsInetAddr

public java.net.InetAddress getValueAsInetAddr()
                                        throws java.lang.IllegalArgumentException
Returns a DHCP Option as InetAddress format.

This method is only allowed for the following option codes:

 DHO_SUBNET_MASK(1)
 DHO_SWAP_SERVER(16)
 DHO_BROADCAST_ADDRESS(28)
 DHO_ROUTER_SOLICITATION_ADDRESS(32)
 DHO_DHCP_REQUESTED_ADDRESS(50)
 DHO_DHCP_SERVER_IDENTIFIER(54)
 DHO_SUBNET_SELECTION(118)
 

Returns:
the option value, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

isOptionAsString

public static final boolean isOptionAsString(byte code)

getValueAsString

public java.lang.String getValueAsString()
                                  throws java.lang.IllegalArgumentException
Returns a DHCP Option as String format.

This method is only allowed for the following option codes:

 DHO_HOST_NAME(12)
 DHO_MERIT_DUMP(14)
 DHO_DOMAIN_NAME(15)
 DHO_ROOT_PATH(17)
 DHO_EXTENSIONS_PATH(18)
 DHO_NETBIOS_SCOPE(47)
 DHO_DHCP_MESSAGE(56)
 DHO_VENDOR_CLASS_IDENTIFIER(60)
 DHO_NWIP_DOMAIN_NAME(62)
 DHO_NIS_DOMAIN(64)
 DHO_NIS_SERVER(65)
 DHO_TFTP_SERVER(66)
 DHO_BOOTFILE(67)
 DHO_NDS_TREE_NAME(86)
 DHO_USER_AUTHENTICATION_PROTOCOL(98)
 

Returns:
the option value, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

isOptionAsShorts

public static final boolean isOptionAsShorts(byte code)

getValueAsShorts

public short[] getValueAsShorts()
                         throws java.lang.IllegalArgumentException
Returns a DHCP Option as Short array format.

This method is only allowed for the following option codes:

 DHO_PATH_MTU_PLATEAU_TABLE(25)
 DHO_NAME_SERVICE_SEARCH(117)
 

Returns:
the option value array, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

isOptionAsInetAddrs

public static final boolean isOptionAsInetAddrs(byte code)

getValueAsInetAddrs

public java.net.InetAddress[] getValueAsInetAddrs()
                                           throws java.lang.IllegalArgumentException
Returns a DHCP Option as InetAddress array format.

This method is only allowed for the following option codes:

 DHO_ROUTERS(3)
 DHO_TIME_SERVERS(4)
 DHO_NAME_SERVERS(5)
 DHO_DOMAIN_NAME_SERVERS(6)
 DHO_LOG_SERVERS(7)
 DHO_COOKIE_SERVERS(8)
 DHO_LPR_SERVERS(9)
 DHO_IMPRESS_SERVERS(10)
 DHO_RESOURCE_LOCATION_SERVERS(11)
 DHO_POLICY_FILTER(21)
 DHO_STATIC_ROUTES(33)
 DHO_NIS_SERVERS(41)
 DHO_NTP_SERVERS(42)
 DHO_NETBIOS_NAME_SERVERS(44)
 DHO_NETBIOS_DD_SERVER(45)
 DHO_FONT_SERVERS(48)
 DHO_X_DISPLAY_MANAGER(49)
 DHO_MOBILE_IP_HOME_AGENT(68)
 DHO_SMTP_SERVER(69)
 DHO_POP3_SERVER(70)
 DHO_NNTP_SERVER(71)
 DHO_WWW_SERVER(72)
 DHO_FINGER_SERVER(73)
 DHO_IRC_SERVER(74)
 DHO_STREETTALK_SERVER(75)
 DHO_STDA_SERVER(76)
 DHO_NDS_SERVERS(85)
 

Returns:
the option value array, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.
DHCPBadPacketException - the option value in packet is of wrong size.

isOptionAsBytes

public static final boolean isOptionAsBytes(byte code)

getValueAsBytes

public byte[] getValueAsBytes()
                       throws java.lang.IllegalArgumentException
Returns a DHCP Option as Byte array format.

This method is only allowed for the following option codes:

 DHO_DHCP_PARAMETER_REQUEST_LIST(55)
 

Note: this mehtod is similar to getOptionRaw, only with option type checking.

Returns:
the option value array, null if option is not present.
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsShort

public static DHCPOption newOptionAsShort(byte code,
                                          short val)
Creates a DHCP Option as Short format.

This method is only allowed for the following option codes:

 DHO_BOOT_SIZE(13)
 DHO_MAX_DGRAM_REASSEMBLY(22)
 DHO_INTERFACE_MTU(26)
 DHO_DHCP_MAX_MESSAGE_SIZE(57)
 

Parameters:
code - the option code.
val - the value
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsShorts

public static DHCPOption newOptionAsShorts(byte code,
                                           short[] arr)
Creates a DHCP Options as Short[] format.

This method is only allowed for the following option codes:

 DHO_PATH_MTU_PLATEAU_TABLE(25)
 DHO_NAME_SERVICE_SEARCH(117)
 

Parameters:
code - the option code.
arr - the array of shorts
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsInt

public static DHCPOption newOptionAsInt(byte code,
                                        int val)
Creates a DHCP Option as Integer format.

This method is only allowed for the following option codes:

 DHO_TIME_OFFSET(2)
 DHO_PATH_MTU_AGING_TIMEOUT(24)
 DHO_ARP_CACHE_TIMEOUT(35)
 DHO_TCP_KEEPALIVE_INTERVAL(38)
 DHO_DHCP_LEASE_TIME(51)
 DHO_DHCP_RENEWAL_TIME(58)
 DHO_DHCP_REBINDING_TIME(59)
 

Parameters:
code - the option code.
val - the value
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsInetAddress

public static DHCPOption newOptionAsInetAddress(byte code,
                                                java.net.InetAddress val)
Sets a DHCP Option as InetAddress format.

This method is only allowed for the following option codes:

 DHO_SUBNET_MASK(1)
 DHO_SWAP_SERVER(16)
 DHO_BROADCAST_ADDRESS(28)
 DHO_ROUTER_SOLICITATION_ADDRESS(32)
 DHO_DHCP_REQUESTED_ADDRESS(50)
 DHO_DHCP_SERVER_IDENTIFIER(54)
 DHO_SUBNET_SELECTION(118)
 
and also as a simplified version for setOptionAsInetAddresses
 DHO_ROUTERS(3)
 DHO_TIME_SERVERS(4)
 DHO_NAME_SERVERS(5)
 DHO_DOMAIN_NAME_SERVERS(6)
 DHO_LOG_SERVERS(7)
 DHO_COOKIE_SERVERS(8)
 DHO_LPR_SERVERS(9)
 DHO_IMPRESS_SERVERS(10)
 DHO_RESOURCE_LOCATION_SERVERS(11)
 DHO_POLICY_FILTER(21)
 DHO_STATIC_ROUTES(33)
 DHO_NIS_SERVERS(41)
 DHO_NTP_SERVERS(42)
 DHO_NETBIOS_NAME_SERVERS(44)
 DHO_NETBIOS_DD_SERVER(45)
 DHO_FONT_SERVERS(48)
 DHO_X_DISPLAY_MANAGER(49)
 DHO_MOBILE_IP_HOME_AGENT(68)
 DHO_SMTP_SERVER(69)
 DHO_POP3_SERVER(70)
 DHO_NNTP_SERVER(71)
 DHO_WWW_SERVER(72)
 DHO_FINGER_SERVER(73)
 DHO_IRC_SERVER(74)
 DHO_STREETTALK_SERVER(75)
 DHO_STDA_SERVER(76)
 DHO_NDS_SERVERS(85)
 

Parameters:
code - the option code.
val - the value
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsInetAddresses

public static DHCPOption newOptionAsInetAddresses(byte code,
                                                  java.net.InetAddress[] val)
Creates a DHCP Option as InetAddress array format.

This method is only allowed for the following option codes:

 DHO_ROUTERS(3)
 DHO_TIME_SERVERS(4)
 DHO_NAME_SERVERS(5)
 DHO_DOMAIN_NAME_SERVERS(6)
 DHO_LOG_SERVERS(7)
 DHO_COOKIE_SERVERS(8)
 DHO_LPR_SERVERS(9)
 DHO_IMPRESS_SERVERS(10)
 DHO_RESOURCE_LOCATION_SERVERS(11)
 DHO_POLICY_FILTER(21)
 DHO_STATIC_ROUTES(33)
 DHO_NIS_SERVERS(41)
 DHO_NTP_SERVERS(42)
 DHO_NETBIOS_NAME_SERVERS(44)
 DHO_NETBIOS_DD_SERVER(45)
 DHO_FONT_SERVERS(48)
 DHO_X_DISPLAY_MANAGER(49)
 DHO_MOBILE_IP_HOME_AGENT(68)
 DHO_SMTP_SERVER(69)
 DHO_POP3_SERVER(70)
 DHO_NNTP_SERVER(71)
 DHO_WWW_SERVER(72)
 DHO_FINGER_SERVER(73)
 DHO_IRC_SERVER(74)
 DHO_STREETTALK_SERVER(75)
 DHO_STDA_SERVER(76)
 DHO_NDS_SERVERS(85)
 

Parameters:
code - the option code.
val - the value array
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

newOptionAsString

public static DHCPOption newOptionAsString(byte code,
                                           java.lang.String val)
Creates a DHCP Option as String format.

This method is only allowed for the following option codes:

 DHO_HOST_NAME(12)
 DHO_MERIT_DUMP(14)
 DHO_DOMAIN_NAME(15)
 DHO_ROOT_PATH(17)
 DHO_EXTENSIONS_PATH(18)
 DHO_NETBIOS_SCOPE(47)
 DHO_DHCP_MESSAGE(56)
 DHO_VENDOR_CLASS_IDENTIFIER(60)
 DHO_NWIP_DOMAIN_NAME(62)
 DHO_NIS_DOMAIN(64)
 DHO_NIS_SERVER(65)
 DHO_TFTP_SERVER(66)
 DHO_BOOTFILE(67)
 DHO_NDS_TREE_NAME(86)
 DHO_USER_AUTHENTICATION_PROTOCOL(98)
 

Parameters:
code - the option code.
val - the value
Throws:
java.lang.IllegalArgumentException - the option code is not in the list above.

applyOption

public DHCPOption applyOption(DHCPPacket request)
Get the option value based on the context, i.e. the client's request.

This should be the only method used with this class to get relevant values.

Parameters:
request - the client's DHCP requets
Returns:
the value of the specific option in the client request
Throws:
java.lang.NullPointerException - if request is null.

append

public void append(java.lang.StringBuilder buffer)
Appends to this string builder a detailed string representation of the DHCP datagram.

This multi-line string details: the static, options and padding parts of the object. This is useful for debugging, but not efficient.

Parameters:
buffer - the string builder the string representation of this object should be appended.

toString

public java.lang.String toString()
Returns a detailed string representation of the DHCP datagram.

This multi-line string details: the static, options and padding parts of the object. This is useful for debugging, but not efficient.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

byte2Bytes

public static byte[] byte2Bytes(byte val)
Type converters.


short2Bytes

public static byte[] short2Bytes(short val)

int2Bytes

public static byte[] int2Bytes(int val)

inetAddress2Bytes

public static byte[] inetAddress2Bytes(java.net.InetAddress val)

inetAddresses2Bytes

public static byte[] inetAddresses2Bytes(java.net.InetAddress[] val)

userClassToList

public static java.util.List<java.lang.String> userClassToList(byte[] buf)
Convert DHO_USER_CLASS (77) option to a List.

Parameters:
buf - option value of type User Class.
Returns:
List of String values.

userClassToString

public static java.lang.String userClassToString(byte[] buf)
Converts DHO_USER_CLASS (77) option to a printable string

Parameters:
buf - option value of type User Class.
Returns:
printable string.

stringListToUserClass

public static byte[] stringListToUserClass(java.util.List<java.lang.String> list)
Converts this list of strings to a DHO_USER_CLASS (77) option.

Parameters:
list - the list of strings
Returns:
byte[] buffer to use with setOptionRaw, null if list is null
Throws:
java.lang.IllegalArgumentException - if List contains anything else than String

agentOptionsToString

public static java.lang.String agentOptionsToString(byte[] buf)
Converts DHO_DHCP_AGENT_OPTIONS (82) option type to a printable string

Parameters:
buf - option value of type Agent Option.
Returns:
printable string.

agentOptionToRaw

public static byte[] agentOptionToRaw(java.util.Map<java.lang.Byte,java.lang.String> map)
Converts Map to DHO_DHCP_AGENT_OPTIONS (82) option.

LinkedHashMap are preferred as they preserve insertion order. Regular HashMap order is randon.

Parameters:
map - Map couples
Returns:
byte[] buffer to use with setOptionRaw
Throws:
java.lang.IllegalArgumentException - if List contains anything else than String

agentOptionsToMap

public static final java.util.Map<java.lang.Byte,java.lang.String> agentOptionsToMap(byte[] buf)
Converts DHO_DHCP_AGENT_OPTIONS (82) option type to a LinkedMap.

Order of parameters is preserved (use avc LinkedHashmapByte, values are of type String.

Parameters:
buf - byte[] buffer returned by getOptionRaw
Returns:
the LinkedHashmap of values, null if buf is null

getOptionFormat

public static java.lang.Class getOptionFormat(byte code)
Returns the type of the option based on the option code.

The type is returned as a Class object:

Please use getSimpleName() methode of Class object for the String representation.

Parameters:
code - the DHCP option code
Returns:
the Class object representing accepted types

string2Class

public static java.lang.Class string2Class(java.lang.String className)
Simple method for converting from string to supported class format.

Support values are:

Parameters:
className - name of the data format (see above)
Returns:
Class or null if not supported

parseNewOption

public static DHCPOption parseNewOption(byte code,
                                        java.lang.Class format,
                                        java.lang.String value)
Parse an option from a pure string representation.

The expected class is passed as a parameter, and can be provided by the string2Class() method from a string representation of the class.

TODO examples

Parameters:
code - DHCP option code
format - expected Java Class after conversion
value - string representation of the value
Returns:
the DHCPOption object

main

public static void main(java.lang.String[] args)