libDwm-0.6.0
Dwm::Ipv4UdpPayload Class Reference

Encapsulates a UDP payload. More...

#include <DwmIpv4UdpPayload.hh>

Inheritance diagram for Dwm::Ipv4UdpPayload:
Collaboration diagram for Dwm::Ipv4UdpPayload:

Public Member Functions

 Ipv4UdpPayload ()
 Constructor.
 
 Ipv4UdpPayload (const Ipv4UdpHeader &udpHeader)
 Construct based on a Ipv4UdpHeader that points into a UDP packet, which may have a payload following the header. More...
 
 Ipv4UdpPayload (uint8_t *buf, uint16_t len)
 Construct based on a pointer that points to the first byte of the payload in a UDP packet. More...
 
 Ipv4UdpPayload (const std::string &s)
 Copy the given string into the payload.
 
 ~Ipv4UdpPayload ()
 Destructor.
 
std::pair< uint16_t, const uint8_t * > Payload () const
 
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 UDP 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 descriptor fd. 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 one of the Write() members were called. 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 UDP payload.

Constructor & Destructor Documentation

◆ Ipv4UdpPayload() [1/2]

Dwm::Ipv4UdpPayload::Ipv4UdpPayload ( const Ipv4UdpHeader udpHeader)

Construct based on a Ipv4UdpHeader that points into a UDP packet, which may have a payload following the 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 Ipv4UdpPayload is still in use.

◆ Ipv4UdpPayload() [2/2]

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

Construct based on a pointer that points to the first byte of the payload in a UDP 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 Ipv4UdpPayload is still in use.

Member Function Documentation

◆ BZRead()

int Dwm::Ipv4UdpPayload::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::Ipv4UdpPayload::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::Ipv4UdpPayload::GetPayload ( T &  payload) const
inline

Copies the payload into payload.

Returns true on success, false on failure. Note that payload must be of 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::Ipv4UdpPayload::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::Ipv4UdpPayload::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::Ipv4UdpPayload::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::Ipv4UdpPayload::SetPayload ( const T &  payload)
inline

Sets the payload to payload.

Returns true on success, false on failure. Note that payload must be of 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::Ipv4UdpPayload::StreamedLength ( ) const
virtual

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

Implements Dwm::Writable.

◆ Sum()

uint32_t Dwm::Ipv4UdpPayload::Sum ( ) const

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

◆ Write() [1/3]

ssize_t Dwm::Ipv4UdpPayload::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::Ipv4UdpPayload::Write ( FILE *  f) const
virtual

Writes the payload to the given descriptor fd.

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

Implements Dwm::Writable.

◆ Write() [3/3]

int Dwm::Ipv4UdpPayload::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: