SourceForge Jpcap

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

public static class IPv4.TCP.Packet
extends IPv4.Packet
implements IPv4.TCP, TCPFields, IPFields

TCP/IPv4 packet class.

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sourceforge.jpcap.net.IPv4.TCP
IPv4.TCP.Packet
 
Nested classes/interfaces inherited from interface net.sourceforge.jpcap.net.IPv4
IPv4.IGMP, IPv4.PacketFactory, IPv4.TCP, IPv4.UDP
 
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.IPv4.TCP
serialVersionUID
 
Fields inherited from interface net.sourceforge.jpcap.net.IPv4
IPv4_VERSION
 
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.TCPFields
TCP_ACK_LEN, TCP_ACK_MASK, TCP_ACK_POS, TCP_CSUM_LEN, TCP_CSUM_POS, TCP_DP_POS, TCP_FIN_MASK, TCP_FLAG_LEN, TCP_FLAG_POS, TCP_HEADER_LEN, TCP_PORT_LEN, TCP_PSH_MASK, TCP_RST_MASK, TCP_SEQ_LEN, TCP_SEQ_POS, TCP_SP_POS, TCP_SYN_MASK, TCP_URG_LEN, TCP_URG_MASK, TCP_URG_POS, TCP_WIN_LEN, TCP_WIN_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.TCP.Packet(int lLen, ByteBuffer bb, Timeval tv)
          Create a new TCP packet.
 
Method Summary
 long getAcknowledgmentNumber()
          Fetch the byte acknowledgment number, i.e.
 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.
 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
  • IP.Packet.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
 int getDestinationPort()
          Fetches the destination port number.
 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.
 int getPayloadDataLength()
          Fetches the length of the payload data.
 long getSequenceNumber()
          Fetch the byte sequence number.
 int getSourcePort()
          Fetch the source port number.
 int getTCPChecksum()
          Fetch the TCP checksum.
 byte[] getTCPData()
          Fetch the TCP data as a byte array.
 byte[] getTCPHeader()
          Fetch the TCP header as a byte array.
 int getTCPHeaderLength()
          Fetch the TCP header length in bytes.
 int getUrgentPointer()
          Fetch the urgent pointer.
 int getWindowSize()
          Fetch the window size.
 boolean isAck()
          Return the ACK flag, indicating that the ack number is valid.
 boolean isFin()
          Return the FIN flag, indicating that the sender has finished sending.
 boolean isPsh()
          Return the PSH flag, indicating that the receiver should pass the data to the application as soon as possible.
 boolean isRst()
          Return the RST flag, indicating that the connection has been reset by the sender.
 boolean isSyn()
          Return the SYN flag, set to synchronize the sequence numbers between the sender and receiver as part of the connect handshake.
 boolean isUrg()
          Return the URG flag, indicating that the urgent pointer is valid.
 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.
 boolean isValidTCPChecksum()
          Return true if the TCP checksum is valid
 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.

 String toColoredString(boolean colored)
          Generate string with contents describing this packet.
 String toColoredVerboseString(boolean colored)
          Convert this IP packet to a more verbose string.
 
Methods inherited from class net.sourceforge.jpcap.net.IPv4.Packet
computeReceiverChecksum, computeReceiverIPChecksum, computeSenderChecksum, computeSenderIPChecksum, getDestinationInetAddress, getFragmentFlags, getFragmentOffset, getId, getIPChecksum, getIPData, getIPHeader, getIPHeaderLength, getIPProtocol, getLength, getProtocol, getSourceInetAddress, getTimeToLive, getTypeOfService, getVersion, isValidIPChecksum, setDestinationInetAddress, setSourceInetAddress
 
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.TCP.Packet

public IPv4.TCP.Packet(int lLen,
                       ByteBuffer bb,
                       Timeval tv)
Create a new TCP packet.

Parameters:
lLen - link-layer header length
bb - Packet data in a ByteBuffer
tv - Timestamp
Since:
2.0.0
Method Detail

getSourcePort

public int getSourcePort()
Description copied from interface: IP.TCP
Fetch the source port number.

Specified by:
getSourcePort in interface IP.TCP
Returns:
the souce port number.

getDestinationPort

public int getDestinationPort()
Description copied from interface: IP.TCP
Fetches the destination port number.

Specified by:
getDestinationPort in interface IP.TCP
Returns:
the destination port number.

getSequenceNumber

public long getSequenceNumber()
Description copied from interface: IP.TCP
Fetch the byte sequence number.

Specified by:
getSequenceNumber in interface IP.TCP
Returns:
the byte sequence number.

getAcknowledgmentNumber

public long getAcknowledgmentNumber()
Description copied from interface: IP.TCP
Fetch the byte acknowledgment number, i.e. the next byte that the sender expects to receive.

Specified by:
getAcknowledgmentNumber in interface IP.TCP
Returns:
the byte acknowledgement number.

getTCPHeaderLength

public int getTCPHeaderLength()
Description copied from interface: IP.TCP
Fetch the TCP header length in bytes.

Specified by:
getTCPHeaderLength in interface IP.TCP

getHeaderLength

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

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

getPayloadDataLength

public int getPayloadDataLength()
Description copied from interface: IP.TCP
Fetches the length of the payload data.

Specified by:
getPayloadDataLength in interface IP.TCP
Returns:
the length of the payload data.

getWindowSize

public int getWindowSize()
Description copied from interface: IP.TCP
Fetch the window size.

Specified by:
getWindowSize in interface IP.TCP
Returns:
the window size.

getTCPChecksum

public int getTCPChecksum()
Description copied from interface: IP.TCP
Fetch the TCP checksum.

Specified by:
getTCPChecksum in interface IP.TCP
Returns:
the TCP 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 IPv4.Packet

getUrgentPointer

public int getUrgentPointer()
Description copied from interface: IP.TCP
Fetch the urgent pointer.

Specified by:
getUrgentPointer in interface IP.TCP
Returns:
the TCP urgent pointer

isUrg

public boolean isUrg()
Description copied from interface: IP.TCP
Return the URG flag, indicating that the urgent pointer is valid.

Specified by:
isUrg in interface IP.TCP
Returns:
the URG flag.

isAck

public boolean isAck()
Description copied from interface: IP.TCP
Return the ACK flag, indicating that the ack number is valid.

Specified by:
isAck in interface IP.TCP
Returns:
the ACK flag.

isPsh

public boolean isPsh()
Description copied from interface: IP.TCP
Return the PSH flag, indicating that the receiver should pass the data to the application as soon as possible.

Specified by:
isPsh in interface IP.TCP
Returns:
the PSH flag.

isRst

public boolean isRst()
Description copied from interface: IP.TCP
Return the RST flag, indicating that the connection has been reset by the sender.

Specified by:
isRst in interface IP.TCP
Returns:
the RST flag.

isSyn

public boolean isSyn()
Description copied from interface: IP.TCP
Return the SYN flag, set to synchronize the sequence numbers between the sender and receiver as part of the connect handshake.

Specified by:
isSyn in interface IP.TCP
Returns:
the SYN flag.

isFin

public boolean isFin()
Description copied from interface: IP.TCP
Return the FIN flag, indicating that the sender has finished sending.

Specified by:
isFin in interface IP.TCP
Returns:
the FIN flag.

getTCPHeader

public byte[] getTCPHeader()
Description copied from interface: IP.TCP
Fetch the TCP header as a byte array. Altering this has no effect on the packet.

Specified by:
getTCPHeader in interface IP.TCP

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 IP.Packet

getTCPData

public byte[] getTCPData()
Description copied from interface: IP.TCP
Fetch the TCP data as a byte array. Altering this has no effect on the packet.

Specified by:
getTCPData in interface IP.TCP

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 IP.Packet

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 IPv4.Packet
Returns:
true iff all the checksums in the packet are valid.

isValidTCPChecksum

public boolean isValidTCPChecksum()
Description copied from interface: IP.TCP
Return true if the TCP checksum is valid

Specified by:
isValidTCPChecksum in interface IP.TCP
Returns:
true or false.

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 IPv4.Packet

toColoredString

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

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

toColoredVerboseString

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

Overrides:
toColoredVerboseString in class IPv4.Packet

getColor

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

Overrides:
getColor in class IP.Packet
Returns:
ASCII escape sequence string

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