TSDuck v3.40-3963
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::IPv4Packet Class Reference

Representation of a raw IPv4 packet. More...

#include <tsIPv4Packet.h>

Public Types

using Port = AbstractNetworkAddress::Port
 The concept of port is used by TCP and UDP.
 

Public Member Functions

 IPv4Packet ()=default
 Default constructor.
 
 IPv4Packet (const void *data, size_t size)
 Constructor from raw content.
 
void clear ()
 Clear the packet content.
 
const uint8_t * data () const
 Get the address of the IPv4 packet content.
 
IPv4Address destinationAddress () const
 Get the destination IPv4 address.
 
Port destinationPort () const
 Get the TCP or UDP destination port.
 
IPv4SocketAddress destinationSocketAddress () const
 Get the destination IPv4 socket address.
 
bool fragmented () const
 Check if the IPv4 packet is fragmented.
 
const uint8_t * ipHeader () const
 Get the address of the IPv4 header.
 
size_t ipHeaderSize () const
 Get the size in bytes of the IPv4 header.
 
bool isTCP () const
 Check if the packet is a valid TCP packet.
 
bool isUDP () const
 Check if the packet is a valid UDP packet.
 
bool isValid () const
 Check if the IPv4 packet is valid.
 
uint8_t protocol () const
 Get the sub-protocol type (TCP, UDP, etc).
 
const uint8_t * protocolData () const
 Get the address of the sub-protocol payload data (TCP data, UDP data, etc).
 
size_t protocolDataSize () const
 Get the size in bytes of the sub-protocol payload data (TCP data, UDP data, etc).
 
const uint8_t * protocolHeader () const
 Get the address of the sub-protocol header (TCP header, UDP header, etc).
 
size_t protocolHeaderSize () const
 Get the size in bytes of the sub-protocol header (TCP header, UDP header, etc).
 
bool reset (const void *data, size_t size)
 Reinitialize the IPv4 packet with new content.
 
size_t size () const
 Get the size in bytes of the IPv4 packet content.
 
IPv4Address sourceAddress () const
 Get the source IPv4 address.
 
Port sourcePort () const
 Get the TCP or UDP source port.
 
IPv4SocketAddress sourceSocketAddress () const
 Get the source IPv4 socket address.
 
bool tcpACK () const
 Get the TCP ACK flag in the packet.
 
bool tcpFIN () const
 Get the TCP FIN flag in the packet.
 
bool tcpRST () const
 Get the TCP RST flag in the packet.
 
uint32_t tcpSequenceNumber () const
 Get the TCP sequence number in the packet.
 
bool tcpSYN () const
 Get the TCP SYN flag in the packet.
 

Static Public Member Functions

static uint16_t IPHeaderChecksum (const void *data, size_t size)
 Compute the checksum of an IPv4 header from raw data.
 
static size_t IPHeaderSize (const void *data, size_t size)
 Get the size in bytes of an IPv4 header from raw data.
 
static bool UpdateIPHeaderChecksum (void *data, size_t size)
 Update the checksum of an IPv4 header as raw data.
 
static bool VerifyIPHeaderChecksum (const void *data, size_t size)
 Verify the checksum of an IPv4 header from raw data.
 

Detailed Description

Representation of a raw IPv4 packet.

Constructor & Destructor Documentation

◆ IPv4Packet()

ts::IPv4Packet::IPv4Packet ( 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::IPv4Packet::reset ( const void *  data,
size_t  size 
)

Reinitialize the IPv4 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.

◆ isValid()

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

Check if the IPv4 packet is valid.

Returns
True if the packet is valid, false otherwise.

◆ protocol()

uint8_t ts::IPv4Packet::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::IPv4Packet::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::IPv4Packet::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::IPv4Packet::data ( ) const
inline

Get the address of the IPv4 packet content.

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

◆ size()

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

Get the size in bytes of the IPv4 packet content.

Returns
The size in bytes of the IPv4 packet content.

◆ ipHeader()

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

Get the address of the IPv4 header.

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

◆ ipHeaderSize()

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

Get the size in bytes of the IPv4 header.

Returns
The size in bytes of the IPv4 header.

◆ protocolHeader()

const uint8_t * ts::IPv4Packet::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::IPv4Packet::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::IPv4Packet::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::IPv4Packet::protocolDataSize ( ) const
inline

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::IPv4Packet::fragmented ( ) const

Check if the IPv4 packet is fragmented.

Returns
True if the packet is just a fragment of a larger packet.

◆ sourceAddress()

IPv4Address ts::IPv4Packet::sourceAddress ( ) const

Get the source IPv4 address.

Returns
The source IPv4 address.

◆ destinationAddress()

IPv4Address ts::IPv4Packet::destinationAddress ( ) const

Get the destination IPv4 address.

Returns
The destination IPv4 address.

◆ sourcePort()

Port ts::IPv4Packet::sourcePort ( ) const
inline

Get the TCP or UDP source port.

Returns
The TCP or UDP source port, zero for other protocols.

◆ destinationPort()

Port ts::IPv4Packet::destinationPort ( ) const
inline

Get the TCP or UDP destination port.

Returns
The TCP or UDP destination port, zero for other protocols.

◆ sourceSocketAddress()

IPv4SocketAddress ts::IPv4Packet::sourceSocketAddress ( ) const

Get the source IPv4 socket address.

Returns
The source IPv4 socket address.

◆ destinationSocketAddress()

IPv4SocketAddress ts::IPv4Packet::destinationSocketAddress ( ) const

Get the destination IPv4 socket address.

Returns
The destination IPv4 socket address.

◆ tcpSequenceNumber()

uint32_t ts::IPv4Packet::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::IPv4Packet::tcpSYN ( ) const

Get the TCP SYN flag in the packet.

Returns
The TCP SYN flag.

◆ tcpACK()

bool ts::IPv4Packet::tcpACK ( ) const

Get the TCP ACK flag in the packet.

Returns
The TCP ACK flag.

◆ tcpRST()

bool ts::IPv4Packet::tcpRST ( ) const

Get the TCP RST flag in the packet.

Returns
The TCP RST flag.

◆ tcpFIN()

bool ts::IPv4Packet::tcpFIN ( ) const

Get the TCP FIN flag in the packet.

Returns
The TCP FIN flag.

◆ IPHeaderSize()

static size_t ts::IPv4Packet::IPHeaderSize ( const void *  data,
size_t  size 
)
static

Get the size in bytes 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
The size in bytes of the IP header or zero on error.

◆ IPHeaderChecksum()

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

Compute 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
The computed checksum of the header.

◆ VerifyIPHeaderChecksum()

static bool ts::IPv4Packet::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.

◆ UpdateIPHeaderChecksum()

static bool ts::IPv4Packet::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.

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