@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } ArpHeader other = (ArpHeader) obj; return operation.equals(other.getOperation()) && srcHardwareAddr.equals(other.srcHardwareAddr) && srcProtocolAddr.equals(other.srcProtocolAddr) && dstHardwareAddr.equals(other.dstHardwareAddr) && dstProtocolAddr.equals(other.dstProtocolAddr) && hardwareType.equals(other.hardwareType) && protocolType.equals(other.protocolType) && hardwareAddrLength == other.hardwareAddrLength && protocolAddrLength == other.protocolAddrLength; }
/** * @param value value * @return a ArpOperation object. */ public static ArpOperation getInstance(Short value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new ArpOperation(value, "unknown"); } }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + hardwareType.hashCode(); result = 31 * result + protocolType.hashCode(); result = 31 * result + hardwareAddrLength; result = 31 * result + protocolAddrLength; result = 31 * result + operation.hashCode(); result = 31 * result + srcHardwareAddr.hashCode(); result = 31 * result + srcProtocolAddr.hashCode(); result = 31 * result + dstHardwareAddr.hashCode(); result = 31 * result + dstProtocolAddr.hashCode(); return result; } }
/** * @param operation operation * @return a ArpOperation object. */ public static ArpOperation register(ArpOperation operation) { return registry.put(operation.value(), operation); }
private ArpHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ARP_HEADER_SIZE) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build an ARP header(") .append(ARP_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.hardwareType = ArpHardwareType.getInstance(ByteArrays.getShort(rawData, HARDWARE_TYPE_OFFSET + offset)); this.protocolType = EtherType.getInstance(ByteArrays.getShort(rawData, PROTOCOL_TYPE_OFFSET + offset)); this.hardwareAddrLength = ByteArrays.getByte(rawData, HW_ADDR_LENGTH_OFFSET + offset); this.protocolAddrLength = ByteArrays.getByte(rawData, PROTO_ADDR_LENGTH_OFFSET + offset); this.operation = ArpOperation.getInstance(ByteArrays.getShort(rawData, OPERATION_OFFSET + offset)); this.srcHardwareAddr = ByteArrays.getMacAddress(rawData, SRC_HARDWARE_ADDR_OFFSET + offset); this.srcProtocolAddr = ByteArrays.getInet4Address(rawData, SRC_PROTOCOL_ADDR_OFFSET + offset); this.dstHardwareAddr = ByteArrays.getMacAddress(rawData, DST_HARDWARE_ADDR_OFFSET + offset); this.dstProtocolAddr = ByteArrays.getInet4Address(rawData, DST_PROTOCOL_ADDR_OFFSET + offset); }
/** */ @Override public String valueAsString() { return String.valueOf(value() & 0xFFFF); }
private ArpHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ARP_HEADER_SIZE) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build an ARP header(") .append(ARP_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.hardwareType = ArpHardwareType.getInstance(ByteArrays.getShort(rawData, HARDWARE_TYPE_OFFSET + offset)); this.protocolType = EtherType.getInstance(ByteArrays.getShort(rawData, PROTOCOL_TYPE_OFFSET + offset)); this.hardwareAddrLength = ByteArrays.getByte(rawData, HW_ADDR_LENGTH_OFFSET + offset); this.protocolAddrLength = ByteArrays.getByte(rawData, PROTO_ADDR_LENGTH_OFFSET + offset); this.operation = ArpOperation.getInstance(ByteArrays.getShort(rawData, OPERATION_OFFSET + offset)); this.srcHardwareAddr = ByteArrays.getMacAddress(rawData, SRC_HARDWARE_ADDR_OFFSET + offset); this.srcProtocolAddr = ByteArrays.getInet4Address(rawData, SRC_PROTOCOL_ADDR_OFFSET + offset); this.dstHardwareAddr = ByteArrays.getMacAddress(rawData, DST_HARDWARE_ADDR_OFFSET + offset); this.dstProtocolAddr = ByteArrays.getInet4Address(rawData, DST_PROTOCOL_ADDR_OFFSET + offset); }
@Override public void gotPacket(Packet packet) { if (packet.contains(ArpPacket.class)) { ArpPacket arp = packet.get(ArpPacket.class); if (arp.getHeader().getOperation().equals(ArpOperation.REPLY)) { SendArpRequest.resolvedAddr = arp.getHeader().getSrcHardwareAddr(); } } System.out.println(packet); } };
/** * @param value value * @return a ArpOperation object. */ public static ArpOperation getInstance(Short value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new ArpOperation(value, "unknown"); } }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + hardwareType.hashCode(); result = 31 * result + protocolType.hashCode(); result = 31 * result + hardwareAddrLength; result = 31 * result + protocolAddrLength; result = 31 * result + operation.hashCode(); result = 31 * result + srcHardwareAddr.hashCode(); result = 31 * result + srcProtocolAddr.hashCode(); result = 31 * result + dstHardwareAddr.hashCode(); result = 31 * result + dstProtocolAddr.hashCode(); return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } ArpHeader other = (ArpHeader) obj; return operation.equals(other.getOperation()) && srcHardwareAddr.equals(other.srcHardwareAddr) && srcProtocolAddr.equals(other.srcProtocolAddr) && dstHardwareAddr.equals(other.dstHardwareAddr) && dstProtocolAddr.equals(other.dstProtocolAddr) && hardwareType.equals(other.hardwareType) && protocolType.equals(other.protocolType) && hardwareAddrLength == other.hardwareAddrLength && protocolAddrLength == other.protocolAddrLength; }
@Override protected List<byte[]> getRawFields() { List<byte[]> rawFields = new ArrayList<byte[]>(); rawFields.add(ByteArrays.toByteArray(hardwareType.value())); rawFields.add(ByteArrays.toByteArray(protocolType.value())); rawFields.add(ByteArrays.toByteArray(hardwareAddrLength)); rawFields.add(ByteArrays.toByteArray(protocolAddrLength)); rawFields.add(ByteArrays.toByteArray(operation.value())); rawFields.add(ByteArrays.toByteArray(srcHardwareAddr)); rawFields.add(ByteArrays.toByteArray(srcProtocolAddr)); rawFields.add(ByteArrays.toByteArray(dstHardwareAddr)); rawFields.add(ByteArrays.toByteArray(dstProtocolAddr)); return rawFields; }
@Override public void gotPacket(Packet packet) { if (packet.contains(ArpPacket.class)) { ArpPacket arp = packet.get(ArpPacket.class); if (arp.getHeader().getOperation().equals(ArpOperation.REPLY)) { SendArpRequest.resolvedAddr = arp.getHeader().getSrcHardwareAddr(); } } System.out.println(packet); } };
/** * @param operation operation * @return a ArpOperation object. */ public static ArpOperation register(ArpOperation operation) { return registry.put(operation.value(), operation); }
ArpPacket ap = packet.get(ArpPacket.class); if (!ap.getHeader().getOperation().equals(ArpOperation.REQUEST)) { return;
/** */ @Override public String valueAsString() { return String.valueOf(value() & 0xFFFF); }
ArpPacket ap = packet.get(ArpPacket.class); if (!ap.getHeader().getOperation().equals(ArpOperation.REQUEST)) { return;