TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::IPPacket Class Reference

#include <tsIPPacket.h>

Public Types

using Port = AbstractNetworkAddress::Port

Public Member Functions

 IPPacket ()=default
 IPPacket (const void *data, size_t size)
void clear ()
const uint8_t * data () const
const IPSocketAddress & destination () const
bool fragmented () const
IP generation () const
const uint8_t * ipHeader () const
size_t ipHeaderSize () const
bool isTCP () const
bool isUDP () const
bool isValid () const
uint8_t protocol () const
const uint8_t * protocolData () const
size_t protocolDataSize () const
const uint8_t * protocolHeader () const
size_t protocolHeaderSize () const
bool reset (const void *data, size_t size)
size_t size () const
const IPSocketAddress & source () const
bool tcpACK () const
bool tcpFIN () const
bool tcpRST () const
uint32_t tcpSequenceNumber () const
bool tcpSYN () const

Static Public Member Functions

static uint16_t IPHeaderChecksum (const void *data, size_t size)
static size_t IPHeaderSize (const void *data, size_t size, uint8_t *protocol=nullptr)
static bool UpdateIPHeaderChecksum (void *data, size_t size)
static bool VerifyIPHeaderChecksum (const void *data, size_t size)

Detailed Description

Representation of a raw IPv4 or IPv6 packet.

Member Typedef Documentation

◆ Port

The concept of port is used by TCP and UDP.

Constructor & Destructor Documentation

◆ IPPacket() [1/2]

ts::IPPacket::IPPacket ( )
default

Default constructor.

◆ IPPacket() [2/2]

ts::IPPacket::IPPacket ( const void * data,
size_t size )

Constructor from raw content.

Parameters
[in]dataAddress of the IP packet data.
[in]sizeSize of the IP packet data.

Member Function Documentation

◆ reset()

bool ts::IPPacket::reset ( const void * data,
size_t size )

Reinitialize the IP4 packet with new content.

Parameters
[in]dataAddress of the IP packet data.
[in]sizeSize of the IP packet data.
Returns
True on success, false if the packet is invalid.

◆ clear()

void ts::IPPacket::clear ( )

Clear the packet content.

◆ isValid()

bool ts::IPPacket::isValid ( ) const
inline

Check if the IPv4 packet is valid.

Returns
True if the packet is valid, false otherwise.

◆ generation()

IP ts::IPPacket::generation ( ) const
inline

Get the current generation of IP addresses.

Returns
The IP generation of the packet. Return IP::Any if the packet is invalid.

◆ protocol()

uint8_t ts::IPPacket::protocol ( ) const
inline

Get the sub-protocol type (TCP, UDP, etc).

Returns
The sub-protocol type, as defined by constants IPv4_PROTO_*.

◆ isTCP()

bool ts::IPPacket::isTCP ( ) const
inline

Check if the packet is a valid TCP packet.

Returns
True if the packet is a valid TCP packet.

◆ isUDP()

bool ts::IPPacket::isUDP ( ) const
inline

Check if the packet is a valid UDP packet.

Returns
True if the packet is a valid UDP packet.

◆ data()

const uint8_t * ts::IPPacket::data ( ) const
inline

Get the address of the IP packet content.

Returns
The address of the IP packet content or a null pointer if the packet is invalid.

◆ size()

size_t ts::IPPacket::size ( ) const
inline

Get the size in bytes of the IP packet content.

Returns
The size in bytes of the IP packet content.

◆ ipHeader()

const uint8_t * ts::IPPacket::ipHeader ( ) const
inline

Get the address of the IP header.

Returns
The address of the IP header or a null pointer if the packet is invalid.

◆ ipHeaderSize()

size_t ts::IPPacket::ipHeaderSize ( ) const
inline

Get the size in bytes of the IP header.

Returns
The size in bytes of the IP header.

◆ protocolHeader()

const uint8_t * ts::IPPacket::protocolHeader ( ) const
inline

Get the address of the sub-protocol header (TCP header, UDP header, etc).

Returns
The address of the sub-protocol header or a null pointer if the packet is invalid.

◆ protocolHeaderSize()

size_t ts::IPPacket::protocolHeaderSize ( ) const
inline

Get the size in bytes of the sub-protocol header (TCP header, UDP header, etc).

Returns
The size in bytes of the sub-protocol header.

◆ protocolData()

const uint8_t * ts::IPPacket::protocolData ( ) const
inline

Get the address of the sub-protocol payload data (TCP data, UDP data, etc).

Returns
The address of the sub-protocol header payload data or a null pointer if the packet is invalid.

◆ protocolDataSize()

size_t ts::IPPacket::protocolDataSize ( ) const

Get the size in bytes of the sub-protocol payload data (TCP data, UDP data, etc).

Returns
The size in bytes of the sub-protocol payload data.

◆ fragmented()

bool ts::IPPacket::fragmented ( ) const

Check if the IP packet is fragmented.

Returns
True if the packet is just a fragment of a larger packet. Only IPv4 packets can be fragmented. Always false on IPv6 packets.

◆ source()

const IPSocketAddress & ts::IPPacket::source ( ) const
inline

Get the source IP socket address.

Returns
A constant reference to the source IP socket address. The port is valid only in the case of UDP or TCP packet.

◆ destination()

const IPSocketAddress & ts::IPPacket::destination ( ) const
inline

Get the destination IP socket address.

Returns
A constant reference to the destination IP socket address. The port is valid only in the case of UDP or TCP packet.

◆ tcpSequenceNumber()

uint32_t ts::IPPacket::tcpSequenceNumber ( ) const

Get the TCP sequence number in the packet.

Returns
The TCP sequence number or zero if this is not a TCP packet.

◆ tcpSYN()

bool ts::IPPacket::tcpSYN ( ) const

Get the TCP SYN flag in the packet.

Returns
The TCP SYN flag.

◆ tcpACK()

bool ts::IPPacket::tcpACK ( ) const

Get the TCP ACK flag in the packet.

Returns
The TCP ACK flag.

◆ tcpRST()

bool ts::IPPacket::tcpRST ( ) const

Get the TCP RST flag in the packet.

Returns
The TCP RST flag.

◆ tcpFIN()

bool ts::IPPacket::tcpFIN ( ) const

Get the TCP FIN flag in the packet.

Returns
The TCP FIN flag.

◆ IPHeaderSize()

size_t ts::IPPacket::IPHeaderSize ( const void * data,
size_t size,
uint8_t * protocol = nullptr )
static

Get the size in bytes of an IP header from raw data.

Parameters
[in]dataAddress of the IP packet.
[in]sizeSize of the IP packet or header (must be larger than the header size).
[out]protocolIf not null, receives the type of the next protocol layer (TCP, UDP, etc).
Returns
The size in bytes of the IP header or zero on error.

◆ IPHeaderChecksum()

uint16_t ts::IPPacket::IPHeaderChecksum ( const void * data,
size_t size )
static

Compute the checksum of an IPv4 header from raw data. The concept of header checksum is specific to IPv4. IPv6 headers do not have checksums.

Parameters
[in]dataAddress of the IP packet.
[in]sizeSize of the IP packet or header (must be larger than the header size).
Returns
The computed checksum of the IPv4 header or zero for IPv6 header.

◆ VerifyIPHeaderChecksum()

bool ts::IPPacket::VerifyIPHeaderChecksum ( const void * data,
size_t size )
static

Verify the checksum of an IPv4 header from raw data.

Parameters
[in]dataAddress of the IP packet.
[in]sizeSize of the IP packet or header (must be larger than the header size).
Returns
True if the checksum of the header if correct, false otherwise. Always true for IPv6 headers (there is no header checksum in IPv6).

◆ UpdateIPHeaderChecksum()

bool ts::IPPacket::UpdateIPHeaderChecksum ( void * data,
size_t size )
static

Update the checksum of an IPv4 header as raw data.

Parameters
[in,out]dataAddress of the IP packet.
[in]sizeSize of the IP packet or header (must be larger than the header size).
Returns
True if the checksum was updated, false on incorrect buffer. Always true for IPv6 headers (there is no header checksum in IPv6).

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