java.lang.Object
org.newsclub.net.unix.darwin.system.IPUtil
Some IP protocol-related helper methods.
- Author:
- Christian Kohlschütter
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
The ICMP protocol.static final int
The identifier for AF_INET (at least on Darwin).static final int
The length (in bytes) of the "domain" header used in loopback packet systems like UTUN_CONTROL.static final int
The length (in bytes) of an IPv4 header without options. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
checksumICMPheader
(ByteBuffer bb, int start, int end) Computes the checksum for an ICMP header, and overwrites any existing checksum with the correct one.static int
checksumIPv4header
(ByteBuffer bb, int start, int end) Computes the checksum for an IPv4 header, and overwrites any existing checksum with the correct one.static void
putICMPEchoResponse
(ByteBuffer bb, short echoIdentifier, short sequenceNumber, ByteBuffer payload) Put (write) an ICMP echo response header to the given byte buffer, using the given parameters.static void
putIPv4Header
(ByteBuffer bb, int payloadLength, byte protocol, int srcIP, int dstIP) Put (write) an IPv4 header to the given byte buffer, using the given parameters.
-
Field Details
-
DOMAIN_HEADER_LENGTH
public static final int DOMAIN_HEADER_LENGTHThe length (in bytes) of the "domain" header used in loopback packet systems like UTUN_CONTROL.- See Also:
-
DOMAIN_AF_INET
public static final int DOMAIN_AF_INETThe identifier for AF_INET (at least on Darwin).- See Also:
-
IPV4_DEFAULT_HEADER_SIZE
public static final int IPV4_DEFAULT_HEADER_SIZEThe length (in bytes) of an IPv4 header without options.- See Also:
-
AF_INET_PROTOCOL_ICMP
public static final byte AF_INET_PROTOCOL_ICMPThe ICMP protocol.- See Also:
-
-
Method Details
-
checksumIPv4header
Computes the checksum for an IPv4 header, and overwrites any existing checksum with the correct one.- Parameters:
bb
- The buffer containing the IPv4 headerstart
- The beginning position of the header in the buffer.end
- The end position (exclusive) of the header in the buffer.- Returns:
- The computed 16-bit checksum
-
checksumICMPheader
Computes the checksum for an ICMP header, and overwrites any existing checksum with the correct one. Also see RFC 792.- Parameters:
bb
- The buffer containing the ICMP headerstart
- The beginning position of the header in the buffer.end
- The end position (exclusive) of the header in the buffer.- Returns:
- The computed 16-bit checksum
-
putIPv4Header
public static void putIPv4Header(ByteBuffer bb, int payloadLength, byte protocol, int srcIP, int dstIP) Put (write) an IPv4 header to the given byte buffer, using the given parameters. This should write exactly 20 bytes to the buffer. The buffer position then is at the end of the header.- Parameters:
bb
- The target byte buffer.payloadLength
- The length of the payload (excluding the IPv4 header).protocol
- The protocol identifier.srcIP
- The source IPv4 address.dstIP
- The destination IPv4 address.
-
putICMPEchoResponse
public static void putICMPEchoResponse(ByteBuffer bb, short echoIdentifier, short sequenceNumber, ByteBuffer payload) Put (write) an ICMP echo response header to the given byte buffer, using the given parameters.- Parameters:
bb
- The target byte buffer.echoIdentifier
- The identifier, from the ICMP echo request.sequenceNumber
- The sequence number, from the ICMP echo request.payload
- The payload, from the ICMP echo request.
-