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:
JByteBuffer, JCompoundHeader<Ip4>, JPayloadAccessor

@Protocol(suite=NETWORK,
          analyzers={Ip4Sequencer.class,Ip4Assembler.class})
@Header(name="Ip4",
        nicname="Ip",
        osi=NETWORK,
        suite=NETWORK,
        spec="RFC792",
        description="ip version 4")
public class Ip4
extends JHeaderMap<Ip4>

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.Flag
          Enum table for Ip4.flags field.
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.NoOp
          Ip4 optional No Operation header.
static class Ip4.RecordRoute
          Ip4 optional Record Route header
static class Ip4.Routing
          Ip4 optional Routing header
static class Ip4.Security
          Ip4 optional Security header.
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
 
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
           
static int DIFF_ECE
           
static int DIFF_ECT
           
static int FLAG_DONT_FRAGMENT
           
static int FLAG_MORE_FRAGMENTS
           
static int FLAG_RESERVED
           
static int 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, EMPTY_HEADER_ARRAY, isSubHeader, packet, state
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME
 
Constructor Summary
Ip4()
           
 
Method Summary
static boolean bindToEthernet(JPacket packet, Ethernet eth)
           
static boolean bindToSnap(JPacket packet, IEEESnap snap)
           
 int checksum()
           
 void checksum(int value)
           
 boolean checkType(int type)
           
 void clearFlags(int flags)
           
protected  void decodeHeader()
          Allows a header to decode its complex fields
 byte[] destination()
           
 void destination(byte[] value)
           
 byte[] destinationToByteArray(byte[] address)
           
 int destinationToInt()
          Converts the 32 bit Ip4 destination address to a java signed 32 bit integer.
 int flags_DF()
           
 java.lang.String flags_DFDescription()
           
 int flags_MF()
           
 java.lang.String flags_MFDescription()
           
 int 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)
           
 int hashCode()
           
 int hlen()
           
 void hlen(int value)
           
 java.lang.String hlenDescription()
           
 int id()
           
 void id(int value)
           
 boolean isFragment()
          Checks if this is ip fragment of a larger PDU.
 boolean isReassembled()
          Checks if this packet has been reassembled from other IP fragments.
 int length()
           
 void length(int value)
           
 int offset()
           
 void offset(int offset)
           
 java.lang.String offsetDescription()
           
 byte[] source()
          Converts the 32 bit Ip4 source address to a java signed 32 bit integer.
 void source(byte[] value)
           
 byte[] sourceToByteArray(byte[] address)
           
 int sourceToInt()
           
 int tos_Codepoint()
           
 java.lang.String tos_CodepointDescription()
           
 int tos_ECE()
           
 java.lang.String tos_ECEDescription()
           
 int tos_ECN()
           
 java.lang.String tos_ECNDescription()
           
 int tos()
           
 void tos(int value)
           
 int ttl()
           
 void ttl(int value)
           
 int type()
           
 void type(int value)
           
 void type(Ip4.Ip4Type type)
           
 java.lang.String typeDescription()
           
 Ip4.Ip4Type typeEnum()
           
 int version()
           
 void version(int value)
           
 
Methods inherited from class org.jnetpcap.packet.JHeaderMap
getSubHeader, getSubHeaders, hasSubHeader, hasSubHeader, hasSubHeaders, setSubHeader, setSubHeaders
 
Methods inherited from class org.jnetpcap.packet.JHeader
addAnalysis, decode, getAnalysis, getAnalysisIterable, getAnnotatedHeader, getDescription, getFields, getId, getLength, getName, getNicname, getOffset, getPacket, getParent, getPayload, getState, getType, hasAnalysis, hasAnalysis, hasAnalysis, hasDescription, peer, peer, peerPayloadTo, setPacket, sizeof, toString, transferPayloadTo, transferPayloadTo, transferPayloadTo, validateHeader
 
Methods inherited from class org.jnetpcap.nio.JBuffer
findUTF8String, getByte, 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, setUByte, setUInt, setUShort, transferFrom, transferFrom, transferFrom, transferTo, transferTo, transferTo
 
Methods inherited from class org.jnetpcap.nio.JMemory
check, cleanup, finalize, isInitialized, isJMemoryBasedOwner, isOwner, peer, setSize, size, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jnetpcap.nio.JByteBuffer
size
 

Field Detail

DIFF_CODEPOINT

public static final int DIFF_CODEPOINT
See Also:
Constant Field Values

DIFF_ECE

public static final int DIFF_ECE
See Also:
Constant Field Values

DIFF_ECT

public static final int DIFF_ECT
See Also:
Constant Field Values

FLAG_DONT_FRAGMENT

public static final int FLAG_DONT_FRAGMENT
See Also:
Constant Field Values

FLAG_MORE_FRAGMENTS

public static final int FLAG_MORE_FRAGMENTS
See Also:
Constant Field Values

FLAG_RESERVED

public static final int FLAG_RESERVED
See Also:
Constant Field Values

ID

public static final int ID
See Also:
Constant Field Values
Constructor Detail

Ip4

public Ip4()
Method Detail

bindToEthernet

@Bind(to=Ethernet.class)
public static boolean bindToEthernet(JPacket packet,
                                                          Ethernet eth)

bindToSnap

@Bind(to=IEEESnap.class)
public static boolean bindToSnap(JPacket packet,
                                                      IEEESnap snap)

getHeaderLength

@HeaderLength
public static int getHeaderLength(JBuffer buffer,
                                               int offset)

checksum

@Field(offset=80,
       length=16,
       format="%x")
public int checksum()

checksum

@FieldSetter
public void checksum(int value)

checkType

public boolean checkType(int type)

clearFlags

public void clearFlags(int flags)

decodeHeader

protected void decodeHeader()
Description copied from class: JHeader
Allows a header to decode its complex fields

Overrides:
decodeHeader in class JHeader

destination

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

destination

@FieldSetter
public void destination(byte[] value)

destinationToByteArray

public byte[] destinationToByteArray(byte[] address)

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:

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_DF

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

flags_DFDescription

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

flags_MF

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

flags_MFDescription

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

hlen

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

hlen

@FieldSetter
public void hlen(int value)

hlenDescription

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

id

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

id

@FieldSetter
public void id(int 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

isReassembled

public boolean isReassembled()
Checks if this packet has been reassembled from other IP fragments. This check only works, if the PDU has been analyzed and reassembled by Ip4Assembler.

Returns:
true if this PDU is reassembled, otherwise false if atomic

length

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

length

@FieldSetter
public void length(int value)

offsetDescription

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

offset

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

offset

@FieldSetter
public void offset(int 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)

sourceToByteArray

public byte[] sourceToByteArray(byte[] address)

sourceToInt

public int sourceToInt()

tos

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

tos

@FieldSetter
public void tos(int value)

tos_Codepoint

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

tos_CodepointDescription

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

tos_ECE

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

tos_ECEDescription

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

tos_ECN

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

tos_ECNDescription

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

ttl

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

ttl

@FieldSetter
public void ttl(int value)

type

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

type

@FieldSetter
public void type(int value)

type

public void type(Ip4.Ip4Type type)

typeDescription

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

typeEnum

public Ip4.Ip4Type typeEnum()

version

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

version

@FieldSetter
public void version(int value)