Class DHCPMessage
- java.lang.Object
-
- com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPMessage
-
public class DHCPMessage extends java.lang.Object
This class represents a DHCP Message.
-
-
Field Summary
Fields Modifier and Type Field Description static java.net.InetAddress
BROADCAST_ADDR
Broadcast Adress to send packets toprivate byte[]
chaddr
Client hardware address.private byte[]
ciaddr
Client IP address; filled in by client in DHCPREQUEST if verifying previously allocated configuration parameters.static int
CLIENT_PORT
Default DHCP client portprivate java.net.InetAddress
destination_IP
The destination IP-Adress of this messagestatic byte
DHCPACK
Message Code representing a DHCPACK messagestatic byte
DHCPDECLINE
Message Code representing a DHCPDECLINE messagestatic byte
DHCPDISCOVER
Message Code representing a DHCPDISCOVER messagestatic byte
DHCPINFORM
Message Code representing a DHCPINFORM messagestatic byte
DHCPNAK
Message Code representing a DHCPNAK messagestatic byte
DHCPOFFER
Message Code representing a DHCPOFFER messagestatic byte
DHCPRELEASE
Message Code representing a DHCPRELEASE messagestatic byte
DHCPREQUEST
Message Code representing a DHCPREQUEST messageprivate byte[]
file
Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.private short
flags
Flags for this message.
The leftmost bit is defined as the BROADCAST (B) flag.private byte[]
giaddr
Relay agent IP address, used in booting via a relay-agent.private int
gPort
global port variable for this messageprivate byte
hlen
Hardware address length (e.g.private byte
hops
Client sets to zero, optionally used by relay-agents when booting via a relay-agent.private byte
htype
Networktype as defined by RFC1340 page 54.private byte
op
static byte
OP_REPLY
Operation for a replystatic byte
OP_REQUEST
Operation for a requestprivate DHCPOptions
optionsList
Internal representation of the given DHCP options.private short
secs
Filled in by client, seconds elapsed since client started trying to boot.static int
SERVER_PORT
Default DHCP server portprivate byte[]
siaddr
IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server.private byte[]
sname
Optional server host name, null terminated string.private int
xid
Transaction 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[]
yiaddr
'your' (client) IP address.
-
Constructor Summary
Constructors Constructor Description 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(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, java.net.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, java.net.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, java.net.InetAddress inServername)
Copy constructor creates DHCPMessage from inMessage and sets server name.DHCPMessage(DHCPMessage inMessage, java.net.InetAddress inServername, int inPort)
Copy constructor creates DHCPMessage from inMessage and sets server and port.DHCPMessage(java.io.DataInputStream inStream)
Creates a new DHCPMessage object from the giben DataInputStream.DHCPMessage(java.net.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(java.net.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
externalize()
Converts a DHCPMessage object to a byte array.byte[]
getChaddr()
byte[]
getCiaddr()
java.lang.String
getDestinationAddress()
Get message destination hostnamebyte[]
getFile()
short
getFlags()
byte[]
getGiaddr()
byte
getHlen()
byte
getHops()
byte
getHtype()
byte
getOp()
byte[]
getOption(int inOptNum)
Returns specified DHCP option that matches the input code.byte[]
getOptions()
int
getPort()
short
getSecs()
byte[]
getSiaddr()
byte[]
getSname()
int
getXid()
byte[]
getYiaddr()
private void
initialize()
Initializes datamembers in the constructors every empty DHCPMessage object will by default contain these params.DHCPMessage
internalize(byte[] ibuff)
Convert a specified byte array containing a DHCP message into a DHCPMessage object.boolean
IsOptSet(int inOptNum)
Report whether or not the input option is set.void
removeOption(int inOptNum)
Removes the specified DHCP option that matches the input code.void
setChaddr(byte[] inChaddr)
Set client harware address.void
setCiaddr(byte[] inCiaddr)
Set client IP address.void
setDestinationHost(java.lang.String inHost)
Set message destination IPvoid
setFile(byte[] inFile)
Set boot file name.void
setFlags(short inFlags)
Set flags field.void
setGiaddr(byte[] inGiaddr)
Set relay agent IP address.void
setHlen(byte inHlen)
Set hardware address length.void
setHops(byte inHops)
Set hops field.void
setHtype(byte inHtype)
Set hardware address type.void
setOp(byte inOp)
Set message Op code / message type.void
setOption(int inOptNum, byte[] inOptionData)
Sets DHCP options in DHCPMessage.void
setPort(int inPortNum)
Set message destination port.void
setSecs(short inSecs)
Set seconds elapsed since client began address acquisition or renewal process.void
setSiaddr(byte[] inSiaddr)
Set address of next server to use in bootstrap.void
setSname(byte[] inSname)
Set optional server host name.void
setXid(int inXid)
Set transaction ID.void
setYiaddr(byte[] inYiaddr)
Set 'your' (client) IP address.
-
-
-
Field Detail
-
OP_REQUEST
public static final byte OP_REQUEST
Operation for a request- See Also:
- Constant Field Values
-
OP_REPLY
public static final byte OP_REPLY
Operation for a reply- See Also:
- Constant Field Values
-
DHCPDISCOVER
public static final byte DHCPDISCOVER
Message Code representing a DHCPDISCOVER message- See Also:
- Constant Field Values
-
DHCPOFFER
public static final byte DHCPOFFER
Message Code representing a DHCPOFFER message- See Also:
- Constant Field Values
-
DHCPREQUEST
public static final byte DHCPREQUEST
Message Code representing a DHCPREQUEST message- See Also:
- Constant Field Values
-
DHCPDECLINE
public static final byte DHCPDECLINE
Message Code representing a DHCPDECLINE message- See Also:
- Constant Field Values
-
DHCPACK
public static final byte DHCPACK
Message Code representing a DHCPACK message- See Also:
- Constant Field Values
-
DHCPNAK
public static final byte DHCPNAK
Message Code representing a DHCPNAK message- See Also:
- Constant Field Values
-
DHCPRELEASE
public static final byte DHCPRELEASE
Message Code representing a DHCPRELEASE message- See Also:
- Constant Field Values
-
DHCPINFORM
public static final byte DHCPINFORM
Message Code representing a DHCPINFORM message- See Also:
- Constant Field Values
-
CLIENT_PORT
public static final int CLIENT_PORT
Default DHCP client port- See Also:
- Constant Field Values
-
SERVER_PORT
public static final int SERVER_PORT
Default DHCP server port- See Also:
- Constant Field Values
-
BROADCAST_ADDR
public static java.net.InetAddress BROADCAST_ADDR
Broadcast Adress to send packets to
-
op
private byte op
-
htype
private byte htype
Networktype as defined by RFC1340 page 54.
-
hlen
private byte hlen
Hardware address length (e.g. '6' for ethernet).
-
hops
private byte hops
Client sets to zero, optionally used by relay-agents when booting via a relay-agent.
-
xid
private int xid
Transaction 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 secs
Filled in by client, seconds elapsed since client started trying to boot.
-
flags
private short flags
Flags for this message.
The leftmost bit is defined as the BROADCAST (B) flag.
-
ciaddr
private byte[] ciaddr
Client 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[] siaddr
IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server.
-
giaddr
private byte[] giaddr
Relay agent IP address, used in booting via a relay-agent.
-
chaddr
private byte[] chaddr
Client hardware address.
-
sname
private byte[] sname
Optional server host name, null terminated string.
-
file
private byte[] file
Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
-
optionsList
private DHCPOptions optionsList
Internal representation of the given DHCP options.
-
gPort
private int gPort
global port variable for this message
-
destination_IP
private java.net.InetAddress destination_IP
The destination IP-Adress of this message
-
-
Constructor Detail
-
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
public DHCPMessage(DHCPMessage inMessage)
Copy constructor creates DHCPMessage from inMessage- Parameters:
inMessage
- The message to be copied
-
DHCPMessage
public DHCPMessage(DHCPMessage inMessage, java.net.InetAddress inServername, int inPort)
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
public DHCPMessage(DHCPMessage inMessage, java.net.InetAddress inServername)
Copy constructor creates DHCPMessage from inMessage and sets server name.- Parameters:
inMessage
- The message to be copiedinServername
- The host name
-
DHCPMessage
public DHCPMessage(java.net.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.- Parameters:
inServername
- The host nameinPort
- The port number
-
DHCPMessage
public DHCPMessage(java.net.InetAddress inServername)
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
public DHCPMessage(byte[] ibuf, java.net.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.- 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
public DHCPMessage(byte[] ibuf, java.net.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.- Parameters:
ibuf
- The byte array to initialize DHCPMessage objectinServername
- The hostname
-
DHCPMessage
public DHCPMessage(java.io.DataInputStream inStream)
Creates a new DHCPMessage object from the giben DataInputStream.- Parameters:
inStream
- The stream to read from
-
-
Method Detail
-
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
public DHCPMessage internalize(byte[] ibuff)
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
public void setDestinationHost(java.lang.String inHost)
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
public java.lang.String 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?
-
-