Class DHCPMessage
java.lang.Object
com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPMessage
This class represents a DHCP Message.
- Author:
- Markus Bernhardt, Copyright 2016, Jason Goldschmidt, Nick Stone and Simon Frankenberger, Bernd Rosstauscher, Copyright 2009
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic InetAddressBroadcast Adress to send packets tostatic final intDefault DHCP client portstatic final byteMessage Code representing a DHCPACK messagestatic final byteMessage Code representing a DHCPDECLINE messagestatic final byteMessage Code representing a DHCPDISCOVER messagestatic final byteMessage Code representing a DHCPINFORM messagestatic final byteMessage Code representing a DHCPNAK messagestatic final byteMessage Code representing a DHCPOFFER messagestatic final byteMessage Code representing a DHCPRELEASE messagestatic final byteMessage Code representing a DHCPREQUEST messagestatic final byteOperation for a replystatic final byteOperation for a requeststatic final intDefault DHCP server port -
Constructor Summary
ConstructorsConstructorDescriptionCreates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, the local subnet, binds to the default server port.DHCPMessage(byte[] ibuf) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to default host name, the local subnet, and bind to the default server port.DHCPMessage(byte[] ibuf, int inPort) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to broadcast address, and binds to the specified port.DHCPMessage(byte[] ibuf, InetAddress inServername) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.DHCPMessage(byte[] ibuf, InetAddress inServername, int inPort) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.DHCPMessage(int inPort) Creates an empty DHCPMessage object, initializes the object, sets the host to the broadcast address, and binds to a specified port.DHCPMessage(DHCPMessage inMessage) Copy constructor creates DHCPMessage from inMessageDHCPMessage(DHCPMessage inMessage, InetAddress inServername) Copy constructor creates DHCPMessage from inMessage and sets server name.DHCPMessage(DHCPMessage inMessage, InetAddress inServername, int inPort) Copy constructor creates DHCPMessage from inMessage and sets server and port.DHCPMessage(DataInputStream inStream) Creates a new DHCPMessage object from the giben DataInputStream.DHCPMessage(InetAddress inServername) Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to the default port.DHCPMessage(InetAddress inServername, int inPort) Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to a specified port. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Converts a DHCPMessage object to a byte array.byte[]byte[]Get message destination hostnamebyte[]getFile()shortgetFlags()byte[]bytegetHlen()bytegetHops()bytegetHtype()bytegetOp()byte[]getOption(int inOptNum) Returns specified DHCP option that matches the input code.byte[]intgetPort()shortgetSecs()byte[]byte[]getSname()intgetXid()byte[]internalize(byte[] ibuff) Convert a specified byte array containing a DHCP message into a DHCPMessage object.booleanIsOptSet(int inOptNum) Report whether or not the input option is set.voidremoveOption(int inOptNum) Removes the specified DHCP option that matches the input code.voidsetChaddr(byte[] inChaddr) Set client harware address.voidsetCiaddr(byte[] inCiaddr) Set client IP address.voidsetDestinationHost(String inHost) Set message destination IPvoidsetFile(byte[] inFile) Set boot file name.voidsetFlags(short inFlags) Set flags field.voidsetGiaddr(byte[] inGiaddr) Set relay agent IP address.voidsetHlen(byte inHlen) Set hardware address length.voidsetHops(byte inHops) Set hops field.voidsetHtype(byte inHtype) Set hardware address type.voidsetOp(byte inOp) Set message Op code / message type.voidsetOption(int inOptNum, byte[] inOptionData) Sets DHCP options in DHCPMessage.voidsetPort(int inPortNum) Set message destination port.voidsetSecs(short inSecs) Set seconds elapsed since client began address acquisition or renewal process.voidsetSiaddr(byte[] inSiaddr) Set address of next server to use in bootstrap.voidsetSname(byte[] inSname) Set optional server host name.voidsetXid(int inXid) Set transaction ID.voidsetYiaddr(byte[] inYiaddr) Set 'your' (client) IP address.
-
Field Details
-
OP_REQUEST
public static final byte OP_REQUESTOperation for a request- See Also:
-
OP_REPLY
public static final byte OP_REPLYOperation for a reply- See Also:
-
DHCPDISCOVER
public static final byte DHCPDISCOVERMessage Code representing a DHCPDISCOVER message- See Also:
-
DHCPOFFER
public static final byte DHCPOFFERMessage Code representing a DHCPOFFER message- See Also:
-
DHCPREQUEST
public static final byte DHCPREQUESTMessage Code representing a DHCPREQUEST message- See Also:
-
DHCPDECLINE
public static final byte DHCPDECLINEMessage Code representing a DHCPDECLINE message- See Also:
-
DHCPACK
public static final byte DHCPACKMessage Code representing a DHCPACK message- See Also:
-
DHCPNAK
public static final byte DHCPNAKMessage Code representing a DHCPNAK message- See Also:
-
DHCPRELEASE
public static final byte DHCPRELEASEMessage Code representing a DHCPRELEASE message- See Also:
-
DHCPINFORM
public static final byte DHCPINFORMMessage Code representing a DHCPINFORM message- See Also:
-
CLIENT_PORT
public static final int CLIENT_PORTDefault DHCP client port- See Also:
-
SERVER_PORT
public static final int SERVER_PORTDefault DHCP server port- See Also:
-
BROADCAST_ADDR
Broadcast Adress to send packets to
-
-
Constructor Details
-
DHCPMessage
public DHCPMessage()Creates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, the local subnet, binds to the default server port. -
DHCPMessage
Copy constructor creates DHCPMessage from inMessage- Parameters:
inMessage- The message to be copied
-
DHCPMessage
Copy constructor creates DHCPMessage from inMessage and sets server and port.- Parameters:
inMessage- The message to be copiedinServername- The host nameinPort- The port number
-
DHCPMessage
Copy constructor creates DHCPMessage from inMessage and sets server name.- Parameters:
inMessage- The message to be copiedinServername- The host name
-
DHCPMessage
Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to a specified port.- Parameters:
inServername- The host nameinPort- The port number
-
DHCPMessage
Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to the default port.- Parameters:
inServername- The host name
-
DHCPMessage
public DHCPMessage(int inPort) Creates an empty DHCPMessage object, initializes the object, sets the host to the broadcast address, and binds to a specified port.- Parameters:
inPort- The port number
-
DHCPMessage
public DHCPMessage(byte[] ibuf) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to default host name, the local subnet, and bind to the default server port.- Parameters:
ibuf- The byte array to initialize DHCPMessage object
-
DHCPMessage
Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.- Parameters:
ibuf- The byte array to initialize DHCPMessage objectinServername- The hostnameinPort- The port number
-
DHCPMessage
public DHCPMessage(byte[] ibuf, int inPort) Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to broadcast address, and binds to the specified port.- Parameters:
ibuf- The byte array to initialize DHCPMessage objectinPort- The port number
-
DHCPMessage
Creates an empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.- Parameters:
ibuf- The byte array to initialize DHCPMessage objectinServername- The hostname
-
DHCPMessage
Creates a new DHCPMessage object from the giben DataInputStream.- Parameters:
inStream- The stream to read from
-
-
Method Details
-
externalize
public byte[] externalize()Converts a DHCPMessage object to a byte array.- Returns:
- A byte array with information from DHCPMessage object, ready to send.
-
internalize
Convert a specified byte array containing a DHCP message into a DHCPMessage object.- Parameters:
ibuff- Byte array to convert to a DHCPMessage object- Returns:
- A DHCPMessage object with information from byte array.
-
setOp
public void setOp(byte inOp) Set message Op code / message type.- Parameters:
inOp- message Op code / message type
-
setHtype
public void setHtype(byte inHtype) Set hardware address type.- Parameters:
inHtype- hardware address type
-
setHlen
public void setHlen(byte inHlen) Set hardware address length.- Parameters:
inHlen- hardware address length
-
setHops
public void setHops(byte inHops) Set hops field.- Parameters:
inHops- hops field
-
setXid
public void setXid(int inXid) Set transaction ID.- Parameters:
inXid- transactionID
-
setSecs
public void setSecs(short inSecs) Set seconds elapsed since client began address acquisition or renewal process.- Parameters:
inSecs- Seconds elapsed since client began address acquisition or renewal process
-
setFlags
public void setFlags(short inFlags) Set flags field.- Parameters:
inFlags- flags field
-
setCiaddr
public void setCiaddr(byte[] inCiaddr) Set client IP address.- Parameters:
inCiaddr- client IP address
-
setYiaddr
public void setYiaddr(byte[] inYiaddr) Set 'your' (client) IP address.- Parameters:
inYiaddr- 'your' (client) IP address
-
setSiaddr
public void setSiaddr(byte[] inSiaddr) Set address of next server to use in bootstrap.- Parameters:
inSiaddr- address of next server to use in bootstrap
-
setGiaddr
public void setGiaddr(byte[] inGiaddr) Set relay agent IP address.- Parameters:
inGiaddr- relay agent IP address
-
setChaddr
public void setChaddr(byte[] inChaddr) Set client harware address.- Parameters:
inChaddr- client hardware address
-
setSname
public void setSname(byte[] inSname) Set optional server host name.- Parameters:
inSname- server host name
-
setFile
public void setFile(byte[] inFile) Set boot file name.- Parameters:
inFile- boot file name
-
setPort
public void setPort(int inPortNum) Set message destination port.- Parameters:
inPortNum- port on message destination host
-
setDestinationHost
Set message destination IP- Parameters:
inHost- string representation of message destination IP or hostname
-
getOp
public byte getOp()- Returns:
- message Op code / message type.
-
getHtype
public byte getHtype()- Returns:
- hardware address type.
-
getHlen
public byte getHlen()- Returns:
- hardware address length.
-
getHops
public byte getHops()- Returns:
- hops field.
-
getXid
public int getXid()- Returns:
- transaction ID.
-
getSecs
public short getSecs()- Returns:
- seconds elapsed since client began address acquisition or renewal process.
-
getFlags
public short getFlags()- Returns:
- flags field.
-
getCiaddr
public byte[] getCiaddr()- Returns:
- client IP address.
-
getYiaddr
public byte[] getYiaddr()- Returns:
- 'your' (client) IP address.
-
getSiaddr
public byte[] getSiaddr()- Returns:
- address of next server to use in bootstrap.
-
getGiaddr
public byte[] getGiaddr()- Returns:
- relay agent IP address.
-
getChaddr
public byte[] getChaddr()- Returns:
- client harware address.
-
getSname
public byte[] getSname()- Returns:
- optional server host name.
-
getFile
public byte[] getFile()- Returns:
- boot file name.
-
getOptions
public byte[] getOptions()- Returns:
- a byte array containing options
-
getPort
public int getPort()- Returns:
- An interger representation of the message destination port
-
getDestinationAddress
Get message destination hostname- Returns:
- A string representing the hostname of the message destination server
-
setOption
public void setOption(int inOptNum, byte[] inOptionData) Sets DHCP options in DHCPMessage. If option already exists then remove old option and insert a new one.- Parameters:
inOptNum- option numberinOptionData- option data
-
getOption
public byte[] getOption(int inOptNum) Returns specified DHCP option that matches the input code. Null is returned if option is not set.- Parameters:
inOptNum- option number- Returns:
- the option matching input code
-
removeOption
public void removeOption(int inOptNum) Removes the specified DHCP option that matches the input code.- Parameters:
inOptNum- option number
-
IsOptSet
public boolean IsOptSet(int inOptNum) Report whether or not the input option is set.- Parameters:
inOptNum- option number- Returns:
- is the given option set?
-