SourceForge Jpcap

net.sourceforge.jpcap.net
Class IP.Packet

java.lang.Object
  extended by net.sourceforge.jpcap.net.Packet
      extended by net.sourceforge.jpcap.net.EthernetPacket
          extended by net.sourceforge.jpcap.net.IP.Packet
All Implemented Interfaces:
Serializable, EthernetFields
Direct Known Subclasses:
IPv4.Packet
Enclosing interface:
IP

public abstract static class IP.Packet
extends EthernetPacket

Base IP packet class.

Since:
2.0.0.
Version:
$Revision: 1.1 $
Author:
Esmond Pitt
See Also:
Serialized Form

Field Summary
protected  int _ipHeaderLength
          Length of IP header).
protected  int _ipOffset
          offset from beginning of byte array where IP header ends (i.e., size of ethernet frame header and IP header).
 
Fields inherited from class net.sourceforge.jpcap.net.EthernetPacket
_byteBuffer, _bytes, _ethOffset, _timeval
 
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
protected IP.Packet(int lLen, byte[] bytes)
           
protected IP.Packet(int lLen, byte[] bytes, Timeval tv)
           
protected IP.Packet(int lLen, ByteBuffer bb, Timeval tv)
           
 
Method Summary
 String getColor()
          Fetch ASCII escape sequence of the color associated with this packet type.
 byte[] getData()
          Fetch the data portion of the packet. This is overridden in derived classes to return successively smaller and smaller amounts of data. For example:
  • EthernetPacket.getData() returns the entire Ethernet payload excluding the Ethernet header
  • getData() only returns the IP payload, i.e. excluding the IP header which is in the Ethernet payload
  • TCPPacket.getData() only returns the TCP payload, i.e. excluding the TCP header which is in the IP payload
abstract  InetAddress getDestinationInetAddress()
          Fetch the destination IP address.
 byte[] getHeader()
          Fetch header portion of the packet. This is overridden in derived classes to return the header appropriate to the packet class. For example:
 int getHeaderLength()
          Return the length of the header.
abstract  byte[] getIPData()
          Fetch the IP data as a byte array.
abstract  byte[] getIPHeader()
          Fetch the IP header as a byte array.
abstract  int getIPHeaderLength()
          Fetch the IP header length in bytes.
abstract  int getIPProtocol()
          Fetch the code indicating the type of protocol embedded in the IP packet.
abstract  int getLength()
          Fetch the IP payload length in bytes.
abstract  InetAddress getSourceInetAddress()
          Fetch the source IP address.
abstract  int getVersion()
          Get the IP version code.
abstract  void setDestinationInetAddress(InetAddress address)
          Set the destination address.
abstract  void setSourceInetAddress(InetAddress address)
          Set the source address.
 String toColoredString(boolean colored)
          Generate string with contents describing this packet.
abstract  String toColoredVerboseString(boolean colored)
          Convert this IP packet to a more verbose string.
 
Methods inherited from class net.sourceforge.jpcap.net.EthernetPacket
equals, getDestinationHwAddress, getDestinationMACAddress, getEthernetCRC32, getEthernetData, getEthernetHeader, getEthernetHeaderLength, getEthernetProtocol, getPacketData, getPacketLength, getProtocol, getSourceHwAddress, getSourceMACAddress, getTimeval, hashCode, setChecksums, setDestinationMACAddress, setEthernetProtocol, setSourceMACAddress, toByteArray, toString
 
Methods inherited from class net.sourceforge.jpcap.net.Packet
getChecksum, ipChecksum, isValidChecksum
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_ipOffset

protected int _ipOffset
offset from beginning of byte array where IP header ends (i.e., size of ethernet frame header and IP header).


_ipHeaderLength

protected int _ipHeaderLength
Length of IP header).

Constructor Detail

IP.Packet

protected IP.Packet(int lLen,
                    byte[] bytes)

IP.Packet

protected IP.Packet(int lLen,
                    byte[] bytes,
                    Timeval tv)

IP.Packet

protected IP.Packet(int lLen,
                    ByteBuffer bb,
                    Timeval tv)
Method Detail

getIPHeaderLength

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

Returns:
the IP header length in bytes

getVersion

public abstract int getVersion()
Get the IP version code.

Returns:
the IP version (4 or 6).

getIPProtocol

public abstract int getIPProtocol()
Fetch the code indicating the type of protocol embedded in the IP packet.

Returns:
the IP protocol identifier.
See Also:
IPProtocols

getSourceInetAddress

public abstract InetAddress getSourceInetAddress()
Fetch the source IP address.

Returns:
the source IP address
Since:
2.0.0

setSourceInetAddress

public abstract void setSourceInetAddress(InetAddress address)
Set the source address.

Parameters:
address - Source address.
Since:
2.0.0

getDestinationInetAddress

public abstract InetAddress getDestinationInetAddress()
Fetch the destination IP address.

Returns:
the destination IP address
Since:
2.0.0

setDestinationInetAddress

public abstract void setDestinationInetAddress(InetAddress address)
Set the destination address.

Parameters:
address - Destination address.
Since:
2.0.0

getIPHeader

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

Returns:
the IP header

getIPData

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

Returns:
the IP payload

getHeaderLength

public int getHeaderLength()
Return the length of the header.

Overrides:
getHeaderLength in class EthernetPacket
Returns:
the length of the header as defined by Packet.getHeader().
See Also:
Packet.getHeader()

getLength

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

Returns:
the IP payload length in bytes.

getHeader

public byte[] getHeader()
Fetch header portion of the packet. This is overridden in derived classes to return the header appropriate to the packet class. For example:

Overrides:
getHeader in class EthernetPacket

getData

public byte[] getData()
Fetch the data portion of the packet. This is overridden in derived classes to return successively smaller and smaller amounts of data. For example:

Overrides:
getData in class EthernetPacket

toColoredString

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

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

toColoredVerboseString

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


getColor

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

Overrides:
getColor in class EthernetPacket
Returns:
ASCII escape sequence string

Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.