/** * @param type type * @return a EtherType object. */ public static EtherType register(EtherType type) { return registry.put(type.value(), type); }
private EthernetHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ETHERNET_HEADER_SIZE) { StringBuilder sb = new StringBuilder(100); sb.append("The data is too short to build an Ethernet header(") .append(ETHERNET_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.dstAddr = ByteArrays.getMacAddress(rawData, DST_ADDR_OFFSET + offset); this.srcAddr = ByteArrays.getMacAddress(rawData, SRC_ADDR_OFFSET + offset); this.type = EtherType.getInstance(ByteArrays.getShort(rawData, TYPE_OFFSET + offset)); }
/** * @param value value * @return a EtherType object. */ public static EtherType getInstance(Short value) { if (registry.containsKey(value)) { return registry.get(value); } else if ((value & 0xFFFF) <= IEEE802_3_MAX_LENGTH) { return new EtherType(value, "Length"); } else { return new EtherType(value, "unknown"); } }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + priority; result = 31 * result + (cfi ? 1231 : 1237); result = 31 * result + vid; result = 31 * result + type.hashCode(); return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } Dot1qVlanTagHeader other = (Dot1qVlanTagHeader) obj; return vid == other.vid && type.equals(other.type) && priority == other.priority && cfi == other.cfi; }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + oui.hashCode(); result = 31 * result + protocolId.hashCode(); return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } SnapHeader other = (SnapHeader) obj; return oui.equals(other.oui) && protocolId.equals(other.protocolId); }
private SnapHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < SNAP_HEADER_SIZE) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build a SNAP header(") .append(SNAP_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.oui = Oui.getInstance(ByteArrays.getSubArray(rawData, offset + OUI_OFFSET, 3)); this.protocolId = EtherType.getInstance(ByteArrays.getShort(rawData, offset + PROTOCOL_ID_OFFSET)); }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + packetType.hashCode(); result = 31 * result + addressType.hashCode(); result = 31 * result + addressLength; result = 31 * result + Arrays.hashCode(addressField); result = 31 * result + protocol.hashCode(); return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } EthernetHeader other = (EthernetHeader) obj; return dstAddr.equals(other.dstAddr) && srcAddr.equals(other.srcAddr) && type.equals(other.type); }
/** * @param value value * @return a EtherType object. */ public static EtherType getInstance(Short value) { if (registry.containsKey(value)) { return registry.get(value); } else if ((value & 0xFFFF) <= IEEE802_3_MAX_LENGTH) { return new EtherType(value, "Length"); } else { return new EtherType(value, "unknown"); } }
private Dot1qVlanTagHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < DOT1Q_TAG_HEADER_SIZE) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build an IEEE802.1Q Tag header(") .append(DOT1Q_TAG_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } short priorityAndCfiAndVid = ByteArrays.getShort(rawData, PRIORITY_AND_CFI_AND_VID_OFFSET + offset); this.priority = (byte) ((priorityAndCfiAndVid & 0xE000) >> 13); this.cfi = ((priorityAndCfiAndVid & 0x1000) >> 12) == 1; this.vid = (short) (priorityAndCfiAndVid & 0x0FFF); this.type = EtherType.getInstance(ByteArrays.getShort(rawData, TYPE_OFFSET + offset)); }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + dstAddr.hashCode(); result = 31 * result + srcAddr.hashCode(); result = 31 * result + type.hashCode(); return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } LinuxSllHeader other = (LinuxSllHeader) obj; return Arrays.equals(addressField, other.addressField) && packetType.equals(other.packetType) && protocol.equals(other.protocol) && addressType.equals(other.addressType) && addressLength == other.addressLength; }
/** @return a string representation of this value. */ @Override public String valueAsString() { return "0x" + ByteArrays.toHexString(value(), ""); }
ByteArrays.getLinkLayerAddress(rawData, ADDR_OFFSET + offset, getAddressLengthAsInt()); this.protocol = EtherType.getInstance(ByteArrays.getShort(rawData, PROTOCOL_OFFSET + offset));
@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; }