libDwm-0.6.0
Dwm::Ipv4TcpPayload Class Reference

Encapsulates a TCP payload. More...

#include <DwmIpv4TcpPayload.hh>

Inheritance diagram for Dwm::Ipv4TcpPayload:
Collaboration diagram for Dwm::Ipv4TcpPayload:

Public Member Functions

 Ipv4TcpPayload ()
 Constructor.
 
 Ipv4TcpPayload (const Ipv4PacketHeader &ipHeader, const Ipv4TcpHeader &tcpHeader)
 Construct based on an Ipv4PacketHeader and Ipv4TcpHeader that point into a TCP packet, which may have a payload following the TCP header. More...
 
 Ipv4TcpPayload (uint8_t *buf, uint16_t len)
 Construct based on a pointer that points to the first byte of the payload in a TCP packet. More...
 
 Ipv4TcpPayload (const std::string &s)
 Copy the given string into the payload.
 
 ~Ipv4TcpPayload ()
 Destructor.
 
std::pair< uint16_t, const uint8_t * > Payload () const
 Returns a shallow copy of the payload.
 
std::string ToString () const
 Returns the payload as a string.
 
uint32_t Sum () const
 Returns the IP sum of the payload, which can be used as part of TCP checksum computation. More...
 
template<typename T >
bool GetPayload (T &payload) const
 Copies the payload into payload. More...
 
template<typename T >
bool SetPayload (const T &payload)
 Sets the payload to payload. More...
 
void Clear ()
 Clears the payload.
 
std::istream & Read (std::istream &is, uint16_t len)
 Reads len bytes of the payload from the given istream is.
 
std::ostream & Write (std::ostream &os) const
 Writes the payload to the given ostream os.
 
ssize_t Read (int fd, uint16_t len)
 Reads len bytes of the payload from the given descriptor fd. More...
 
ssize_t Write (int fd) const
 Writes the payload to the given descriptor fd. More...
 
size_t Read (FILE *f, uint16_t len)
 Reads len bytes of the payload from the given FILE f. More...
 
size_t Write (FILE *f) const
 Writes the payload to the given FILE f. More...
 
int Read (gzFile gzf, uint16_t len)
 Reads len bytes of the payload from the given gzFile gzf. More...
 
int Write (gzFile gzf) const
 Writes the payload to the given gzFile gzf. More...
 
int BZRead (BZFILE *bzf, uint16_t len)
 Reads len bytes of the payload from the given BZFILE bzf. More...
 
int BZWrite (BZFILE *bzf) const
 Writes the payload to the given BZFILE bzf. More...
 
uint32_t StreamedLength () const
 Returns the number of bytes that would be written if we called one of the Write() members. More...
 
- Public Member Functions inherited from Dwm::Writable
virtual ~Writable ()
 Destructor.
 
- Public Member Functions inherited from Dwm::GZWritable
virtual ~GZWritable ()
 destructor
 

Detailed Description

Encapsulates a TCP payload.

Note
We don't inherit from Readable, GZReadable and BZ because our read members need to be passed a length.

Constructor & Destructor Documentation

◆ Ipv4TcpPayload() [1/2]

Dwm::Ipv4TcpPayload::Ipv4TcpPayload ( const Ipv4PacketHeader ipHeader,
const Ipv4TcpHeader tcpHeader 
)

Construct based on an Ipv4PacketHeader and Ipv4TcpHeader that point into a TCP packet, which may have a payload following the TCP header.

The underlying memory will not be copied, we'll just point to it. Hence the caller should not free the underlying memory while the Ipv4TcpPayload is still in use.

◆ Ipv4TcpPayload() [2/2]

Dwm::Ipv4TcpPayload::Ipv4TcpPayload ( uint8_t *  buf,
uint16_t  len 
)

Construct based on a pointer that points to the first byte of the payload in a TCP packet.

The underlying memory will not be copied, we'll just point to it. Hence the caller should not free the underlying memory while the Ipv4TcpPayload is still in use.

Member Function Documentation

◆ BZRead()

int Dwm::Ipv4TcpPayload::BZRead ( BZFILE *  bzf,
uint16_t  len 
)

Reads len bytes of the payload from the given BZFILE bzf.

Returns the number of bytes read on success, -1 on failure.

◆ BZWrite()

int Dwm::Ipv4TcpPayload::BZWrite ( BZFILE *  bzf) const
virtual

Writes the payload to the given BZFILE bzf.

Returns the number of bytes written on success, -1 on failure.

Implements Dwm::BZ2Writable.

◆ GetPayload()

template<typename T >
bool Dwm::Ipv4TcpPayload::GetPayload ( T &  payload) const
inline

Copies the payload into payload.

Returns true on success, false on failure. Note that payload must be a type natively supported by Dwm::IO or a type derived from Dwm::Readable.

Here is the call graph for this function:

◆ Read() [1/3]

ssize_t Dwm::Ipv4TcpPayload::Read ( int  fd,
uint16_t  len 
)

Reads len bytes of the payload from the given descriptor fd.

Returns the number of bytes read on success, -1 on failure.

◆ Read() [2/3]

size_t Dwm::Ipv4TcpPayload::Read ( FILE *  f,
uint16_t  len 
)

Reads len bytes of the payload from the given FILE f.

Returns 1 on success, 0 on failure (fread() semantics).

◆ Read() [3/3]

int Dwm::Ipv4TcpPayload::Read ( gzFile  gzf,
uint16_t  len 
)

Reads len bytes of the payload from the given gzFile gzf.

Returns the number of bytes read on success, -1 on failure.

◆ SetPayload()

template<typename T >
bool Dwm::Ipv4TcpPayload::SetPayload ( const T &  payload)
inline

Sets the payload to payload.

Returns true on success, false on failure. Note that payload must be a type natively supported by Dwm::IO or a type derived from Dwm::Writable.

Here is the call graph for this function:

◆ StreamedLength()

uint32_t Dwm::Ipv4TcpPayload::StreamedLength ( ) const
virtual

Returns the number of bytes that would be written if we called one of the Write() members.

Implements Dwm::Writable.

◆ Sum()

uint32_t Dwm::Ipv4TcpPayload::Sum ( ) const

Returns the IP sum of the payload, which can be used as part of TCP checksum computation.

◆ Write() [1/3]

ssize_t Dwm::Ipv4TcpPayload::Write ( int  fd) const
virtual

Writes the payload to the given descriptor fd.

Returns the number of bytes written on success, -1 on failure.

Implements Dwm::Writable.

◆ Write() [2/3]

size_t Dwm::Ipv4TcpPayload::Write ( FILE *  f) const
virtual

Writes the payload to the given FILE f.

Returns 1 on success, 0 on failure (fread() semantics).

Implements Dwm::Writable.

◆ Write() [3/3]

int Dwm::Ipv4TcpPayload::Write ( gzFile  gzf) const
virtual

Writes the payload to the given gzFile gzf.

Returns the number of bytes written on success, -1 on failure.

Implements Dwm::GZWritable.


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