java.lang.Object
org.newsclub.net.unix.darwin.system.IPUtil
Some IP protocol-related helper methods.
- Author:
- Christian Kohlschütter
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final byteThe ICMP protocol.static final intThe identifier for AF_INET (at least on Darwin).static final intThe length (in bytes) of the "domain" header used in loopback packet systems like UTUN_CONTROL.static final intThe length (in bytes) of an IPv4 header without options.
- 
Method SummaryModifier and TypeMethodDescriptionstatic intchecksumICMPheader(ByteBuffer bb, int start, int end) Computes the checksum for an ICMP header, and overwrites any existing checksum with the correct one.static intchecksumIPv4header(ByteBuffer bb, int start, int end) Computes the checksum for an IPv4 header, and overwrites any existing checksum with the correct one.static voidputICMPEchoResponse(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 voidputIPv4Header(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_LENGTHpublic 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_INETpublic static final int DOMAIN_AF_INETThe identifier for AF_INET (at least on Darwin).- See Also:
 
- 
IPV4_DEFAULT_HEADER_SIZEpublic static final int IPV4_DEFAULT_HEADER_SIZEThe length (in bytes) of an IPv4 header without options.- See Also:
 
- 
AF_INET_PROTOCOL_ICMPpublic static final byte AF_INET_PROTOCOL_ICMPThe ICMP protocol.- See Also:
 
 
- 
- 
Method Details- 
checksumIPv4headerComputes the checksum for an IPv4 header, and overwrites any existing checksum with the correct one.- Parameters:
- bb- The buffer containing the IPv4 header
- start- 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
 
- 
checksumICMPheaderComputes 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 header
- start- 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
 
- 
putIPv4Headerpublic 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.
 
- 
putICMPEchoResponsepublic 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.
 
 
-