net.sourceforge.jpcap.net
Class IPPacket

java.lang.Object
  |
  +--net.sourceforge.jpcap.net.Packet
        |
        +--net.sourceforge.jpcap.net.EthernetPacket
              |
              +--net.sourceforge.jpcap.net.IPPacket
All Implemented Interfaces:
EthernetFields, IPFields
Direct Known Subclasses:
ICMPPacket, IGMPPacket, TCPPacket, UDPPacket

public class IPPacket
extends EthernetPacket
implements IPFields

An IP protocol packet.

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


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
 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 data portion of the IP header.
 java.lang.String getDestinationAddress()
          Fetch the IP address of the host where the packet is destined for.
 int getFragmentFlags()
          Fetch fragmentation flags.
 int getFragmentOffset()
          Fetch the fragment offset.
 byte[] getHeader()
          Fetch the IP header, excluding ip data.
 int getHeaderLength()
          Fetch the IP header length in bytes.
protected static int getHeaderLength(byte[] hdr)
          Fetch the IP header length in bytes.
protected static int getHeaderLength(int lLen, byte[] bytes)
          Fetch the IP header length in bytes.
 int getId()
          Fetch the unique ID of this IP datagram.
 byte[] getIPData()
          Fetch data portion of the IP header.
 byte[] getIPHeader()
          Fetch the IP header, excluding ip data.
 int getIpHeaderLength()
          Fetch the IP header length in bytes.
 int getLength()
          Fetch the total length of the IP packet, including header and data payload, 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.
 int getTimeToLive()
          Fetch the time to live.
 int getTypeOfService()
          Fetch the type of service.
 int getVersion()
          Get the IP version code.
 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, getSourceHwAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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. i.e. 0x4 is IPv4.

getHeaderLength

protected static int getHeaderLength(int lLen,
                                     byte[] bytes)
Fetch the IP header length in bytes.
Parameters:
lLen - the offset in bytes past the link-layer header.
bytes - an ethernet header containing an IP datagram.

getHeaderLength

protected static int getHeaderLength(byte[] hdr)
Fetch the IP header length in bytes.
Parameters:
hdr - a truncated IP header.

getIpHeaderLength

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

getHeaderLength

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

getTypeOfService

public int getTypeOfService()
Fetch the type of service. @see TypesOfService.

getLength

public int getLength()
Fetch the total length of the IP packet, including header and data payload, 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 the fragment 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.

getProtocol

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

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.

getDestinationAddress

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

getIPHeader

public byte[] getIPHeader()
Fetch the IP header, excluding ip data.

getIPData

public byte[] getIPData()
Fetch data portion of the IP header.

getHeader

public byte[] getHeader()
Fetch the IP header, excluding ip data.
Overrides:
getHeader in class EthernetPacket

getData

public byte[] getData()
Fetch data portion of the IP header.
Overrides:
getData in class EthernetPacket

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