@Test public void testDeserialize() throws Exception { DHCP dhcp = deserializer.deserialize(byteHeader, 0, byteHeader.length); assertEquals(opCode, dhcp.opCode); assertEquals(hardwareType, dhcp.hardwareType); assertEquals(hardwareAddressLength, dhcp.hardwareAddressLength); assertEquals(hops, dhcp.hops); assertEquals(transactionId, dhcp.transactionId); assertEquals(seconds, dhcp.seconds); assertEquals(flags, dhcp.flags); assertEquals(clientIpAddress, dhcp.clientIPAddress); assertEquals(yourIpAddress, dhcp.yourIPAddress); assertEquals(serverIpAddress, dhcp.serverIPAddress); assertEquals(gatewayIpAddress, dhcp.gatewayIPAddress); assertTrue(Arrays.equals(clientHardwareAddress, dhcp.clientHardwareAddress)); assertEquals(serverName, dhcp.serverName); assertEquals(bootFileName, dhcp.bootFileName); assertEquals(2, dhcp.options.size()); assertEquals(hostNameOption, dhcp.options.get(0)); }
@Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); if (bb.remaining() < DHCP.MIN_HEADER_LENGTH) { return this; } this.opCode = bb.get(); this.hardwareType = bb.get(); this.hardwareAddressLength = bb.get(); this.hops = bb.get(); this.transactionId = bb.getInt(); this.seconds = bb.getShort(); this.flags = bb.getShort(); this.clientIPAddress = bb.getInt(); this.yourIPAddress = bb.getInt(); this.serverIPAddress = bb.getInt(); this.gatewayIPAddress = bb.getInt(); final int hardwareAddressLength = 0xff & this.hardwareAddressLength; this.clientHardwareAddress = new byte[hardwareAddressLength]; bb.get(this.clientHardwareAddress); for (int i = hardwareAddressLength; i < 16; ++i) { bb.get(); } this.serverName = this.readString(bb, 64); this.bootFileName = this.readString(bb, 128); bb.get(); bb.get(); bb.get(); bb.get(); while (bb.hasRemaining()) { final DHCPOption option = new DHCPOption(); int code = 0xff & bb.get(); option.setCode((byte) code); if (code == 0) { continue; } else if (code != 255) { if (bb.hasRemaining()) { final int l = 0xff & bb.get(); option.setLength((byte) l); if (bb.remaining() >= l) { final byte[] optionData = new byte[l]; bb.get(optionData); option.setData(optionData); } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } this.options.add(option); if (code == 255) { break; } } return this; }
DHCP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); if (bb.remaining() < DHCP.MIN_HEADER_LENGTH) { return this; } this.opCode = bb.get(); this.hardwareType = bb.get(); this.hardwareAddressLength = bb.get(); this.hops = bb.get(); this.transactionId = bb.getInt(); this.seconds = bb.getShort(); this.flags = bb.getShort(); this.clientIPAddress = bb.getInt(); this.yourIPAddress = bb.getInt(); this.serverIPAddress = bb.getInt(); this.gatewayIPAddress = bb.getInt(); final int hardwareAddressLength = 0xff & this.hardwareAddressLength; this.clientHardwareAddress = new byte[hardwareAddressLength]; bb.get(this.clientHardwareAddress); for (int i = hardwareAddressLength; i < 16; ++i) { bb.get(); } this.serverName = this.readString(bb, 64); this.bootFileName = this.readString(bb, 128); bb.get(); bb.get(); bb.get(); bb.get(); while (bb.hasRemaining()) { final DHCPOption option = new DHCPOption(); int code = 0xff & bb.get(); option.setCode((byte) code); if (code == 0) { continue; } else if (code != 255) { if (bb.hasRemaining()) { final int l = 0xff & bb.get(); option.setLength((byte) l); if (bb.remaining() >= l) { final byte[] optionData = new byte[l]; bb.get(optionData); option.setData(optionData); } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } this.options.add(option); if (code == 255) { break; } } return this; } }
DHCP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); if (bb.remaining() < DHCP.MIN_HEADER_LENGTH) { return this; } this.opCode = bb.get(); this.hardwareType = bb.get(); this.hardwareAddressLength = bb.get(); this.hops = bb.get(); this.transactionId = bb.getInt(); this.seconds = bb.getShort(); this.flags = bb.getShort(); this.clientIPAddress = bb.getInt(); this.yourIPAddress = bb.getInt(); this.serverIPAddress = bb.getInt(); this.gatewayIPAddress = bb.getInt(); final int hardwareAddressLength = 0xff & this.hardwareAddressLength; this.clientHardwareAddress = new byte[hardwareAddressLength]; bb.get(this.clientHardwareAddress); for (int i = hardwareAddressLength; i < 16; ++i) { bb.get(); } this.serverName = this.readString(bb, 64); this.bootFileName = this.readString(bb, 128); bb.get(); bb.get(); bb.get(); bb.get(); while (bb.hasRemaining()) { final DHCPOption option = new DHCPOption(); int code = 0xff & bb.get(); option.setCode((byte) code); if (code == 0) { continue; } else if (code != 255) { if (bb.hasRemaining()) { final int l = 0xff & bb.get(); option.setLength((byte) l); if (bb.remaining() >= l) { final byte[] optionData = new byte[l]; bb.get(optionData); option.setData(optionData); } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } this.options.add(option); if (code == 255) { break; } } return this; }  }
DHCP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); if (bb.remaining() < DHCP.MIN_HEADER_LENGTH) { return this; } this.opCode = bb.get(); this.hardwareType = bb.get(); this.hardwareAddressLength = bb.get(); this.hops = bb.get(); this.transactionId = bb.getInt(); this.seconds = bb.getShort(); this.flags = bb.getShort(); this.clientIPAddress = bb.getInt(); this.yourIPAddress = bb.getInt(); this.serverIPAddress = bb.getInt(); this.gatewayIPAddress = bb.getInt(); final int hardwareAddressLength = 0xff & this.hardwareAddressLength; this.clientHardwareAddress = new byte[hardwareAddressLength]; bb.get(this.clientHardwareAddress); for (int i = hardwareAddressLength; i < 16; ++i) { bb.get(); } this.serverName = this.readString(bb, 64); this.bootFileName = this.readString(bb, 128); bb.get(); bb.get(); bb.get(); bb.get(); while (bb.hasRemaining()) { final DHCPOption option = new DHCPOption(); int code = 0xff & bb.get(); option.setCode((byte) code); if (code == 0) { continue; } else if (code != 255) { if (bb.hasRemaining()) { final int l = 0xff & bb.get(); option.setLength((byte) l); if (bb.remaining() >= l) { final byte[] optionData = new byte[l]; bb.get(optionData); option.setData(optionData); } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } this.options.add(option); if (code == 255) { break; } } return this; }  byte getOpCode(); DHCP setOpCode(final byte opCode); byte getHardwareType(); DHCP setHardwareType(final byte hardwareType); byte getHardwareAddressLength(); DHCP setHardwareAddressLength(final byte hardwareAddressLength); byte getHops(); DHCP setHops(final byte hops); int getTransactionId(); DHCP setTransactionId(final int transactionId); short getSeconds(); DHCP setSeconds(final short seconds); short getFlags(); DHCP setFlags(final short flags); int getClientIPAddress(); DHCP setClientIPAddress(final int clientIPAddress); int getYourIPAddress(); DHCP setYourIPAddress(final int yourIPAddress); int getServerIPAddress(); DHCP setServerIPAddress(final int serverIPAddress); int getGatewayIPAddress(); DHCP setGatewayIPAddress(final int gatewayIPAddress); byte[] getClientHardwareAddress(); DHCP setClientHardwareAddress(final byte[] clientHardwareAddress); DHCPOption getOption(final DHCPOptionCode optionCode); List<DHCPOption> getOptions(); DHCP setOptions(final List<DHCPOption> options); DHCPPacketType getPacketType(); String getServerName(); DHCP setServerName(final String server); String getBootFileName(); DHCP setBootFileName(final String bootFile); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); static Deserializer<DHCP> deserializer(); @Override String toString(); }
DHCP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); if (bb.remaining() < DHCP.MIN_HEADER_LENGTH) { return this; } this.opCode = bb.get(); this.hardwareType = bb.get(); this.hardwareAddressLength = bb.get(); this.hops = bb.get(); this.transactionId = bb.getInt(); this.seconds = bb.getShort(); this.flags = bb.getShort(); this.clientIPAddress = bb.getInt(); this.yourIPAddress = bb.getInt(); this.serverIPAddress = bb.getInt(); this.gatewayIPAddress = bb.getInt(); final int hardwareAddressLength = 0xff & this.hardwareAddressLength; this.clientHardwareAddress = new byte[hardwareAddressLength]; bb.get(this.clientHardwareAddress); for (int i = hardwareAddressLength; i < 16; ++i) { bb.get(); } this.serverName = this.readString(bb, 64); this.bootFileName = this.readString(bb, 128); bb.get(); bb.get(); bb.get(); bb.get(); while (bb.hasRemaining()) { final DHCPOption option = new DHCPOption(); int code = 0xff & bb.get(); option.setCode((byte) code); if (code == 0) { continue; } else if (code != 255) { if (bb.hasRemaining()) { final int l = 0xff & bb.get(); option.setLength((byte) l); if (bb.remaining() >= l) { final byte[] optionData = new byte[l]; bb.get(optionData); option.setData(optionData); } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } else { code = 0xff; option.setCode((byte) code); option.setLength((byte) 0); } } this.options.add(option); if (code == 255) { break; } } return this; }  byte getOpCode(); DHCP setOpCode(final byte opCode); byte getHardwareType(); DHCP setHardwareType(final byte hardwareType); byte getHardwareAddressLength(); DHCP setHardwareAddressLength(final byte hardwareAddressLength); byte getHops(); DHCP setHops(final byte hops); int getTransactionId(); DHCP setTransactionId(final int transactionId); short getSeconds(); DHCP setSeconds(final short seconds); short getFlags(); DHCP setFlags(final short flags); int getClientIPAddress(); DHCP setClientIPAddress(final int clientIPAddress); int getYourIPAddress(); DHCP setYourIPAddress(final int yourIPAddress); int getServerIPAddress(); DHCP setServerIPAddress(final int serverIPAddress); int getGatewayIPAddress(); DHCP setGatewayIPAddress(final int gatewayIPAddress); byte[] getClientHardwareAddress(); DHCP setClientHardwareAddress(final byte[] clientHardwareAddress); DHCPOption getOption(final DHCPOptionCode optionCode); List<DHCPOption> getOptions(); DHCP setOptions(final List<DHCPOption> options); DHCPPacketType getPacketType(); String getServerName(); DHCP setServerName(final String server); String getBootFileName(); DHCP setBootFileName(final String bootFile); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); static Deserializer<DHCP> deserializer(); @Override String toString(); static final int MIN_HEADER_LENGTH; static final byte OPCODE_REQUEST; static final byte OPCODE_REPLY; static final byte HWTYPE_ETHERNET; }