org.jnetpcap.protocol.network
Class Ip4

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JBuffer
          extended by org.jnetpcap.packet.JHeader
              extended by org.jnetpcap.packet.JHeaderMap<Ip4>
                  extended by org.jnetpcap.protocol.network.Ip4
All Implemented Interfaces:
JCompoundHeader<Ip4>, JHeaderChecksum, JPayloadAccessor

@Protocol(suite=NETWORK)
@Header(name="Ip4",
        nicname="Ip",
        osi=NETWORK,
        suite=NETWORK,
        spec="RFC792",
        description="ip version 4")
public class Ip4
extends JHeaderMap<Ip4>
implements JHeaderChecksum

IP version 4. Network layer internet protocol version 4. This is the main header file for Internet Protocol version 4. The header file defines various accessor methods for reading directly out of the Ip4 data structure found within the packet data buffer. The header is peered with the packet at appropriate offset into the buffer and data can be accessed via friendly accessor methods defined by this header, or by using JBuffer accessors. The header also performs decoding of the header, sepecifically decoding and attaching optional sub-headers to this header.

Ip4 header is the backbone of the internet.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class Ip4.AddressExtension
          The Class AddressExtension.
static class Ip4.Encode
          The Class Encode.
static class Ip4.ExperimentalAccessControl
          The Class ExperimentalAccessControl.
static class Ip4.ExperimentalFlowControl
          The Class ExperimentalFlowControl.
static class Ip4.ExperimentalMeasurement
          The Class ExperimentalMeasurement.
static class Ip4.ExtendedIp
          The Class ExtendedIp.
static class Ip4.Flag
          Enum table for Ip4.flags field.
static class Ip4.IMITrafficDescriptor
          The Class IMITrafficDescriptor.
static class Ip4.Ip4Type
          A table of IpTypes and their names.
static class Ip4.IpOption
          Baseclass for all Ip option headers.
static class Ip4.LooseSourceRoute
          Ip4 optional Loose Source Route header.
static class Ip4.MtuProbe
          The Class MtuProbe.
static class Ip4.MtuReply
          The Class MtuReply.
static class Ip4.NoOp
          Ip4 optional No Operation header.
static class Ip4.RecordRoute
          Ip4 optional Record Route header.
static class Ip4.RouterAlert
          The Class RouterAlert.
static class Ip4.Routing
          Ip4 optional Routing header.
static class Ip4.Security
          Ip4 optional Security header.
static class Ip4.SelectiveDirectedBroadcastMode
          The Class SelectiveDirectedBroadcastMode.
static class Ip4.StreamId
          Ip4 optional Stream ID header.
static class Ip4.StrictSourceRoute
          Ip4 optional Strict Source Route header.
static class Ip4.Timestamp
          Ip4 optional Timestamp header.
static class Ip4.Traceroute
          The Class Traceroute.
 
Nested classes/interfaces inherited from class org.jnetpcap.packet.JHeader
JHeader.State
 
Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory
JMemory.Type
 
Field Summary
static int DIFF_CODEPOINT
          The Constant DIFF_CODEPOINT.
static int DIFF_ECE
          The Constant DIFF_ECE.
static int DIFF_ECT
          The Constant DIFF_ECT.
static int FLAG_DONT_FRAGMENT
          The Constant FLAG_DONT_FRAGMENT.
static int FLAG_MORE_FRAGMENTS
          The Constant FLAG_MORE_FRAGMENTS.
static int FLAG_RESERVED
          The Constant FLAG_RESERVED.
static int ID
          The Constant ID.
 
Fields inherited from class org.jnetpcap.packet.JHeaderMap
MAX_HEADERS, optionsBitmap, optionsLength, optionsOffsets, X_HEADERS
 
Fields inherited from class org.jnetpcap.packet.JHeader
annotatedHeader, BYTE, EMPTY_HEADER_ARRAY, isSubHeader, packet, state
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER
 
Constructor Summary
Ip4()
           
 
Method Summary
 int calculateChecksum()
          Calculates a checksum using protocol specification for a header.
 int checksum()
          Retrieves the header's checksum.
 void checksum(int value)
          Checksum.
 java.lang.String checksumDescription()
          Checksum description.
 boolean checkType(int type)
          Check type.
 void clearFlags(int flags)
          Clear flags.
protected  void decodeHeader()
          Decode header.
 byte[] destination()
          Destination.
 void destination(byte[] value)
          Destination.
 byte[] destinationToByteArray(byte[] address)
          Destination to byte array.
 int destinationToInt()
          Converts the 32 bit Ip4 destination address to a java signed 32 bit integer.
 int flags_DF()
          Flags_ df.
 java.lang.String flags_DFDescription()
          Flags_ df description.
 int flags_MF()
          Flags_ mf.
 java.lang.String flags_MFDescription()
          Flags_ mf description.
 int flags_Reserved()
          Flags_ reserved.
 int flags()
          Retrives the flags header field as an unsigned integer, length of 3 bits, that has each Ip4 flag encoded as a bit field.
 void flags(int flags)
          A setter method that changes the flag bits directly in the peered Ip4 header structure within the packet data buffer.
 java.util.Set<Ip4.Flag> flagsEnum()
          Retrieves the flags field as a collection's set of enum constants that represent each flag.
static int getHeaderLength(JBuffer buffer, int offset)
          Gets the header length.
 int hashCode()
          Hash code.
 int hlen()
          Hlen.
 void hlen(int value)
          Hlen.
 java.lang.String hlenDescription()
          Hlen description.
 int id()
          Id.
 void id(int value)
          Id.
 boolean isChecksumValid()
          Checks if the checksum is valid, even for fragmented packets.
 boolean isFragment()
          Checks if this is ip fragment of a larger PDU.
 int length()
          Length.
 void length(int value)
          Length.
 int offset()
          Offset.
 void offset(int offset)
          Offset.
 java.lang.String offsetDescription()
          Offset description.
 byte[] source()
          Converts the 32 bit Ip4 source address to a java signed 32 bit integer.
 void source(byte[] value)
          Source.
 byte[] sourceToByteArray(byte[] address)
          Source to byte array.
 int sourceToInt()
          Source to int.
 int tos_Codepoint()
          Tos_ codepoint.
 java.lang.String tos_CodepointDescription()
          Tos_ codepoint description.
 int tos_ECE()
          Tos_ ece.
 java.lang.String tos_ECEDescription()
          Tos_ ece description.
 int tos_ECN()
          Tos_ ecn.
 java.lang.String tos_ECNDescription()
          Tos_ ecn description.
 int tos()
          Tos.
 void tos(int value)
          Tos.
 int ttl()
          Ttl.
 void ttl(int value)
          Ttl.
 int type()
          Type.
 void type(int value)
          Type.
 void type(Ip4.Ip4Type type)
          Type.
 java.lang.String typeDescription()
          Type description.
 Ip4.Ip4Type typeEnum()
          Type enum.
 int version()
          Version.
 void version(int value)
          Version.
 
Methods inherited from class org.jnetpcap.packet.JHeaderMap
getSubHeader, getSubHeaders, hasSubHeader, hasSubHeader, hasSubHeaders, setSubHeader, setSubHeaders
 
Methods inherited from class org.jnetpcap.packet.JHeader
decode, getAnnotatedHeader, getDescription, getFields, getGap, getGapLength, getGapOffset, getHeader, getHeaderLength, getHeaderOffset, getId, getIndex, getLength, getName, getNextHeaderId, getNextHeaderOffset, getNicname, getOffset, getPacket, getParent, getPayload, getPayloadLength, getPayloadOffset, getPostfix, getPostfixLength, getPostfixOffset, getPrefix, getPrefixLength, getPrefixOffset, getPreviousHeaderId, getPreviousHeaderOffset, getState, hasDescription, hasGap, hasNextHeader, hasPayload, hasPostfix, hasPrefix, hasPreviousHeader, isFragmented, isGapTruncated, isHeaderTruncated, isPayloadTruncated, isPostfixTruncated, isPrefixTruncated, peer, peer, peerPayloadTo, setPacket, sizeof, toString, transferPayloadTo, transferPayloadTo, transferPayloadTo, validateHeader
 
Methods inherited from class org.jnetpcap.nio.JBuffer
findUTF8String, getByte, getByteArray, getByteArray, getByteArray, getDouble, getFloat, getInt, getLong, getShort, getUByte, getUInt, getUShort, getUTF8Char, getUTF8String, getUTF8String, getUTF8String, getUTF8String, isReadonly, order, order, peer, peer, peer, peer, setByte, setByteArray, setByteBuffer, setDouble, setFloat, setInt, setLong, setShort, setShort0, setUByte, setUInt, setUShort, transferFrom, transferFrom, transferFrom, transferTo, transferTo, transferTo
 
Methods inherited from class org.jnetpcap.nio.JMemory
availableDirectMemory, check, cleanup, createReference, isInitialized, isJMemoryBasedOwner, isOwner, maxDirectMemory, peer, reservedDirectMemory, setSize, size, softDirectMemory, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DIFF_CODEPOINT

public static final int DIFF_CODEPOINT
The Constant DIFF_CODEPOINT.

See Also:
Constant Field Values

DIFF_ECE

public static final int DIFF_ECE
The Constant DIFF_ECE.

See Also:
Constant Field Values

DIFF_ECT

public static final int DIFF_ECT
The Constant DIFF_ECT.

See Also:
Constant Field Values

FLAG_DONT_FRAGMENT

public static final int FLAG_DONT_FRAGMENT
The Constant FLAG_DONT_FRAGMENT.

See Also:
Constant Field Values

FLAG_MORE_FRAGMENTS

public static final int FLAG_MORE_FRAGMENTS
The Constant FLAG_MORE_FRAGMENTS.

See Also:
Constant Field Values

FLAG_RESERVED

public static final int FLAG_RESERVED
The Constant FLAG_RESERVED.

See Also:
Constant Field Values

ID

public static final int ID
The Constant ID.

See Also:
Constant Field Values
Constructor Detail

Ip4

public Ip4()
Method Detail

getHeaderLength

@HeaderLength
public static int getHeaderLength(JBuffer buffer,
                                               int offset)
Gets the header length.

Parameters:
buffer - the buffer
offset - the offset
Returns:
the header length

checksumDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String checksumDescription()
Checksum description.

Returns:
the string

checksum

@Field(offset=80,
       length=16,
       format="%x")
public int checksum()
Retrieves the header's checksum.

Specified by:
checksum in interface JHeaderChecksum
Returns:
header's stored checksum

checksum

@FieldSetter
public void checksum(int value)
Checksum.

Parameters:
value - the value

checkType

public boolean checkType(int type)
Check type.

Parameters:
type - the type
Returns:
true, if successful

clearFlags

public void clearFlags(int flags)
Clear flags.

Parameters:
flags - the flags

decodeHeader

protected void decodeHeader()
Decode header.

Overrides:
decodeHeader in class JHeader
See Also:
JHeader.decodeHeader()

destination

@Field(offset=128,
       length=32,
       format="#ip4#")
@FlowKey(index=0)
public byte[] destination()
Destination.

Returns:
the byte[]

destination

@FieldSetter
public void destination(byte[] value)
Destination.

Parameters:
value - the value

destinationToByteArray

public byte[] destinationToByteArray(byte[] address)
Destination to byte array.

Parameters:
address - the address
Returns:
the byte[]

destinationToInt

public int destinationToInt()
Converts the 32 bit Ip4 destination address to a java signed 32 bit integer. The value returned should be treated as an unsigned integer, which java can not represent as an int. If neccessary to printout the value returned, in order to correctly represent the unsinged value, the integer returned should be converted to a java long type and sign appropriately handled to take advantage of the extra length of a java long type.

Returns:
unsinged 32 bit integer representing the Ip4 destination address

flags

@Field(offset=48,
       length=3,
       format="%x")
public int flags()
Retrives the flags header field as an unsigned integer, length of 3 bits, that has each Ip4 flag encoded as a bit field. The first flag is encoded in bit number 0 of the returned usigned integer.

Returns:
3 bits of the flag field as unsigned integer

flagsEnum

public java.util.Set<Ip4.Flag> flagsEnum()
Retrieves the flags field as a collection's set of enum constants that represent each flag. The flags returned are an EnumSet which efficiently encodes the enum constants as an internal bitfield.

Returns:
the sets the

flags

@FieldSetter
public void flags(int flags)
A setter method that changes the flag bits directly in the peered Ip4 header structure within the packet data buffer.

Parameters:
flags - new flags to set

flags_Reserved

@Field(parent="flags",
       offset=2,
       length=1,
       display="reserved")
public int flags_Reserved()
Flags_ reserved.

Returns:
the int

flags_DF

@Field(parent="flags",
       offset=1,
       length=1,
       display="DF: do not fragment")
public int flags_DF()
Flags_ df.

Returns:
the int

flags_DFDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String flags_DFDescription()
Flags_ df description.

Returns:
the string

flags_MF

@Field(parent="flags",
       offset=0,
       length=1,
       display="MF: more fragments",
       nicname="M")
public int flags_MF()
Flags_ mf.

Returns:
the int

flags_MFDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String flags_MFDescription()
Flags_ mf description.

Returns:
the string

hashCode

public int hashCode()
Hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
the int
See Also:
Object.hashCode()

hlen

@Field(offset=4,
       length=4,
       format="%d")
public int hlen()
Hlen.

Returns:
the int

hlen

@FieldSetter
public void hlen(int value)
Hlen.

Parameters:
value - the value

hlenDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String hlenDescription()
Hlen description.

Returns:
the string

id

@Field(offset=32,
       length=16,
       format="%x")
public int id()
Id.

Returns:
the int

id

@FieldSetter
public void id(int value)
Id.

Parameters:
value - the value

isFragment

public boolean isFragment()
Checks if this is ip fragment of a larger PDU. The method checks offset and flags.MF fields to see if there are other fragments, marked by flags and offset, for a larger PDU.

Returns:
true if this is a fragment, otherwise false

length

@Field(offset=16,
       length=16,
       format="%d")
public int length()
Length.

Returns:
the int

length

@FieldSetter
public void length(int value)
Length.

Parameters:
value - the value

offsetDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String offsetDescription()
Offset description.

Returns:
the string

offset

@Field(offset=51,
       length=13,
       format="%d")
public int offset()
Offset.

Returns:
the int

offset

@FieldSetter
public void offset(int offset)
Offset.

Parameters:
offset - the offset

source

@Field(offset=96,
       length=32,
       format="#ip4#")
@FlowKey(index=0)
public byte[] source()
Converts the 32 bit Ip4 source address to a java signed 32 bit integer. The value returned should be treated as an unsigned integer, which java can not represent as an int. If neccessary to printout the value returned, in order to correctly represent the unsinged value, the integer returned should be converted to a java long type and sign appropriately handled to take advantage of the extra length of a java long type.

Returns:
unsinged 32 bit integer representing the Ip4 source address

source

@FieldSetter
public void source(byte[] value)
Source.

Parameters:
value - the value

sourceToByteArray

public byte[] sourceToByteArray(byte[] address)
Source to byte array.

Parameters:
address - the address
Returns:
the byte[]

sourceToInt

public int sourceToInt()
Source to int.

Returns:
the int

tos

@Field(offset=8,
       length=8,
       format="%x",
       display="diffserv")
public int tos()
Tos.

Returns:
the int

tos

@FieldSetter
public void tos(int value)
Tos.

Parameters:
value - the value

tos_Codepoint

@Field(parent="tos",
       offset=2,
       length=6,
       display="code point")
public int tos_Codepoint()
Tos_ codepoint.

Returns:
the int

tos_CodepointDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String tos_CodepointDescription()
Tos_ codepoint description.

Returns:
the string

tos_ECE

@Field(parent="tos",
       offset=0,
       length=1,
       display="ECE bit")
public int tos_ECE()
Tos_ ece.

Returns:
the int

tos_ECEDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String tos_ECEDescription()
Tos_ ece description.

Returns:
the string

tos_ECN

@Field(parent="tos",
       offset=1,
       length=1,
       display="ECN bit")
public int tos_ECN()
Tos_ ecn.

Returns:
the int

tos_ECNDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String tos_ECNDescription()
Tos_ ecn description.

Returns:
the string

ttl

@Field(offset=64,
       length=8,
       format="%d",
       description="time to live")
public int ttl()
Ttl.

Returns:
the int

ttl

@FieldSetter
public void ttl(int value)
Ttl.

Parameters:
value - the value

type

@Field(offset=72,
       length=8,
       format="%d")
@FlowKey(index=1)
public int type()
Type.

Returns:
the int

type

@FieldSetter
public void type(int value)
Type.

Parameters:
value - the value

type

public void type(Ip4.Ip4Type type)
Type.

Parameters:
type - the type

typeDescription

@Dynamic(value=DESCRIPTION)
public java.lang.String typeDescription()
Type description.

Returns:
the string

typeEnum

public Ip4.Ip4Type typeEnum()
Type enum.

Returns:
the ip4 type

version

@Field(offset=0,
       length=4,
       format="%d")
public int version()
Version.

Returns:
the int

version

@FieldSetter
public void version(int value)
Version.

Parameters:
value - the value

calculateChecksum

public int calculateChecksum()
Calculates a checksum using protocol specification for a header. Checksums for partial headers or fragmented packets (unless the protocol alows it) are not calculated.

Specified by:
calculateChecksum in interface JHeaderChecksum
Returns:
header's calculated checksum

isChecksumValid

public boolean isChecksumValid()
Checks if the checksum is valid, even for fragmented packets.

Specified by:
isChecksumValid in interface JHeaderChecksum
Returns:
true if checksum checks out, otherwise if the computed checksum does not match the stored checksum false is returned