/** * @param array array * @param offset offset * @return a new Inet4Address object. */ public static Inet4Address getInet4Address(byte[] array, int offset) { return getInet4Address(array, offset, ByteOrder.BIG_ENDIAN); }
static Inet4Address itoInetAddress(int i) { return ByteArrays.getInet4Address( ByteArrays.toByteArray(i, NativeMappings.NATIVE_BYTE_ORDER), 0); }
private IcmpV4RedirectHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ICMPV4_REDIRECT_HEADER_SIZE) { StringBuilder sb = new StringBuilder(80); sb.append("The data is too short to build an ICMPv4 Redirect Header(") .append(ICMPV4_REDIRECT_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.gatewayInternetAddress = ByteArrays.getInet4Address(rawData, GATEWAY_INTERNET_ADDRESS_OFFSET + offset); }
private IpV4InternetTimestampOptionAddressPrespecified(byte[] rawData, int offset, int length) throws IllegalRawDataException { if ((length % INT_SIZE_IN_BYTES) != 0) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be an integer multiple of 4 octets long." + " rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.address = ByteArrays.getInet4Address(rawData, 0 + offset); this.timestamps = new ArrayList<Integer>(); for (int i = INT_SIZE_IN_BYTES; i < length; i += INT_SIZE_IN_BYTES) { timestamps.add(ByteArrays.getInt(rawData, i + offset)); } }
private IpV4InternetTimestampOptionTimestampsWithAddresses(byte[] rawData, int offset, int length) throws IllegalRawDataException { if ((length % INT_SIZE_IN_BYTES) != 0) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be an integer multiple of 4 octets long." + " rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.timestampsWithAddresses = new ArrayList<TimestampWithAddress>(); for (int i = 0; i < length; i += INT_SIZE_IN_BYTES * 2) { Inet4Address address = ByteArrays.getInet4Address(rawData, i + offset); Integer timestamp = null; if (i + INT_SIZE_IN_BYTES < length) { timestamp = ByteArrays.getInt(rawData, i + INT_SIZE_IN_BYTES + offset); } timestampsWithAddresses.add(new TimestampWithAddress(address, timestamp)); } }
private DnsRDataWks(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < INET4_ADDRESS_SIZE_IN_BYTES + BYTE_SIZE_IN_BYTES) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build a DnsRDataWks (") .append(INET4_ADDRESS_SIZE_IN_BYTES + BYTE_SIZE_IN_BYTES) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } int cursor = 0; this.address = ByteArrays.getInet4Address(rawData, offset); cursor += INET4_ADDRESS_SIZE_IN_BYTES; this.protocol = IpNumber.getInstance(ByteArrays.getByte(rawData, offset + cursor)); cursor += BYTE_SIZE_IN_BYTES; if (cursor < length) { this.bitMap = ByteArrays.getSubArray(rawData, offset + cursor, length - cursor); } else { this.bitMap = new byte[0]; } if (bitMap.length > 8192) { throw new IllegalRawDataException( "Length of bitMap must be less than 8193. bitMap.length: " + bitMap.length); } this.portNumbers = toPortNumbers(bitMap); }
this.address = ByteArrays.getInet4Address(rawData, offset); this.addressPlainText = false; } else {
routeData.add(ByteArrays.getInet4Address(rawData, i + 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); }
this.protocol = IpNumber.getInstance(ByteArrays.getByte(rawData, PROTOCOL_OFFSET + offset)); this.headerChecksum = ByteArrays.getShort(rawData, HEADER_CHECKSUM_OFFSET + offset); this.srcAddr = ByteArrays.getInet4Address(rawData, SRC_ADDR_OFFSET + offset); this.dstAddr = ByteArrays.getInet4Address(rawData, DST_ADDR_OFFSET + offset);
/** * @param array array * @param offset offset * @return a new Inet4Address object. */ public static Inet4Address getInet4Address(byte[] array, int offset) { return getInet4Address(array, offset, ByteOrder.BIG_ENDIAN); }
static Inet4Address itoInetAddress(int i) { return ByteArrays.getInet4Address( ByteArrays.toByteArray(i, NativeMappings.NATIVE_BYTE_ORDER), 0); }
private IcmpV4RedirectHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ICMPV4_REDIRECT_HEADER_SIZE) { StringBuilder sb = new StringBuilder(80); sb.append("The data is too short to build an ICMPv4 Redirect Header(") .append(ICMPV4_REDIRECT_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.gatewayInternetAddress = ByteArrays.getInet4Address(rawData, GATEWAY_INTERNET_ADDRESS_OFFSET + offset); }
private IpV4InternetTimestampOptionAddressPrespecified(byte[] rawData, int offset, int length) throws IllegalRawDataException { if ((length % INT_SIZE_IN_BYTES) != 0) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be an integer multiple of 4 octets long." + " rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.address = ByteArrays.getInet4Address(rawData, 0 + offset); this.timestamps = new ArrayList<Integer>(); for (int i = INT_SIZE_IN_BYTES; i < length; i += INT_SIZE_IN_BYTES) { timestamps.add(ByteArrays.getInt(rawData, i + offset)); } }
private IpV4InternetTimestampOptionTimestampsWithAddresses(byte[] rawData, int offset, int length) throws IllegalRawDataException { if ((length % INT_SIZE_IN_BYTES) != 0) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be an integer multiple of 4 octets long." + " rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.timestampsWithAddresses = new ArrayList<TimestampWithAddress>(); for (int i = 0; i < length; i += INT_SIZE_IN_BYTES * 2) { Inet4Address address = ByteArrays.getInet4Address(rawData, i + offset); Integer timestamp = null; if (i + INT_SIZE_IN_BYTES < length) { timestamp = ByteArrays.getInt(rawData, i + INT_SIZE_IN_BYTES + offset); } timestampsWithAddresses.add(new TimestampWithAddress(address, timestamp)); } }
this.address = ByteArrays.getInet4Address(rawData, offset); this.addressPlainText = false; } else {
private DnsRDataWks(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < INET4_ADDRESS_SIZE_IN_BYTES + BYTE_SIZE_IN_BYTES) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build a DnsRDataWks (") .append(INET4_ADDRESS_SIZE_IN_BYTES + BYTE_SIZE_IN_BYTES) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } int cursor = 0; this.address = ByteArrays.getInet4Address(rawData, offset); cursor += INET4_ADDRESS_SIZE_IN_BYTES; this.protocol = IpNumber.getInstance(ByteArrays.getByte(rawData, offset + cursor)); cursor += BYTE_SIZE_IN_BYTES; if (cursor < length) { this.bitMap = ByteArrays.getSubArray(rawData, offset + cursor, length - cursor); } else { this.bitMap = new byte[0]; } if (bitMap.length > 8192) { throw new IllegalRawDataException( "Length of bitMap must be less than 8193. bitMap.length: " + bitMap.length); } this.portNumbers = toPortNumbers(bitMap); }
routeData.add(ByteArrays.getInet4Address(rawData, i + 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); }
this.protocol = IpNumber.getInstance(ByteArrays.getByte(rawData, PROTOCOL_OFFSET + offset)); this.headerChecksum = ByteArrays.getShort(rawData, HEADER_CHECKSUM_OFFSET + offset); this.srcAddr = ByteArrays.getInet4Address(rawData, SRC_ADDR_OFFSET + offset); this.dstAddr = ByteArrays.getInet4Address(rawData, DST_ADDR_OFFSET + offset);