public static Ethernet DhcpDiscoveryRequestEthernet(MACAddress hostMac) {
List<DHCPOption> optionList = new ArrayList<DHCPOption>();
byte[] requestValue = new byte[4];
requestValue[0] = requestValue[1] = requestValue[2] = requestValue[3] = 0;
DHCPOption requestOption =
new DHCPOption()
.setCode(DHCP.DHCPOptionCode.OptionCode_RequestedIP.
getValue())
.setLength((byte)4)
.setData(requestValue);
byte[] msgTypeValue = new byte[1];
msgTypeValue[0] = 1; // DHCP request
DHCPOption msgTypeOption =
new DHCPOption()
.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.
getValue())
.setLength((byte)1)
.setData(msgTypeValue);
byte[] reqParamValue = new byte[4];
reqParamValue[0] = 1; // subnet mask
reqParamValue[1] = 3; // Router
reqParamValue[2] = 6; // Domain Name Server
reqParamValue[3] = 42; // NTP Server
DHCPOption reqParamOption =
new DHCPOption()
.setCode(DHCP.DHCPOptionCode.OptionCode_RequestedParameters.
getValue())
.setLength((byte)4)
.setData(reqParamValue);
byte[] clientIdValue = new byte[7];
clientIdValue[0] = 1; // Ethernet
System.arraycopy(hostMac.toBytes(), 0,
clientIdValue, 1, 6);
DHCPOption clientIdOption =
new DHCPOption()
.setCode(DHCP.DHCPOptionCode.OptionCode_ClientID.
getValue())
.setLength((byte)7)
.setData(clientIdValue);
DHCPOption endOption =
new DHCPOption()
.setCode(DHCP.DHCPOptionCode.OptionCode_END.
getValue())
.setLength((byte)0)
.setData(null);