|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dhcp4java.DHCPOption
public class DHCPOption
Class for manipulating DHCP options (used internally).
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 |
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 |
---|
public DHCPOption(byte code, byte[] value, boolean mirror)
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.
code
- DHCP option codevalue
- DHCP option value as a byte array.public DHCPOption(byte code, byte[] value)
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.
code
- DHCP option codevalue
- DHCP option value as a byte array.Method Detail |
---|
public byte getCode()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public byte[] getValue()
public byte[] getValueFast()
public boolean isMirror()
To be used only in servers.
public static final boolean isOptionAsByte(byte code)
public static DHCPOption newOptionAsByte(byte code, byte val)
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)
code
- the option code.val
- the value
java.lang.IllegalArgumentException
- the option code is not in the list above.public byte getValueAsByte() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public static final boolean isOptionAsShort(byte code)
public short getValueAsShort() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public static final boolean isOptionAsInt(byte code)
public int getValueAsInt() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public java.lang.Integer getValueAsNum() throws java.lang.IllegalArgumentException
There is no check on the option
java.lang.IllegalArgumentException
public static final boolean isOptionAsInetAddr(byte code)
public java.net.InetAddress getValueAsInetAddr() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public static final boolean isOptionAsString(byte code)
public java.lang.String getValueAsString() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.public static final boolean isOptionAsShorts(byte code)
public short[] getValueAsShorts() throws java.lang.IllegalArgumentException
This method is only allowed for the following option codes:
DHO_PATH_MTU_PLATEAU_TABLE(25) DHO_NAME_SERVICE_SEARCH(117)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public static final boolean isOptionAsInetAddrs(byte code)
public java.net.InetAddress[] getValueAsInetAddrs() throws java.lang.IllegalArgumentException
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)
java.lang.IllegalArgumentException
- the option code is not in the list above.
DHCPBadPacketException
- the option value in packet is of wrong size.public static final boolean isOptionAsBytes(byte code)
public byte[] getValueAsBytes() throws java.lang.IllegalArgumentException
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.
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsShort(byte code, short val)
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)
code
- the option code.val
- the value
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsShorts(byte code, short[] arr)
This method is only allowed for the following option codes:
DHO_PATH_MTU_PLATEAU_TABLE(25) DHO_NAME_SERVICE_SEARCH(117)
code
- the option code.arr
- the array of shorts
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsInt(byte code, int val)
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)
code
- the option code.val
- the value
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsInetAddress(byte code, java.net.InetAddress val)
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)
code
- the option code.val
- the value
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsInetAddresses(byte code, java.net.InetAddress[] val)
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)
code
- the option code.val
- the value array
java.lang.IllegalArgumentException
- the option code is not in the list above.public static DHCPOption newOptionAsString(byte code, java.lang.String val)
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)
code
- the option code.val
- the value
java.lang.IllegalArgumentException
- the option code is not in the list above.public DHCPOption applyOption(DHCPPacket request)
This should be the only method used with this class to get relevant values.
request
- the client's DHCP requets
java.lang.NullPointerException
- if request is null.public void append(java.lang.StringBuilder buffer)
This multi-line string details: the static, options and padding parts of the object. This is useful for debugging, but not efficient.
buffer
- the string builder the string representation of this object should be appended.public java.lang.String toString()
This multi-line string details: the static, options and padding parts of the object. This is useful for debugging, but not efficient.
toString
in class java.lang.Object
public static byte[] byte2Bytes(byte val)
public static byte[] short2Bytes(short val)
public static byte[] int2Bytes(int val)
public static byte[] inetAddress2Bytes(java.net.InetAddress val)
public static byte[] inetAddresses2Bytes(java.net.InetAddress[] val)
public static java.util.List<java.lang.String> userClassToList(byte[] buf)
buf
- option value of type User Class.
public static java.lang.String userClassToString(byte[] buf)
buf
- option value of type User Class.
public static byte[] stringListToUserClass(java.util.List<java.lang.String> list)
list
- the list of strings
java.lang.IllegalArgumentException
- if List contains anything else than Stringpublic static java.lang.String agentOptionsToString(byte[] buf)
buf
- option value of type Agent Option.
public static byte[] agentOptionToRaw(java.util.Map<java.lang.Byte,java.lang.String> map)
LinkedHashMap are preferred as they preserve insertion order. Regular HashMap order is randon.
map
- Mapjava.lang.IllegalArgumentException
- if List contains anything else than Stringpublic static final java.util.Map<java.lang.Byte,java.lang.String> agentOptionsToMap(byte[] buf)
Order of parameters is preserved (use avc LinkedHashmapByte, values are of type String.
buf
- byte[] buffer returned by getOptionRaw
public static java.lang.Class getOptionFormat(byte code)
The type is returned as a Class object:
Please use getSimpleName() methode of Class object for the String representation.
code
- the DHCP option code
public static java.lang.Class string2Class(java.lang.String className)
Support values are:
className
- name of the data format (see above)
public static DHCPOption parseNewOption(byte code, java.lang.Class format, java.lang.String value)
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
code
- DHCP option codeformat
- expected Java Class after conversionvalue
- string representation of the value
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |