@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } IcmpV4CommonHeader other = (IcmpV4CommonHeader) obj; return checksum == other.checksum && type.equals(other.type) && code.equals(other.code); }
private IcmpV4CommonHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ICMPV4_COMMON_HEADER_SIZE) { StringBuilder sb = new StringBuilder(80); sb.append("The data is too short to build an ICMPv4 common header(") .append(ICMPV4_COMMON_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.type = IcmpV4Type.getInstance(ByteArrays.getByte(rawData, TYPE_OFFSET + offset)); this.code = IcmpV4Code.getInstance(type.value(), ByteArrays.getByte(rawData, CODE_OFFSET + offset)); this.checksum = ByteArrays.getShort(rawData, CHECKSUM_OFFSET + offset); }
/** * @param value value * @return a IcmpV4Type object. */ public static IcmpV4Type getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IcmpV4Type(value, "unknown"); } }
type = IcmpV4Type.getInstance(Byte.parseByte(strType)); } catch (NumberFormatException e) { throw new IllegalArgumentException("args[1]: " + strType, e); if (!type.equals(IcmpV4Type.DESTINATION_UNREACHABLE) && !type.equals(IcmpV4Type.TIME_EXCEEDED) && !type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { throw new IllegalArgumentException("args[1]: " + strType); code = IcmpV4Code.getInstance(type.value(), Byte.parseByte(strCode)); } catch (NumberFormatException e) { throw new IllegalArgumentException("args[1]: " + strType, e); if (type.equals(IcmpV4Type.DESTINATION_UNREACHABLE)) { tmp = new IcmpV4DestinationUnreachablePacket.Builder(); } else if (type.equals(IcmpV4Type.TIME_EXCEEDED)) { tmp = new IcmpV4TimeExceededPacket.Builder(); } else if (type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { tmp = new IcmpV4ParameterProblemPacket.Builder(); } else {
/** * @param type type * @return a IcmpV4Type object. */ public static IcmpV4Type register(IcmpV4Type type) { return registry.put(type.value(), type); }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + code.hashCode(); result = 31 * result + checksum; return result; } }
type = IcmpV4Type.getInstance(Byte.parseByte(strType)); } catch (NumberFormatException e) { throw new IllegalArgumentException("args[1]: " + strType, e); if (!type.equals(IcmpV4Type.DESTINATION_UNREACHABLE) && !type.equals(IcmpV4Type.TIME_EXCEEDED) && !type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { throw new IllegalArgumentException("args[1]: " + strType); code = IcmpV4Code.getInstance(type.value(), Byte.parseByte(strCode)); } catch (NumberFormatException e) { throw new IllegalArgumentException("args[1]: " + strType, e); if (type.equals(IcmpV4Type.DESTINATION_UNREACHABLE)) { tmp = new IcmpV4DestinationUnreachablePacket.Builder(); } else if (type.equals(IcmpV4Type.TIME_EXCEEDED)) { tmp = new IcmpV4TimeExceededPacket.Builder(); } else if (type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { tmp = new IcmpV4ParameterProblemPacket.Builder(); } else {
@Override public String valueAsString() { return String.valueOf(value() & 0xFF); }
@Override protected int calcHashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + code.hashCode(); result = 31 * result + checksum; return result; } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } IcmpV4CommonHeader other = (IcmpV4CommonHeader) obj; return checksum == other.checksum && type.equals(other.type) && code.equals(other.code); }
private IcmpV4CommonHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < ICMPV4_COMMON_HEADER_SIZE) { StringBuilder sb = new StringBuilder(80); sb.append("The data is too short to build an ICMPv4 common header(") .append(ICMPV4_COMMON_HEADER_SIZE) .append(" bytes). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.type = IcmpV4Type.getInstance(ByteArrays.getByte(rawData, TYPE_OFFSET + offset)); this.code = IcmpV4Code.getInstance(type.value(), ByteArrays.getByte(rawData, CODE_OFFSET + offset)); this.checksum = ByteArrays.getShort(rawData, CHECKSUM_OFFSET + offset); }
/** * @param value value * @return a IcmpV4Type object. */ public static IcmpV4Type getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IcmpV4Type(value, "unknown"); } }
public void gotPacket(Packet packet) { if (packet.contains(IcmpV4EchoPacket.class)) { if (type.equals(IcmpV4Type.DESTINATION_UNREACHABLE)) { ((IcmpV4DestinationUnreachablePacket.Builder) icmpV4errb) .payload( IcmpV4Helper.makePacketForInvokingPacketField( packet.get(IpV4Packet.class))); } else if (type.equals(IcmpV4Type.TIME_EXCEEDED)) { ((IcmpV4TimeExceededPacket.Builder) icmpV4errb) .payload( IcmpV4Helper.makePacketForInvokingPacketField( packet.get(IpV4Packet.class))); } else if (type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { ((IcmpV4ParameterProblemPacket.Builder) icmpV4errb) .payload(
/** * @param type type * @param code code * @return a IcmpV4Code object. */ public static IcmpV4Code register(IcmpV4Type type, IcmpV4Code code) { if (registry.containsKey(type.value())) { return registry.get(type.value()).put(code.value(), code); } else { Map<Byte, IcmpV4Code> map = new HashMap<Byte, IcmpV4Code>(); map.put(code.value(), code); registry.put(type.value(), map); return null; } }
private List<byte[]> getRawFields(boolean zeroInsteadOfChecksum) { List<byte[]> rawFields = new ArrayList<byte[]>(); rawFields.add(ByteArrays.toByteArray(type.value())); rawFields.add(ByteArrays.toByteArray(code.value())); rawFields.add(ByteArrays.toByteArray(zeroInsteadOfChecksum ? (short) 0 : checksum)); return rawFields; }
public void gotPacket(Packet packet) { if (packet.contains(IcmpV4EchoPacket.class)) { if (type.equals(IcmpV4Type.DESTINATION_UNREACHABLE)) { ((IcmpV4DestinationUnreachablePacket.Builder) icmpV4errb) .payload( IcmpV4Helper.makePacketForInvokingPacketField( packet.get(IpV4Packet.class))); } else if (type.equals(IcmpV4Type.TIME_EXCEEDED)) { ((IcmpV4TimeExceededPacket.Builder) icmpV4errb) .payload( IcmpV4Helper.makePacketForInvokingPacketField( packet.get(IpV4Packet.class))); } else if (type.equals(IcmpV4Type.PARAMETER_PROBLEM)) { ((IcmpV4ParameterProblemPacket.Builder) icmpV4errb) .payload(
/** * @param type type * @return a IcmpV4Type object. */ public static IcmpV4Type register(IcmpV4Type type) { return registry.put(type.value(), type); }
@Override public String valueAsString() { return String.valueOf(value() & 0xFF); }