DwmDns-0.1.0
Dwm::Dns::Message Class Reference

Encapsulates a DNS message. More...

#include <DwmDnsMessage.hh>

Public Member Functions

 Message ()
 Constructor.
 
bool operator== (const Message &message) const
 Equal-to operator, mostly useful for unit tests.
 
void Clear ()
 Clears the message contents.
 
const MessageHeaderHeader () const
 Returns a const reference to the message header.
 
MessageHeaderHeader ()
 Returns a mutable reference to the message header.
 
const std::vector< MessageQuestion > & Questions () const
 Returns a const reference to the questions in the message.
 
std::vector< MessageQuestion > & Questions ()
 Returns a mutable reference to the questions in the message.
 
const std::vector< ResourceRecord > & Answers () const
 Returns a const reference to the records from the answers section of the message. More...
 
std::vector< ResourceRecord > & Answers ()
 Returns a mutable reference to the records from the answers section of the message. More...
 
const std::vector< ResourceRecord > & Authorities () const
 Returns a const reference to the records from the authority section of the message. More...
 
std::vector< ResourceRecord > & Authorities ()
 Returns a mutable reference to the records from the authority section of the message. More...
 
const std::vector< ResourceRecord > & Additional () const
 Returns a const reference to the records from the additional section of the message. More...
 
std::vector< ResourceRecord > & Additional ()
 Returns a mutable reference to the records from the additional section of the message. More...
 
uint8_t * Encode (uint8_t *pkt, uint8_t *ptr, uint16_t pktlen) const
 Encode the Message in pkt of length pktlen, starting at ptr. More...
 
const uint8_t * Decode (const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen)
 Decodes the Message in pkt of length pktlen, starting at ptr. More...
 
ssize_t SendTo (int sockFd, int flags, const struct sockaddr *to, int tolen) const
 A wrapper for sendto(). More...
 
ssize_t Write (int fd) const
 Writes the message to a connected TCP socket fd. More...
 
ssize_t RecvFrom (int sockFd, int flags, sockaddr *from, socklen_t *fromlen)
 A wrapper for recvfrom(). More...
 
ssize_t Read (int fd)
 Reads the Message from a connected TCP socket fd. More...
 
void EnableEDNS (uint16_t pduSize, bool doDnssec)
 Enable EDNS by setting the maximum packet size to pduSize and enable or disable DNSSEC. More...
 

Detailed Description

Encapsulates a DNS message.

See RFC1035 for details.

Member Function Documentation

◆ Additional() [1/2]

const std::vector<ResourceRecord>& Dwm::Dns::Message::Additional ( ) const
inline

Returns a const reference to the records from the additional section of the message.

◆ Additional() [2/2]

std::vector<ResourceRecord>& Dwm::Dns::Message::Additional ( )
inline

Returns a mutable reference to the records from the additional section of the message.

◆ Answers() [1/2]

const std::vector<ResourceRecord>& Dwm::Dns::Message::Answers ( ) const
inline

Returns a const reference to the records from the answers section of the message.

◆ Answers() [2/2]

std::vector<ResourceRecord>& Dwm::Dns::Message::Answers ( )
inline

Returns a mutable reference to the records from the answers section of the message.

◆ Authorities() [1/2]

const std::vector<ResourceRecord>& Dwm::Dns::Message::Authorities ( ) const
inline

Returns a const reference to the records from the authority section of the message.

◆ Authorities() [2/2]

std::vector<ResourceRecord>& Dwm::Dns::Message::Authorities ( )
inline

Returns a mutable reference to the records from the authority section of the message.

◆ Decode()

const uint8_t* Dwm::Dns::Message::Decode ( const uint8_t *  pkt,
const uint8_t *  ptr,
uint16_t  pktlen 
)

Decodes the Message in pkt of length pktlen, starting at ptr.

Returns the address of the first byte in pkt after the encoded message on success. Throws std::out_of_range if pkt was too short to hold the message or another decoding error occurred.

◆ EnableEDNS()

void Dwm::Dns::Message::EnableEDNS ( uint16_t  pduSize,
bool  doDnssec 
)

Enable EDNS by setting the maximum packet size to pduSize and enable or disable DNSSEC.

◆ Encode()

uint8_t* Dwm::Dns::Message::Encode ( uint8_t *  pkt,
uint8_t *  ptr,
uint16_t  pktlen 
) const

Encode the Message in pkt of length pktlen, starting at ptr.

Returns the address of the first byte after the encoded message on success. Throws std::out_of_range if the message will not fit in the packet.

◆ Read()

ssize_t Dwm::Dns::Message::Read ( int  fd)

Reads the Message from a connected TCP socket fd.

Note that under the hood, we read the 2-byte length before reading the Message content, since that's how DNS over TCP works per RFC1035. Returns the number of bytes read on success, -1 on failure.

◆ RecvFrom()

ssize_t Dwm::Dns::Message::RecvFrom ( int  sockFd,
int  flags,
sockaddr *  from,
socklen_t *  fromlen 
)

A wrapper for recvfrom().

Receives the message from socket descriptor 'sockFd'. 'from' and 'to' will be filled with information about the source of the message (just like recvfrom()). 'flags' has the same meaning as flags for recvfrom(). Returns the return value of recvfrom() (which is called under the hood).

◆ SendTo()

ssize_t Dwm::Dns::Message::SendTo ( int  sockFd,
int  flags,
const struct sockaddr *  to,
int  tolen 
) const

A wrapper for sendto().

Sends the message to the destination specified destination 'to' via socket descriptor 'sockFd'. 'flags' has the same meaning as flags for sendto(), and 'tolen' should be the size of 'to'. Returns the return value of sendto().

◆ Write()

ssize_t Dwm::Dns::Message::Write ( int  fd) const

Writes the message to a connected TCP socket fd.

Note that under the hood, we write the 2-byte length before writing the Message content, since that's how DNS over TCP works per RFC1035. Returns the number of bytes written on success, -1 on failure.


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