private UnknownIpV6NeighborDiscoveryOption(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < 2) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be more than 1. rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.type = IpV6NeighborDiscoveryOptionType.getInstance(rawData[offset]); this.length = rawData[1 + offset]; if (length < this.length * 8) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data is too short to build this option(") .append(this.length * 8) .append("). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.data = ByteArrays.getSubArray(rawData, 2 + offset, this.length * 8 - 2); }
private TcpSackOption(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < 2) { StringBuilder sb = new StringBuilder(50); sb.append("The raw data length must be more than 1. rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } if (rawData[offset] != kind.value()) { StringBuilder sb = new StringBuilder(100); sb.append("The kind must be: ") .append(kind.valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.length = rawData[1 + offset]; int lengthFieldAsInt = getLengthAsInt(); if (lengthFieldAsInt < 2) { throw new IllegalRawDataException( "The value of length field must be more than 1 but: " + lengthFieldAsInt); } if ((lengthFieldAsInt - 2) % (INT_SIZE_IN_BYTES * 2) != 0) { StringBuilder sb = new StringBuilder(100); sb.append("The value of length field must be an integer multiple of 8 octets long but: ") .append(lengthFieldAsInt); throw new IllegalRawDataException(sb.toString()); } if (length < lengthFieldAsInt) { StringBuilder sb = new StringBuilder(100); sb.append("rawData is too short. length field: ") .append(lengthFieldAsInt) .append(", rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } for (int i = 2; i < lengthFieldAsInt; i += INT_SIZE_IN_BYTES * 2) { sacks.add( new Sack( ByteArrays.getInt(rawData, i + offset), ByteArrays.getInt(rawData, i + INT_SIZE_IN_BYTES + offset))); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Type: ") .append(type) .append("] [Length: ") .append(getLengthAsInt()) .append(" bytes] [Data: 0x") .append(ByteArrays.toHexString(data, "")) .append("]"); return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Option Type: ") .append(type) .append("] [Illegal Raw Data: 0x") .append(ByteArrays.toHexString(rawData, "")) .append("] [cause: ") .append(cause) .append("]"); return sb.toString(); }
private RadiotapDataRate(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < LENGTH) { StringBuilder sb = new StringBuilder(200); sb.append("The data is too short to build a RadiotapRate (") .append(LENGTH) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.rate = ByteArrays.getByte(rawData, offset); }
private IcmpV6NeighborAdvertisementHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < OPTIONS_OFFSET) { StringBuilder sb = new StringBuilder(120); sb.append("The raw data must be more than ") .append(OPTIONS_OFFSET - 1) .append("bytes") .append(" to build this header. raw data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } int tmp = ByteArrays.getInt(rawData, R_S_O_RESERVED_OFFSET + offset); this.routerFlag = (tmp & 0x80000000) != 0; this.solicitedFlag = (tmp & 0x40000000) != 0; this.overrideFlag = (tmp & 0x20000000) != 0; this.reserved = 0x1FFFFFFF & tmp; this.targetAddress = ByteArrays.getInet6Address(rawData, TARGET_ADDRESS_OFFSET + offset); this.options = new ArrayList<IpV6NeighborDiscoveryOption>(); int currentOffsetInHeader = OPTIONS_OFFSET; while (currentOffsetInHeader < length) { IpV6NeighborDiscoveryOptionType type = IpV6NeighborDiscoveryOptionType.getInstance(rawData[currentOffsetInHeader + offset]); IpV6NeighborDiscoveryOption newOne; try { newOne = PacketFactories.getFactory( IpV6NeighborDiscoveryOption.class, IpV6NeighborDiscoveryOptionType.class) .newInstance( rawData, currentOffsetInHeader + offset, length - currentOffsetInHeader, type); } catch (Exception e) { break; } options.add(newOne); currentOffsetInHeader += newOne.length(); } }
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 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)); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[illegal data: ").append(ByteArrays.toHexString(rawData, "")).append("]"); return sb.toString(); }