SourceForge Jpcap

net.sourceforge.jpcap.net
Class IPv4.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
              extended by net.sourceforge.jpcap.net.IPv4.Packet
All Implemented Interfaces:
Serializable, EthernetFields, IPFields
Direct Known Subclasses:
IPPacket, IPv4.TCP.Packet, IPv4.UDP.Packet
Enclosing interface:
IPv4

public abstract static class IPv4.Packet
extends IP.Packet
implements IPFields

Base IPv4 packet class.

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

Field Summary
 
Fields inherited from class net.sourceforge.jpcap.net.IP.Packet
_ipHeaderLength, _ipOffset
 
Fields inherited from class net.sourceforge.jpcap.net.EthernetPacket
_byteBuffer, _bytes, _ethOffset, _timeval
 
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
IPv4.Packet(int lLen, byte[] bytes)
           
IPv4.Packet(int lLen, byte[] bytes, Timeval tv)
           
IPv4.Packet(int lLen, ByteBuffer bb, Timeval tv)
           
 
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()
          Return the actual packet checksum as received.
 InetAddress getDestinationInetAddress()
          Fetch the destination IP address.
 int getFragmentFlags()
          Fetch fragmentation flags.
 int getFragmentOffset()
          Fetch fragment offset.
 int getId()
          Fetch the unique ID of this IP packet.
 int getIPChecksum()
          Fetch the IP checksum.
 byte[] getIPData()
          Fetch the IP data as a byte array.
 byte[] getIPHeader()
          Fetch the IP header as a byte array.
 int getIPHeaderLength()
          Fetch the IP header length in bytes.
 int getIPProtocol()
          Fetch the code indicating the type of protocol embedded in the IP packet.
 int getLength()
          Fetch the IP payload length in bytes.
 int getProtocol()
          Return the protocol. This is overridden by derived classes: for example:
 InetAddress getSourceInetAddress()
          Fetch the source IP address.
 int getTimeToLive()
          Fetch the time to live.
 int getTypeOfService()
          Fetch the type of service.
 int getVersion()
          Get the IP version code.
 boolean isValidChecksum()
          Return true iff all the checksums in the packet are valid, otherwise false.
 boolean isValidIPChecksum()
          Check if the IP packet is valid, checksum-wise.
 void setChecksums()
          Set all the checksums in this packet prior to sending. Calling this method sets all the IP, ICMP, IGMP, TCP, UDP etc checksums as appropriate. It is called automatically by PacketOutputStream.writePacket(Packet). Derived classes must override this abstract method, and must call super.setChecksums(), after setting their own checksums (unless super.setChecksums() is abstract, i.e. this method). Otherwise the lower-level checksums will not be correct.
 void setDestinationInetAddress(InetAddress address)
          Set the destination address.
 void setSourceInetAddress(InetAddress address)
          Set the source address.
 String toColoredVerboseString(boolean colored)
          Convert this IP packet to a more verbose string.
 
Methods inherited from class net.sourceforge.jpcap.net.IP.Packet
getColor, getData, getHeader, getHeaderLength, toColoredString
 
Methods inherited from class net.sourceforge.jpcap.net.EthernetPacket
equals, getDestinationHwAddress, getDestinationMACAddress, getEthernetCRC32, getEthernetData, getEthernetHeader, getEthernetHeaderLength, getEthernetProtocol, getPacketData, getPacketLength, getSourceHwAddress, getSourceMACAddress, getTimeval, hashCode, setDestinationMACAddress, setEthernetProtocol, setSourceMACAddress, toByteArray, toString
 
Methods inherited from class net.sourceforge.jpcap.net.Packet
ipChecksum
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IPv4.Packet

public IPv4.Packet(int lLen,
                   byte[] bytes)

IPv4.Packet

public IPv4.Packet(int lLen,
                   byte[] bytes,
                   Timeval tv)

IPv4.Packet

public IPv4.Packet(int lLen,
                   ByteBuffer bb,
                   Timeval tv)
Method Detail

getVersion

public int getVersion()
Description copied from class: IP.Packet
Get the IP version code.

Specified by:
getVersion in class IP.Packet
Returns:
the IP version (4 or 6).

getIPHeaderLength

public int getIPHeaderLength()
Description copied from class: IP.Packet
Fetch the IP header length in bytes.

Specified by:
getIPHeaderLength in class IP.Packet
Returns:
the IP header length in bytes

getTypeOfService

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

Returns:
the type of service.
See Also:
TypesOfService

getLength

public int getLength()
Description copied from class: IP.Packet
Fetch the IP payload length in bytes.

Specified by:
getLength in class IP.Packet
Returns:
the IP payload length in bytes.

getId

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

Returns:
the unique packet ID

getFragmentFlags

public int getFragmentFlags()
Fetch fragmentation flags.

Returns:
the fragmentation flags

getFragmentOffset

public int getFragmentOffset()
Fetch fragment offset.

Returns:
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.

Returns:
the TTL

getIPProtocol

public int getIPProtocol()
Description copied from class: IP.Packet
Fetch the code indicating the type of protocol embedded in the IP packet.

Specified by:
getIPProtocol in class IP.Packet
Returns:
the IP protocol identifier.
See Also:
IPProtocols

getProtocol

public int getProtocol()
Return the protocol. This is overridden by derived classes: for example:

Overrides:
getProtocol in class EthernetPacket
Returns:
the protocol word.

getIPChecksum

public int getIPChecksum()
Fetch the IP checksum.

Returns:
the IP checksum

getChecksum

public int getChecksum()
Return the actual packet checksum as received. Derived classes override this to return the most specific checksum, e.g.: The implementation in Packet.getChecksum() returns zero.

Overrides:
getChecksum in class Packet

getSourceInetAddress

public InetAddress getSourceInetAddress()
Description copied from class: IP.Packet
Fetch the source IP address.

Specified by:
getSourceInetAddress in class IP.Packet
Returns:
the source IP address

setSourceInetAddress

public void setSourceInetAddress(InetAddress address)
Description copied from class: IP.Packet
Set the source address.

Specified by:
setSourceInetAddress in class IP.Packet
Parameters:
address - Source address.

getDestinationInetAddress

public InetAddress getDestinationInetAddress()
Description copied from class: IP.Packet
Fetch the destination IP address.

Specified by:
getDestinationInetAddress in class IP.Packet
Returns:
the destination IP address

setDestinationInetAddress

public void setDestinationInetAddress(InetAddress address)
Description copied from class: IP.Packet
Set the destination address.

Specified by:
setDestinationInetAddress in class IP.Packet
Parameters:
address - Destination address.

getIPHeader

public byte[] getIPHeader()
Description copied from class: IP.Packet
Fetch the IP header as a byte array.

Specified by:
getIPHeader in class IP.Packet
Returns:
the IP header

getIPData

public byte[] getIPData()
Description copied from class: IP.Packet
Fetch the IP data as a byte array.

Specified by:
getIPData in class IP.Packet
Returns:
the IP payload

isValidChecksum

public boolean isValidChecksum()
Return true iff all the checksums in the packet are valid, otherwise false. Derived classes with checksums should override, and should call super.isValidChecksum() to check the validity of base class checksums. The Packet.isValidChecksum() implementation just returns true.

Overrides:
isValidChecksum in class Packet
Returns:
true iff all the checksums in the packet are valid.

isValidIPChecksum

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

Returns:
true iff the IP checksum is valid.

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)

setChecksums

public void setChecksums()
Set all the checksums in this packet prior to sending. Calling this method sets all the IP, ICMP, IGMP, TCP, UDP etc checksums as appropriate. It is called automatically by PacketOutputStream.writePacket(Packet). Derived classes must override this abstract method, and must call super.setChecksums(), after setting their own checksums (unless super.setChecksums() is abstract, i.e. this method). Otherwise the lower-level checksums will not be correct.

After calling this method the EthernetPacket.hashCode() of this object will probably change.

Overrides:
setChecksums in class EthernetPacket

toColoredVerboseString

public String toColoredVerboseString(boolean colored)
Description copied from class: IP.Packet
Convert this IP packet to a more verbose string.

Specified by:
toColoredVerboseString in class IP.Packet

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