Click
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
TCPHelper Class Reference

This class provides several methods that can be used by elements that inherits from it to manage TCP packets. More...

#include <tcphelper.hh>

Inheritance diagram for TCPHelper:
IPHelper

Public Member Functions

WritablePacket * forgeRst (Packet *packet)
 
WritablePacket * forgePacket (uint32_t saddr, uint32_t daddr, uint16_t sport, uint16_t dport, tcp_seq_t seq, tcp_seq_t ack, uint16_t winSize, uint8_t flags, uint32_t contentSize=0) const
 Create a TCP packet.
 
uint16_t getDestinationPort (Packet *packet) const
 Return the destination port of a packet.
 
uint16_t getSourcePort (Packet *packet) const
 Return the source port of a packet.
 
tcp_seq_t getNextSequenceNumber (Packet *packet) const
 Return the sequence number of the packet that will be received after the given one.
 
uint16_t getWindowSize (Packet *packet) const
 Return the window size set in the header of a packet.
 
void setWindowSize (WritablePacket *packet, uint16_t winSize) const
 Set the window size in the TCP header of a packet.
 
unsigned char * getPayload (WritablePacket *packet) const
 Return the payload of a TCP packet.
 
const unsigned char * getPayloadConst (Packet *packet) const
 Return the payload of a TCP packet.
 
uint16_t getPayloadOffset (Packet *packet) const
 Return the offset of the payload in a TCP packet.
 
void setPayload (WritablePacket *packet, const unsigned char *payload, uint32_t length) const
 Set the payload of a TCP packet.
 
void setSequenceNumber (WritablePacket *packet, tcp_seq_t seq) const
 Set the sequence number of a TCP packet.
 
void setAckNumber (WritablePacket *packet, tcp_seq_t ack) const
 Set the ack number of a TCP packet.
 
uint8_t getFlags (Packet *packet) const
 Return the flags of a TCP packet.
 
- Public Member Functions inherited from IPHelper
uint16_t packetTotalLength (Packet *packet) const
 Return the length of the IP packet, obtained from the header.
 
uint16_t getIPHeaderOffset (Packet *packet) const
 Return the offset in the packet at which the IP header starts.
 
void setPacketTotalLength (WritablePacket *packet, unsigned length) const
 Set the length of the IP packet in the header.
 
uint32_t getDestinationAddress (Packet *packet) const
 Return the IP destination address of the packet.
 
uint32_t getSourceAddress (Packet *packet) const
 Return the IP source address of the packet.
 
void computeIPChecksum (WritablePacket *packet) const
 Recompute the IP checksum of the packet and set it in the IP header.
 
void rewrite_ipport (WritablePacket *p, IPAddress ip, uint16_t port, const int shift, bool is_tcp)
 

Static Public Member Functions

static tcp_seq_t getSequenceNumber (Packet *packet)
 Return the sequence number of a packet.
 
static tcp_seq_t getAckNumber (Packet *packet)
 Return the ack number of a packet.
 
static bool isTCP (Packet *packet)
 Indicate whether a packet is a TCP packet.
 
static bool isSyn (Packet *packet)
 Indicate whether a packet is a SYN packet.
 
static bool isFin (Packet *packet)
 Indicate whether a packet is a FIN packet.
 
static bool isRst (Packet *packet)
 Indicate whether a packet is a RST packet.
 
static bool isAck (Packet *packet)
 Indicate whether a packet is an ACK packet.
 
static bool checkFlag (Packet *packet, uint8_t flag)
 Check if a given flag is set in a packet.
 
static unsigned getPayloadLength (Packet *packet)
 Return the length of the TCP payload of a packet.
 
static bool isJustAnAck (Packet *packet, const bool or_fin=false)
 Indicate whether the packet is just an ACK without any additional information.
 
static void computeTCPChecksum (WritablePacket *packet)
 Compute the TCP checksum of a packet and set it in its header.
 
static void resetTCPChecksum (WritablePacket *packet)
 Reset the TCP checksum of a packet and set it in its header.
 
static int iterateOptions (Packet *packet, std::function< bool(uint8_t, void *)> fnt)
 
static void printPacket (Packet *p)
 

Detailed Description

This class provides several methods that can be used by elements that inherits from it to manage TCP packets.

Member Function Documentation

◆ forgePacket()

WritablePacket * TCPHelper::forgePacket ( uint32_t  saddr,
uint32_t  daddr,
uint16_t  sport,
uint16_t  dport,
tcp_seq_t  seq,
tcp_seq_t  ack,
uint16_t  winSize,
uint8_t  flags,
uint32_t  contentSize = 0 
) const

Create a TCP packet.

Parameters
saddrSource IP address
daddrDestination IP address
sportSource port
dportDestination port
seqSequence number
ackAck number
windowSizeWindow size
flagsThe TCP flags on one byte
contentSizeExtra space to allocate for the TCP payload
Returns
The created TCP packet

◆ getDestinationPort()

uint16_t TCPHelper::getDestinationPort ( Packet *  packet) const
inline

Return the destination port of a packet.

Parameters
packetThe packet
Returns
The destination port of the packet

◆ getSourcePort()

uint16_t TCPHelper::getSourcePort ( Packet *  packet) const
inline

Return the source port of a packet.

Parameters
packetThe packet
Returns
The source port of the packet

◆ getSequenceNumber()

tcp_seq_t TCPHelper::getSequenceNumber ( Packet *  packet)
inlinestatic

Return the sequence number of a packet.

Parameters
packetThe packet
Returns
The sequence number of the packet

◆ getAckNumber()

tcp_seq_t TCPHelper::getAckNumber ( Packet *  packet)
inlinestatic

Return the ack number of a packet.

Parameters
packetThe packet
Returns
The ack number of the packet

◆ getNextSequenceNumber()

tcp_seq_t TCPHelper::getNextSequenceNumber ( Packet *  packet) const
inline

Return the sequence number of the packet that will be received after the given one.

Parameters
fcbA pointer to the FCB of the flow
packetThe packet to check
Returns
The sequence number of the packet after the given one

◆ getWindowSize()

uint16_t TCPHelper::getWindowSize ( Packet *  packet) const
inline

Return the window size set in the header of a packet.

Parameters
packetThe packet
Returns
The window size set in the header of the packet

◆ setWindowSize()

void TCPHelper::setWindowSize ( WritablePacket *  packet,
uint16_t  winSize 
) const
inline

Set the window size in the TCP header of a packet.

Parameters
packetThe packet
winSizeThe window size

◆ isTCP()

bool TCPHelper::isTCP ( Packet *  packet)
inlinestatic

Indicate whether a packet is a TCP packet.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is a TCP packet

◆ isSyn()

bool TCPHelper::isSyn ( Packet *  packet)
inlinestatic

Indicate whether a packet is a SYN packet.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is a SYN packet

◆ isFin()

bool TCPHelper::isFin ( Packet *  packet)
inlinestatic

Indicate whether a packet is a FIN packet.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is a FIN packet

◆ isRst()

bool TCPHelper::isRst ( Packet *  packet)
inlinestatic

Indicate whether a packet is a RST packet.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is a RST packet

◆ isAck()

bool TCPHelper::isAck ( Packet *  packet)
inlinestatic

Indicate whether a packet is an ACK packet.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is an ACK packet

◆ checkFlag()

bool TCPHelper::checkFlag ( Packet *  packet,
uint8_t  flag 
)
inlinestatic

Check if a given flag is set in a packet.

Parameters
packetThe packet
flagThe offset of the flag
Returns
A boolean indicating whether the flag is set in the packet

◆ getPayloadLength()

unsigned TCPHelper::getPayloadLength ( Packet *  packet)
inlinestatic

Return the length of the TCP payload of a packet.

Parameters
packetThe packet
Returns
The length of the TCP payload of the packet

◆ getPayload()

unsigned char * TCPHelper::getPayload ( WritablePacket *  packet) const
inline

Return the payload of a TCP packet.

Parameters
packetThe packet
Returns
The payload of the packet

◆ getPayloadConst()

const unsigned char * TCPHelper::getPayloadConst ( Packet *  packet) const
inline

Return the payload of a TCP packet.

Parameters
packetThe packet
Returns
The const payload of the packet

◆ getPayloadOffset()

uint16_t TCPHelper::getPayloadOffset ( Packet *  packet) const
inline

Return the offset of the payload in a TCP packet.

Parameters
packetThe packet
Returns
The offset of the payload in a TCP packet

◆ setPayload()

void TCPHelper::setPayload ( WritablePacket *  packet,
const unsigned char *  payload,
uint32_t  length 
) const
inline

Set the payload of a TCP packet.

Parameters
packetThe packet
payloadThe new value of the payload
lengthThe length of the payload

◆ setSequenceNumber()

void TCPHelper::setSequenceNumber ( WritablePacket *  packet,
tcp_seq_t  seq 
) const
inline

Set the sequence number of a TCP packet.

Parameters
packetThe packet
seqThe sequence number of the packet

◆ setAckNumber()

void TCPHelper::setAckNumber ( WritablePacket *  packet,
tcp_seq_t  ack 
) const
inline

Set the ack number of a TCP packet.

Parameters
packetThe packet
ackThe ack number of the packet

◆ isJustAnAck()

bool TCPHelper::isJustAnAck ( Packet *  packet,
const bool  or_fin = false 
)
inlinestatic

Indicate whether the packet is just an ACK without any additional information.

Parameters
packetThe packet
Returns
A boolean indicating whether the packet is just an ACK without any additional information

◆ getFlags()

uint8_t TCPHelper::getFlags ( Packet *  packet) const
inline

Return the flags of a TCP packet.

Parameters
packetThe packet
Returns
A byte containing the flags of the packet

◆ computeTCPChecksum()

void TCPHelper::computeTCPChecksum ( WritablePacket *  packet)
inlinestatic

Compute the TCP checksum of a packet and set it in its header.

Parameters
packetThe packet

◆ resetTCPChecksum()

void TCPHelper::resetTCPChecksum ( WritablePacket *  packet)
inlinestatic

Reset the TCP checksum of a packet and set it in its header.

Parameters
packetThe packet

The documentation for this class was generated from the following files: