Exemple #1
0
  @Override
  public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException {
    ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
    this.hardwareType = bb.getShort();
    this.protocolType = bb.getShort();
    this.hardwareAddressLength = bb.get();
    this.protocolAddressLength = bb.get();
    if (this.hardwareAddressLength != 6) {
      String msg = "Incorrect ARP hardware address length: " + hardwareAddressLength;
      throw new PacketParsingException(msg);
    }
    if (this.protocolAddressLength != 4) {
      String msg = "Incorrect ARP protocol address length: " + protocolAddressLength;
      throw new PacketParsingException(msg);
    }
    this.opCode = ArpOpcode.of(bb.getShort());

    byte[] tmpMac = new byte[0xff & this.hardwareAddressLength];
    byte[] tmpIp = new byte[0xff & this.protocolAddressLength];

    bb.get(tmpMac, 0, this.hardwareAddressLength);
    this.senderHardwareAddress = MacAddress.of(tmpMac);
    bb.get(tmpIp, 0, this.protocolAddressLength);
    this.senderProtocolAddress = IPv4Address.of(tmpIp);

    bb.get(tmpMac, 0, this.hardwareAddressLength);
    this.targetHardwareAddress = MacAddress.of(tmpMac);
    bb.get(tmpIp, 0, this.protocolAddressLength);
    this.targetProtocolAddress = IPv4Address.of(tmpIp);

    return this;
  }