libDwm-0.6.0
Dwm::Ipv4UdpHeader Class Reference

Encapsulates an IPv4 UDP header. More...

#include <DwmIpv4UdpHeader.hh>

Inheritance diagram for Dwm::Ipv4UdpHeader:
Collaboration diagram for Dwm::Ipv4UdpHeader:

Public Member Functions

 Ipv4UdpHeader ()
 Constructor. The new object will own the underlying memory.
 
 Ipv4UdpHeader (const Ipv4PacketHeader &ipHeader)
 Construct from the given IPv4 packet header ipHeader.
 
 Ipv4UdpHeader (const Ipv4UdpHeader &udpHeader)
 Copy constructor.
 
 Ipv4UdpHeader (struct udphdr *udpHdr)
 Construct from a pointer to an existing udphdr. More...
 
 Ipv4UdpHeader (const struct udphdr &udpHdr)
 Constructor. Copies the contents of udpHdr. The new object will.
 
Ipv4UdpHeaderoperator= (const Ipv4UdpHeader &udpHeader)
 operator =
 
 ~Ipv4UdpHeader ()
 Destructor. More...
 
uint16_t SourcePort () const
 Returns the UDP source port in host byte order.
 
uint16_t SourcePort (uint16_t port)
 Sets the UDP source port to port, which must be in host byte order. More...
 
uint16_t DestinationPort () const
 Returns the UDP destination port in host byte order.
 
uint16_t DestinationPort (uint16_t port)
 Sets the UDP destination port to port, which must be in host byte order. More...
 
uint16_t UdpLength () const
 Returns the UDP length in host byte order. More...
 
uint16_t UdpLength (uint16_t udpLength)
 Sets and returns the UDP length in host byte order. More...
 
uint16_t UdpChecksum () const
 Returns the UDP checksum field.
 
void SetUdpChecksum (const Ipv4PacketHeader &ipHeader, const std::string &data)
 Calculates and sets the UDP checksum field, which requires the UDP payload data and some fields from the IP header. More...
 
void SetUdpChecksum (const Ipv4PacketHeader &ipHeader, const Ipv4UdpPayload &data)
 Calculates and sets the UDP checksum field, which requires the UDP payload data and some fields from the IP header. More...
 
uint8_t * End () const
 
std::istream & Read (std::istream &is)
 Reads the UDP header from an istream. Returns the istream.
 
std::ostream & Write (std::ostream &os) const
 Writes the UDP header to an ostream. Returns the ostream.
 
ssize_t Read (int fd)
 Reads the UDP header from a file descriptor. More...
 
ssize_t Write (int fd) const
 Writes the UDP header to a file descriptor. More...
 
size_t Read (FILE *f)
 Reads the UDP header from a FILE. More...
 
size_t Write (FILE *f) const
 Writes the UDP header to a FILE. More...
 
uint32_t StreamedLength () const
 Returns the number of bytes that would be written if we called one of the Write() members. More...
 
int Read (gzFile gzf)
 Reads the UDP header from a gzFile. More...
 
int Write (gzFile gzf) const
 Writes the UDP header to a gzFile. More...
 
int BZRead (BZFILE *bzf)
 Reads the UDP header from a BZFILE. More...
 
int BZWrite (BZFILE *bzf) const
 Writes the UDP header to a BZFILE. More...
 
bool operator== (const Ipv4UdpHeader &udpHeader) const
 operator ==
 
std::ostream & PrintXML (std::ostream &os, const std::string &pre="") const
 Print the UDP header to an ostream in pseudo-XML, with each line prefixed by pre. 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 an IPv4 UDP header.

Constructor & Destructor Documentation

◆ Ipv4UdpHeader()

Dwm::Ipv4UdpHeader::Ipv4UdpHeader ( struct udphdr *  udpHdr)

Construct from a pointer to an existing udphdr.

We will not copy the contents of udpHdr, it will continue to be owned by the caller. This is useful when the caller wishes to use this class for manipulating an existing udphdr.

◆ ~Ipv4UdpHeader()

Dwm::Ipv4UdpHeader::~Ipv4UdpHeader ( )

Destructor.

If the object owns the underlying memory, the underlying memory will be freed.

Member Function Documentation

◆ BZRead()

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

Reads the UDP header from a BZFILE.

Returns the number of bytes read on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::BZ2Readable.

◆ BZWrite()

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

Writes the UDP header to a BZFILE.

Returns the number of bytes written on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::BZ2Writable.

◆ DestinationPort()

uint16_t Dwm::Ipv4UdpHeader::DestinationPort ( uint16_t  port)

Sets the UDP destination port to port, which must be in host byte order.

Returns the UDP destination port in host byte order.

◆ PrintXML()

std::ostream& Dwm::Ipv4UdpHeader::PrintXML ( std::ostream &  os,
const std::string &  pre = "" 
) const

Print the UDP header to an ostream in pseudo-XML, with each line prefixed by pre.

Returns the ostream.

◆ Read() [1/3]

ssize_t Dwm::Ipv4UdpHeader::Read ( int  fd)
virtual

Reads the UDP header from a file descriptor.

Returns the number of bytes read on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::Readable.

◆ Read() [2/3]

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

Reads the UDP header from a FILE.

Returns 1 on success, 0 on failure.

Implements Dwm::Readable.

◆ Read() [3/3]

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

Reads the UDP header from a gzFile.

Returns the number of bytes read on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::GZReadable.

◆ SetUdpChecksum() [1/2]

void Dwm::Ipv4UdpHeader::SetUdpChecksum ( const Ipv4PacketHeader ipHeader,
const std::string &  data 
)

Calculates and sets the UDP checksum field, which requires the UDP payload data and some fields from the IP header.

◆ SetUdpChecksum() [2/2]

void Dwm::Ipv4UdpHeader::SetUdpChecksum ( const Ipv4PacketHeader ipHeader,
const Ipv4UdpPayload data 
)

Calculates and sets the UDP checksum field, which requires the UDP payload data and some fields from the IP header.

◆ SourcePort()

uint16_t Dwm::Ipv4UdpHeader::SourcePort ( uint16_t  port)

Sets the UDP source port to port, which must be in host byte order.

Returns the UDP source port in host byte order.

◆ StreamedLength()

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

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

Implements Dwm::Writable.

◆ UdpLength() [1/2]

uint16_t Dwm::Ipv4UdpHeader::UdpLength ( ) const

Returns the UDP length in host byte order.

The UDP length field includes the bytes for both the UDP header and the UDP payload.

◆ UdpLength() [2/2]

uint16_t Dwm::Ipv4UdpHeader::UdpLength ( uint16_t  udpLength)

Sets and returns the UDP length in host byte order.

The UDP length field includes the bytes for both the UDP header and the UDP payload.

◆ Write() [1/3]

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

Writes the UDP header to a file descriptor.

Returns the number of bytes written on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::Writable.

◆ Write() [2/3]

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

Writes the UDP header to a FILE.

Returns 1 on success, 0 on failure.

Implements Dwm::Writable.

◆ Write() [3/3]

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

Writes the UDP header to a gzFile.

Returns the number of bytes written on success (should be equal to StreamedLength()), -1 on failure.

Implements Dwm::GZWritable.


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