libDwm-0.6.0
Dwm::Ipv4UdpPacket Class Reference

Encapsulates a UDP packet, including the IP header. More...

#include <DwmIpv4UdpPacket.hh>

Inheritance diagram for Dwm::Ipv4UdpPacket:
Collaboration diagram for Dwm::Ipv4UdpPacket:

Public Member Functions

 Ipv4UdpPacket ()
 Constructor.
 
 Ipv4UdpPacket (uint8_t *ptr)
 Construct from a pointer to the start of IP header in a UDP packet. More...
 
 ~Ipv4UdpPacket ()
 Destructor. If we own the underlying data, we free it.
 
const Ipv4PacketHeaderIpHeader () const
 Returns a const reference to the IP header.
 
Ipv4PacketHeaderIpHeader ()
 Returns a mutable reference to the IP header.
 
const Ipv4UdpHeaderUdpHeader () const
 Returns a const refernece to the UDP header.
 
Ipv4UdpHeaderUdpHeader ()
 Returns a mutable reference to the UDP header.
 
std::string Payload () const
 Returns the payload as a string.
 
template<typename T >
bool GetPayload (T &payload) const
 Copies the contained payload into payload. More...
 
template<typename T >
bool SetPayload (const T &payload)
 Sets the contained payload to payload. More...
 
std::istream & Read (std::istream &is)
 Reads from an istream. Returns the istream.
 
std::ostream & Write (std::ostream &os) const
 Writes to an ostream. Returns the ostream.
 
ssize_t Read (int fd)
 NOT IMPLEMENTED.
 
ssize_t Write (int fd) const
 Writes to a file descriptor. More...
 
size_t Read (FILE *f)
 Reads the packet from the given FILE f. More...
 
size_t Write (FILE *f) const
 Writes the packet to the given FILE f. More...
 
int Read (gzFile gzf)
 Reads the packet from the given gzFile gzf. More...
 
int Write (gzFile gzf) const
 Writes the packet to the given gzFile gzf. More...
 
int BZRead (BZFILE *bzf)
 Reads the packet from the given BZFILE bzf. More...
 
int BZWrite (BZFILE *bzf) const
 Writes the packet to the given BZFILE bzf. More...
 
uint32_t StreamedLength () const
 Returns the numbers of bytes that should be written if one of the Write() members is called. More...
 
bool SendTo (int fd) const
 Sends the packet via the given descriptor fd. More...
 
bool SendTo (Socket &s) const
 Sends the packet via the given Socket s. More...
 
- Public Member Functions inherited from Dwm::Readable
virtual ~Readable ()
 destructor
 
- Public Member Functions inherited from Dwm::Writable
virtual ~Writable ()
 Destructor.
 
- Public Member Functions inherited from Dwm::GZReadable
virtual ~GZReadable ()
 destructor
 
- Public Member Functions inherited from Dwm::GZWritable
virtual ~GZWritable ()
 destructor
 

Detailed Description

Encapsulates a UDP packet, including the IP header.

Constructor & Destructor Documentation

◆ Ipv4UdpPacket()

Dwm::Ipv4UdpPacket::Ipv4UdpPacket ( uint8_t *  ptr)

Construct from a pointer to the start of IP header in a UDP packet.

We don't copy, so the caller still owns the memory at ptr.

Member Function Documentation

◆ BZRead()

int Dwm::Ipv4UdpPacket::BZRead ( BZFILE *  bzf)
virtual

Reads the packet from the given BZFILE bzf.

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

Implements Dwm::BZ2Readable.

◆ BZWrite()

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

Writes the packet 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::Ipv4UdpPacket::GetPayload ( T &  payload) const
inline

Copies the contained payload into payload.

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

Here is the call graph for this function:

◆ Read() [1/2]

size_t Dwm::Ipv4UdpPacket::Read ( FILE *  f)
virtual

Reads the packet from the given FILE f.

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

Implements Dwm::Readable.

◆ Read() [2/2]

int Dwm::Ipv4UdpPacket::Read ( gzFile  gzf)
virtual

Reads the packet from the given gzFile gzf.

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

Implements Dwm::GZReadable.

◆ SendTo() [1/2]

bool Dwm::Ipv4UdpPacket::SendTo ( int  fd) const

Sends the packet via the given descriptor fd.

Returns true on success, false on failure.

◆ SendTo() [2/2]

bool Dwm::Ipv4UdpPacket::SendTo ( Socket s) const

Sends the packet via the given Socket s.

Returns true on success, false on failure.

◆ SetPayload()

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

Sets the contained payload to payload.

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

Here is the call graph for this function:

◆ StreamedLength()

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

Returns the numbers of bytes that should be written if one of the Write() members is called.

Implements Dwm::Writable.

◆ Write() [1/3]

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

Writes to a file descriptor.

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

Implements Dwm::Writable.

◆ Write() [2/3]

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

Writes the packet to the given FILE f.

Returns 1 on success, 0 on failure.

Implements Dwm::Writable.

◆ Write() [3/3]

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

Writes the packet 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: