net.sourceforge.jpcap.net
Class IPPacket

java.lang.Object
  extended bynet.sourceforge.jpcap.net.Packet
      extended bynet.sourceforge.jpcap.net.EthernetPacket
          extended bynet.sourceforge.jpcap.net.IPPacket
All Implemented Interfaces:
EthernetFields, IPFields, java.io.Serializable
Direct Known Subclasses:
ICMPPacket, IGMPPacket, TCPPacket, UDPPacket

public class IPPacket
extends EthernetPacket
implements IPFields, java.io.Serializable

An IP protocol packet.

Extends an ethernet packet, adding IP header information and an IP data payload.

See Also:
Serialized Form

Nested Class Summary
 class IPPacket.TestProbe
          This inner class provides access to private methods for unit testing.
 
Field Summary
protected  int _ipOffset
           
 
Fields inherited from class net.sourceforge.jpcap.net.EthernetPacket
_bytes, _ethOffset
 
Fields inherited from interface net.sourceforge.jpcap.net.IPFields
IP_CODE_LEN, IP_CODE_POS, IP_CSUM_LEN, IP_CSUM_POS, IP_DST_POS, IP_FRAG_LEN, IP_FRAG_POS, IP_HEADER_LEN, IP_ID_LEN, IP_ID_POS, IP_LEN_LEN, IP_LEN_POS, IP_SRC_POS, IP_TOS_LEN, IP_TOS_POS, IP_TTL_LEN, IP_TTL_POS, IP_VER_LEN, IP_VER_POS
 
Fields inherited from interface net.sourceforge.jpcap.net.EthernetFields
ETH_CODE_LEN, ETH_CODE_POS, ETH_DST_POS, ETH_HEADER_LEN, ETH_SRC_POS
 
Constructor Summary
IPPacket(int lLen, byte[] bytes)
          Create a new IP packet.
 
Method Summary
protected  int computeReceiverChecksum(int start, int len)
           
protected  int computeReceiverIPChecksum()
           
protected  int computeSenderChecksum(int start, int len, int csumPos)
           
protected  int computeSenderIPChecksum()
           
 int getChecksum()
          Fetch the header checksum.
 java.lang.String getColor()
          Fetch ascii escape sequence of the color associated with this packet type.
 byte[] getData()
          Fetch the IP data as a byte array.
 java.lang.String getDestinationAddress()
          Fetch the IP address of the host where the packet is destined.
 long getDestinationAddressAsLong()
          Fetch the destination address as a long.
 byte[] getDestinationAddressBytes()
          Fetch the destination address as a byte array.
 int getFragmentFlags()
          Fetch fragmentation flags.
 int getFragmentOffset()
          Fetch fragmentation offset.
 byte[] getHeader()
          Fetch the IP header as a byte array.
 int getHeaderLength()
          Fetch the packet IP header length.
 int getId()
          Fetch the unique ID of this IP datagram.
 int getIPChecksum()
          Fetch the header checksum.
 byte[] getIPData()
          Fetch the IP data as a byte array.
 byte[] getIPHeader()
          Fetch the IP header a byte array.
 int getIpHeaderLength()
          Fetch the IP header length in bytes.
 int getIPHeaderLength()
          Fetch the IP header length in bytes.
 int getIPProtocol()
          Fetch the code indicating the type of protocol embedded in the IP datagram.
 int getLength()
          Fetch the IP length in bytes.
 int getProtocol()
          Fetch the code indicating the type of protocol embedded in the IP datagram.
 java.lang.String getSourceAddress()
          Fetch the IP address of the host where the packet originated from.
 long getSourceAddressAsLong()
          Fetch the source address as a long.
 byte[] getSourceAddressBytes()
          Fetch the source address as a byte array.
 int getTimeToLive()
          Fetch the time to live.
 int getTypeOfService()
          Fetch the type of service.
 int getVersion()
          Get the IP version code.
 boolean isValidChecksum()
          Check if the IP packet is valid, checksum-wise.
 boolean isValidIPChecksum()
          Check if the IP packet is valid, checksum-wise.
protected  int onesCompSum(byte[] bytes, int start, int len)
           
 java.lang.String toColoredString(boolean colored)
          Generate string with contents describing this IP packet.
 java.lang.String toColoredVerboseString(boolean colored)
          Convert this IP packet to a more verbose string.
 java.lang.String toString()
          Convert this IP packet to a readable string.
 
Methods inherited from class net.sourceforge.jpcap.net.EthernetPacket
getDestinationHwAddress, getEthernetData, getEthernetHeader, getEthernetHeaderLength, getEthernetProtocol, getSourceHwAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_ipOffset

protected int _ipOffset
Constructor Detail

IPPacket

public IPPacket(int lLen,
                byte[] bytes)
Create a new IP packet.

Method Detail

getVersion

public int getVersion()
Get the IP version code.


getIPHeaderLength

public int getIPHeaderLength()
Fetch the IP header length in bytes.


getIpHeaderLength

public int getIpHeaderLength()
Fetch the IP header length in bytes.


getHeaderLength

public int getHeaderLength()
Fetch the packet IP header length.

Overrides:
getHeaderLength in class EthernetPacket

getTypeOfService

public int getTypeOfService()
Fetch the type of service. For more information refer to the TypesOfService interface.


getLength

public int getLength()
Fetch the IP length in bytes.


getId

public int getId()
Fetch the unique ID of this IP datagram. The ID normally increments by one each time a datagram is sent by a host.


getFragmentFlags

public int getFragmentFlags()
Fetch fragmentation flags.


getFragmentOffset

public int getFragmentOffset()
Fetch fragmentation offset.


getTimeToLive

public int getTimeToLive()
Fetch the time to live. TTL sets the upper limit on the number of routers through which this IP datagram is allowed to pass.


getIPProtocol

public int getIPProtocol()
Fetch the code indicating the type of protocol embedded in the IP datagram. @see IPProtocols.


getProtocol

public int getProtocol()
Fetch the code indicating the type of protocol embedded in the IP datagram. @see IPProtocols.

Overrides:
getProtocol in class EthernetPacket

getIPChecksum

public int getIPChecksum()
Fetch the header checksum.


getChecksum

public int getChecksum()
Fetch the header checksum.


getSourceAddress

public java.lang.String getSourceAddress()
Fetch the IP address of the host where the packet originated from.


getSourceAddressBytes

public byte[] getSourceAddressBytes()
Fetch the source address as a byte array.


getSourceAddressAsLong

public long getSourceAddressAsLong()
Fetch the source address as a long.


getDestinationAddress

public java.lang.String getDestinationAddress()
Fetch the IP address of the host where the packet is destined.


getDestinationAddressBytes

public byte[] getDestinationAddressBytes()
Fetch the destination address as a byte array.


getDestinationAddressAsLong

public long getDestinationAddressAsLong()
Fetch the destination address as a long.


getIPHeader

public byte[] getIPHeader()
Fetch the IP header a byte array.


getHeader

public byte[] getHeader()
Fetch the IP header as a byte array.

Overrides:
getHeader in class EthernetPacket

getIPData

public byte[] getIPData()
Fetch the IP data as a byte array.


getData

public byte[] getData()
Fetch the IP data as a byte array.

Overrides:
getData in class EthernetPacket

isValidChecksum

public boolean isValidChecksum()
Check if the IP packet is valid, checksum-wise.


isValidIPChecksum

public boolean isValidIPChecksum()
Check if the IP packet is valid, checksum-wise.


computeReceiverIPChecksum

protected int computeReceiverIPChecksum()

computeReceiverChecksum

protected int computeReceiverChecksum(int start,
                                      int len)

computeSenderIPChecksum

protected int computeSenderIPChecksum()

computeSenderChecksum

protected int computeSenderChecksum(int start,
                                    int len,
                                    int csumPos)

onesCompSum

protected int onesCompSum(byte[] bytes,
                          int start,
                          int len)

toString

public java.lang.String toString()
Convert this IP packet to a readable string.

Overrides:
toString in class EthernetPacket

toColoredString

public java.lang.String toColoredString(boolean colored)
Generate string with contents describing this IP packet.

Overrides:
toColoredString in class EthernetPacket
Parameters:
colored - whether or not the string should contain ansi color escape sequences.

toColoredVerboseString

public java.lang.String toColoredVerboseString(boolean colored)
Convert this IP packet to a more verbose string.


getColor

public java.lang.String getColor()
Fetch ascii escape sequence of the color associated with this packet type.

Overrides:
getColor in class EthernetPacket