Class TCP

  • All Implemented Interfaces:
    IPacket

    public class TCP
    extends BasePacket
    Implements TCP packet format.
    • Field Detail

      • sourcePort

        protected int sourcePort
      • destinationPort

        protected int destinationPort
      • sequence

        protected int sequence
      • acknowledge

        protected int acknowledge
      • dataOffset

        protected byte dataOffset
      • flags

        protected short flags
      • windowSize

        protected short windowSize
      • checksum

        protected short checksum
      • urgentPointer

        protected short urgentPointer
      • options

        protected byte[] options
    • Constructor Detail

      • TCP

        public TCP()
    • Method Detail

      • getSourcePort

        public int getSourcePort()
        Gets TCP source port.
        Returns:
        TCP source port
      • setSourcePort

        public TCP setSourcePort​(int sourcePort)
        Sets TCP source port.
        Parameters:
        sourcePort - the sourcePort to set (unsigned 16 bits integer)
        Returns:
        this
      • getDestinationPort

        public int getDestinationPort()
        Gets TCP destination port.
        Returns:
        the destinationPort
      • setDestinationPort

        public TCP setDestinationPort​(int destinationPort)
        Sets TCP destination port.
        Parameters:
        destinationPort - the destinationPort to set (unsigned 16 bits integer)
        Returns:
        this
      • getChecksum

        public short getChecksum()
        Gets checksum.
        Returns:
        the checksum
      • setChecksum

        public TCP setChecksum​(short checksum)
        Sets checksum.
        Parameters:
        checksum - the checksum to set
        Returns:
        this
      • getSequence

        public int getSequence()
        Gets sequence number.
        Returns:
        the sequence number
      • setSequence

        public TCP setSequence​(int seq)
        Sets sequence number.
        Parameters:
        seq - the sequence number to set
        Returns:
        this
      • getAcknowledge

        public int getAcknowledge()
        Gets acknowledge number.
        Returns:
        the acknowledge number
      • setAcknowledge

        public TCP setAcknowledge​(int ack)
        Sets acknowledge number.
        Parameters:
        ack - the acknowledge number to set
        Returns:
        this
      • getDataOffset

        public byte getDataOffset()
        Gets offset.
        Returns:
        the offset
      • setDataOffset

        public TCP setDataOffset​(byte offset)
        Sets offset.
        Parameters:
        offset - the offset to set
        Returns:
        this
      • getFlags

        public short getFlags()
        Gets TCP flags.
        Returns:
        the TCP flags
      • setFlags

        public TCP setFlags​(short flags)
        Sets TCP flags.
        Parameters:
        flags - the TCP flags to set
        Returns:
        this
      • getWindowSize

        public short getWindowSize()
        Gets TCP window size.
        Returns:
        the TCP window size
      • setWindowSize

        public TCP setWindowSize​(short windowSize)
        Sets TCP window size.
        Parameters:
        windowSize - the TCP window size to set
        Returns:
        this
      • resetChecksum

        public void resetChecksum()
        Description copied from interface: IPacket
        Reset any checksum as needed, and call resetChecksum on all parents.
        Specified by:
        resetChecksum in interface IPacket
        Overrides:
        resetChecksum in class BasePacket
      • getUrgentPointer

        public short getUrgentPointer()
        Gets urgent pointer.
        Returns:
        the urgent pointer
      • setUrgentPointer

        public TCP setUrgentPointer​(short urgentPointer)
        Sets urgent pointer.
        Parameters:
        urgentPointer - the urgent pointer to set
        Returns:
        this
      • getOptions

        public byte[] getOptions()
        Gets TCP options.
        Returns:
        the TCP options
      • setOptions

        public TCP setOptions​(byte[] options)
        Sets TCP options.
        Parameters:
        options - the options to set
        Returns:
        this
      • serialize

        public byte[] serialize()
        Serializes the packet. Will compute and set the following fields if they are set to specific values at the time serialize is called: -checksum : 0 -length : 0
        Returns:
        a byte[] containing this packet and payloads
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class BasePacket
      • deserializer

        public static Deserializer<TCP> deserializer()
        Deserializer function for TCP packets.
        Returns:
        deserializer function
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object