@Test public void testToIPv4AddressBytes() { byte[] expected = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("255.255.255.255")); expected = new byte[] {(byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80}; Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("128.128.128.128")); expected = new byte[] {0x7f,0x7f,0x7f,0x7f}; Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("127.127.127.127")); }
public static byte[] toIPv4AddressBytes(String ipAddress) { String[] octets = ipAddress.split("\\."); if (octets.length != 4) throw new IllegalArgumentException("Specified IPv4 address must" + "contain 4 sets of numerical digits separated by periods"); byte[] result = new byte[4]; for (int i = 0; i < 4; ++i) { result[i] = Integer.valueOf(octets[i]).byteValue(); } return result; }
IPv4 extends BasePacket { public static byte[] toIPv4AddressBytes(String ipAddress) { String[] octets = ipAddress.split("\\."); if (octets.length != 4) throw new IllegalArgumentException("Specified IPv4 address must" + "contain 4 sets of numerical digits separated by periods"); byte[] result = new byte[4]; for (int i = 0; i < 4; ++i) { result[i] = Integer.valueOf(octets[i]).byteValue(); } return result; } }
IPv4 extends BasePacket { public static byte[] toIPv4AddressBytes(String ipAddress) { String[] octets = ipAddress.split("\\."); if (octets.length != 4) throw new IllegalArgumentException("Specified IPv4 address must" + "contain 4 sets of numerical digits separated by periods"); byte[] result = new byte[4]; for (int i = 0; i < 4; ++i) { result[i] = Integer.valueOf(octets[i]).byteValue(); } return result; } IPv4(); }
IPv4 extends BasePacket { public static byte[] toIPv4AddressBytes(String ipAddress) { String[] octets = ipAddress.split("\\."); if (octets.length != 4) throw new IllegalArgumentException("Specified IPv4 address must" + "contain 4 sets of numerical digits separated by periods"); byte[] result = new byte[4]; for (int i = 0; i < 4; ++i) { result[i] = Integer.valueOf(octets[i]).byteValue(); } return result; } IPv4(); byte getVersion(); IPv4 setVersion(byte version); byte getHeaderLength(); byte getDiffServ(); IPv4 setDiffServ(byte diffServ); short getTotalLength(); short getIdentification(); boolean isTruncated(); void setTruncated(boolean isTruncated); boolean isFragment(); void setFragment(boolean isFrag); IPv4 setIdentification(short identification); byte getFlags(); IPv4 setFlags(byte flags); short getFragmentOffset(); IPv4 setFragmentOffset(short fragmentOffset); byte getTtl(); IPv4 setTtl(byte ttl); byte getProtocol(); IPv4 setProtocol(byte protocol); short getChecksum(); IPv4 setChecksum(short checksum); @Override void resetChecksum(); int getSourceAddress(); IPv4 setSourceAddress(int sourceAddress); IPv4 setSourceAddress(String sourceAddress); int getDestinationAddress(); IPv4 setDestinationAddress(int destinationAddress); IPv4 setDestinationAddress(String destinationAddress); byte[] getOptions(); IPv4 setOptions(byte[] options); @Override byte[] serialize(); @Override IPacket deserialize(byte[] data, int offset, int length); static int toIPv4Address(String ipAddress); static int toIPv4Address(byte[] ipAddress); static String fromIPv4Address(int ipAddress); static String fromIPv4AddressCollection(Collection<Integer> ipAddresses); static byte[] toIPv4AddressBytes(String ipAddress); static byte[] toIPv4AddressBytes(int ipAddress); @Override int hashCode(); @Override boolean equals(Object obj); }
IPv4 extends BasePacket { public static byte[] toIPv4AddressBytes(String ipAddress) { String[] octets = ipAddress.split("\\."); if (octets.length != 4) throw new IllegalArgumentException("Specified IPv4 address must" + "contain 4 sets of numerical digits separated by periods"); byte[] result = new byte[4]; for (int i = 0; i < 4; ++i) { result[i] = Integer.valueOf(octets[i]).byteValue(); } return result; } IPv4(); byte getVersion(); IPv4 setVersion(byte version); byte getHeaderLength(); byte getDiffServ(); IPv4 setDiffServ(byte diffServ); short getTotalLength(); short getIdentification(); boolean isTruncated(); void setTruncated(boolean isTruncated); boolean isFragment(); void setFragment(boolean isFrag); IPv4 setIdentification(short identification); byte getFlags(); IPv4 setFlags(byte flags); short getFragmentOffset(); IPv4 setFragmentOffset(short fragmentOffset); byte getTtl(); IPv4 setTtl(byte ttl); byte getProtocol(); IPv4 setProtocol(byte protocol); short getChecksum(); IPv4 setChecksum(short checksum); @Override void resetChecksum(); int getSourceAddress(); IPv4 setSourceAddress(int sourceAddress); IPv4 setSourceAddress(String sourceAddress); int getDestinationAddress(); IPv4 setDestinationAddress(int destinationAddress); IPv4 setDestinationAddress(String destinationAddress); byte[] getOptions(); IPv4 setOptions(byte[] options); @Override byte[] serialize(); @Override IPacket deserialize(byte[] data, int offset, int length); static int toIPv4Address(String ipAddress); static int toIPv4Address(byte[] ipAddress); static String fromIPv4Address(int ipAddress); static String fromIPv4AddressCollection(Collection<Integer> ipAddresses); static byte[] toIPv4AddressBytes(String ipAddress); static byte[] toIPv4AddressBytes(int ipAddress); @Override int hashCode(); @Override boolean equals(Object obj); static final byte PROTOCOL_ICMP; static final byte PROTOCOL_TCP; static final byte PROTOCOL_UDP; static Map<Byte, Class<? extends IPacket>> protocolClassMap; static final byte IPV4_FLAGS_MOREFRAG; static final byte IPV4_FLAGS_DONTFRAG; static final byte IPV4_FLAGS_MASK; static final byte IPV4_FLAGS_SHIFT; static final short IPV4_OFFSET_MASK; }