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)); }
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)); }
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)); }
ByteArrays.getLinkLayerAddress(rawData, ADDR_OFFSET + offset, getAddressLengthAsInt()); this.protocol = EtherType.getInstance(ByteArrays.getShort(rawData, PROTOCOL_OFFSET + offset));
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 protected Packet getWholePacket() { EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(MacAddress.getByName("aa:bb:cc:dd:ee:ff")) .srcAddr(MacAddress.getByName("11:22:33:44:55:66")) .type(EtherType.getInstance((short) packet.length())) .payloadBuilder(new SimpleBuilder(packet)) .paddingAtBuild(true); return eb.build(); }
@Override protected Packet getWholePacket() { EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(MacAddress.getByName("aa:bb:cc:dd:ee:ff")) .srcAddr(MacAddress.getByName("11:22:33:44:55:66")) .type(EtherType.getInstance((short) packet.length())) .payloadBuilder(new SimpleBuilder(packet)) .paddingAtBuild(true); return eb.build(); }
@Override protected Packet getWholePacket() { EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(((ArpPacket) packet.getPayload()).getHeader().getDstHardwareAddr()) .srcAddr(((ArpPacket) packet.getPayload()).getHeader().getSrcHardwareAddr()) .type(EtherType.getInstance((short) packet.length())) .payloadBuilder(new SimpleBuilder(packet)) .paddingAtBuild(true); return eb.build(); }
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)); }
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)); }
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)); }
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); }
ByteArrays.getLinkLayerAddress(rawData, ADDR_OFFSET + offset, getAddressLengthAsInt()); this.protocol = EtherType.getInstance(ByteArrays.getShort(rawData, PROTOCOL_OFFSET + offset));
@Override protected Packet getWholePacket() { LlcPacket llc = new LlcPacket.Builder() .dsap(LlcNumber.SNAP) .ssap(LlcNumber.SNAP) .control( new LlcControlUnnumbered.Builder() .modifierFunction(LlcControlModifierFunction.UI) .pfBit(false) .build()) .payloadBuilder(new SimpleBuilder(packet)) .build(); EthernetPacket.Builder eb = new EthernetPacket.Builder(); eb.dstAddr(((ArpPacket) packet.getPayload()).getHeader().getDstHardwareAddr()) .srcAddr(((ArpPacket) packet.getPayload()).getHeader().getSrcHardwareAddr()) .type(EtherType.getInstance((short) llc.length())) .payloadBuilder(new SimpleBuilder(llc)) .paddingAtBuild(true); return eb.build(); }