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 MessageHeader & | Header () const |
| Returns a const reference to the message header. | |
| MessageHeader & | Header () |
| 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... | |
Encapsulates a DNS message.
See RFC1035 for details.
|
inline |
Returns a const reference to the records from the additional section of the message.
|
inline |
Returns a mutable reference to the records from the additional section of the message.
|
inline |
Returns a const reference to the records from the answers section of the message.
|
inline |
Returns a mutable reference to the records from the answers section of the message.
|
inline |
Returns a const reference to the records from the authority section of the message.
|
inline |
Returns a mutable reference to the records from the authority section of the message.
| 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.
| 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.
| 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.
| ssize_t Dwm::Dns::Message::Read | ( | int | fd | ) |
| 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).
| 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().
| 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.