@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ARP other = (ARP) obj; if (hardwareAddressLength != other.hardwareAddressLength) return false; if (hardwareType != other.hardwareType) return false; if (opCode == null) { if (other.opCode != null) return false; } else if (!opCode.equals(other.opCode)) return false; if (protocolAddressLength != other.protocolAddressLength) return false; if (protocolType != other.protocolType) return false; if (senderHardwareAddress == null) { if (other.senderHardwareAddress != null) return false; } else if (!senderHardwareAddress.equals(other.senderHardwareAddress)) return false; if (senderProtocolAddress == null) { if (other.senderProtocolAddress != null) return false; } else if (!senderProtocolAddress.equals(other.senderProtocolAddress)) return false; if (targetHardwareAddress == null) { if (other.targetHardwareAddress != null) return false; } else if (!targetHardwareAddress.equals(other.targetHardwareAddress)) return false; if (targetProtocolAddress == null) { if (other.targetProtocolAddress != null) return false; } else if (!targetProtocolAddress.equals(other.targetProtocolAddress)) return false; return true; }
@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; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hardwareAddressLength; result = prime * result + hardwareType; result = prime * result + ((opCode == null) ? 0 : opCode.hashCode()); result = prime * result + protocolAddressLength; result = prime * result + protocolType; result = prime * result + ((senderHardwareAddress == null) ? 0 : senderHardwareAddress.hashCode()); result = prime * result + ((senderProtocolAddress == null) ? 0 : senderProtocolAddress.hashCode()); result = prime * result + ((targetHardwareAddress == null) ? 0 : targetHardwareAddress.hashCode()); result = prime * result + ((targetProtocolAddress == null) ? 0 : targetProtocolAddress.hashCode()); return result; }