Class DHCPMessage
java.lang.Object
com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPMessage
This class represents a DHCP Message.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic InetAddressBroadcast Adress to send packets toprivate byte[]Client hardware address.private byte[]Client IP address; filled in by client in DHCPREQUEST if verifying previously allocated configuration parameters.static final intDefault DHCP client portprivate InetAddressThe destination IP-Adress of this messagestatic 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 messageprivate byte[]Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.private shortFlags for this message.
The leftmost bit is defined as the BROADCAST (B) flag.private byte[]Relay agent IP address, used in booting via a relay-agent.private intglobal port variable for this messageprivate byteHardware address length (e.g.private byteClient sets to zero, optionally used by relay-agents when booting via a relay-agent.private byteNetworktype as defined by RFC1340 page 54.private bytestatic final byteOperation for a replystatic final byteOperation for a requestprivate DHCPOptionsInternal representation of the given DHCP options.private shortFilled in by client, seconds elapsed since client started trying to boot.static final intDefault DHCP server portprivate byte[]IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server.private byte[]Optional server host name, null terminated string.private intTransaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.private byte[]'your' (client) IP address. -
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[]private voidInitializes datamembers in the constructors every empty DHCPMessage object will by default contain these params.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 -
op
private byte op -
htype
private byte htypeNetworktype as defined by RFC1340 page 54. -
hlen
private byte hlenHardware address length (e.g. '6' for ethernet). -
hops
private byte hopsClient sets to zero, optionally used by relay-agents when booting via a relay-agent. -
xid
private int xidTransaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server. -
secs
private short secsFilled in by client, seconds elapsed since client started trying to boot. -
flags
private short flagsFlags for this message.
The leftmost bit is defined as the BROADCAST (B) flag. -
ciaddr
private byte[] ciaddrClient IP address; filled in by client in DHCPREQUEST if verifying previously allocated configuration parameters. -
yiaddr
private byte[] yiaddr'your' (client) IP address. -
siaddr
private byte[] siaddrIP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server. -
giaddr
private byte[] giaddrRelay agent IP address, used in booting via a relay-agent. -
chaddr
private byte[] chaddrClient hardware address. -
sname
private byte[] snameOptional server host name, null terminated string. -
file
private byte[] fileBoot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER. -
optionsList
Internal representation of the given DHCP options. -
gPort
private int gPortglobal port variable for this message -
destination_IP
The destination IP-Adress of this message
-
-
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
-
initialize
private void initialize()Initializes datamembers in the constructors every empty DHCPMessage object will by default contain these params. Initializes options array from linked list form. -
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?
-