Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DnsMessage Class Reference

DNS message. More...

#include <dnsmessage.h>

+ Collaboration diagram for DnsMessage:

Public Member Functions

 DnsMessage ()
 constructor
 ~DnsMessage ()
 destructor
message_buff compile (int maxlen)
 compile DNS message
DnsMessageinitialize_answer ()
 create answer message TODO: rename? Creates a DNS message that has the same sign key, so that read_data can check whether it is an answer to the DNS message. TODO: note: not for clients
int read_from_data (unsigned char *data, int len)
 read DNS message
void read_section (std::list< DnsRR > &section, int count, message_buff &buff, int &pos, unsigned int *tsig_pos=NULL)
void write_section (std::list< DnsRR > &section, int lenpos, std::string &message, std::list< dom_compr_info > &comprinfo, int maxlen, bool is_additional=false)

Static Public Member Functions

static DnsRR read_rr (message_buff &buff, int &pos, int flags=0)
static void write_rr (DnsRR &rr, std::string &message, std::list< dom_compr_info > *comprinfo, int flags=0)

Public Attributes

bool AA
 authoritative answer
std::list< DnsRRadditional
 additional section
std::list< DnsRRanswers
 answer section
std::list< DnsRRauthority
 authority section
u_int16 ID
 message ID
u_int4 OPCODE
 operation
bool QR
 query bit
std::list< DnsQuestionquestions
 question section
bool RA
 recursion available
u_int4 RCODE
 return code
bool RD
 recursion desired
std::string sign_key
 TSIG key for message.
bool TC
 truncated
DnsRRtsig_rr
 TSIG record for message.
time_t tsig_rr_signtime
 optional tsig_rr signing time (if set to 0, time(NULL) will be used
u_int3 Z
 reserved bits

Detailed Description

DNS message.

This structure holds a DNS message, the message type with which DNS servers talk to each other. It has member functions for reading data from binary DNS messages, and to create a binary DNS message from the structure.

Constructor & Destructor Documentation

DnsMessage::DnsMessage ( )

constructor

This constructs an empty DNS message, with all fields set to defaults.

DnsMessage::~DnsMessage ( )

destructor

This destroys the DNS message.

Member Function Documentation

message_buff DnsMessage::compile ( int  maxlen)

compile DNS message

This function will compile the DNS message into the binary format sent over UDP or TCP connections.

Parameters
maxlenMaximum length. If the message exceeds this limit, it will be cut off and the TC bit will be set. This should be 65535 for TCP messages and 512 for UDP messages.
Returns
The compiled DNS message
Todo:
: is this safe if chars are unsigned?

< Secure Key Transaction Authentication (RFC 2845)

< Secure Key Transaction Authentication (RFC 2845)

< Secure Key Transaction Authentication (RFC 2845)

< Secure Key Transaction Authentication (RFC 2845)

DnsMessage * DnsMessage::initialize_answer ( )

create answer message TODO: rename? Creates a DNS message that has the same sign key, so that read_data can check whether it is an answer to the DNS message. TODO: note: not for clients

Returns
the answer message
int DnsMessage::read_from_data ( unsigned char *  data,
int  len 
)

read DNS message

This function will read DNS message information from the binary DNS message pointed to by data. If the DNS message contains a TSIG record, the function returns the number of bytes read before the TSIG record. This information is nessecary in case you want to call verify_signature on the message manually.

If the tsig_rr is non-NULL, the message is verified; if it is NULL and the message still contains a TSIG record, then tsig_rr is set to the TSIG record found in the message (for use in later checking).

Parameters
dataBinary DNS message
lenLength of message
Returns
The length of the data read, not including a TSIG record if it is present
DnsRR DnsMessage::read_rr ( message_buff buff,
int &  pos,
int  flags = 0 
)
static
void DnsMessage::read_section ( std::list< DnsRR > &  section,
int  count,
message_buff buff,
int &  pos,
unsigned int *  tsig_pos = NULL 
)

< DNS update message

< Secure Key Transaction Authentication (RFC 2845)

void DnsMessage::write_rr ( DnsRR rr,
std::string &  message,
std::list< dom_compr_info > *  comprinfo,
int  flags = 0 
)
static
void DnsMessage::write_section ( std::list< DnsRR > &  section,
int  lenpos,
std::string &  message,
std::list< dom_compr_info > &  comprinfo,
int  maxlen,
bool  is_additional = false 
)

< DNS update message

Member Data Documentation

bool DnsMessage::AA

authoritative answer

This is set to true by the server if it was authoritative for the zone the query was in. Note that, if the answer contains CNAMEs, this does not nessecarily mean the server was also authoritative for the domain the CNAME pointed to.

std::list< DnsRR > DnsMessage::additional

additional section

This section contains additional information that might be interesting for the client, for example addresses for NS or MX records in the answer or authority sections.

std::list< DnsRR > DnsMessage::answers

answer section

This section, filled by the server, contains the Resource Records that form a direct answer to the query.

std::list< DnsRR > DnsMessage::authority

authority section

This section contains pointers to authoritative sources for the information. Most nameservers put the nameserver list for the domain names in the section here.

u_int16 DnsMessage::ID

message ID

This is the message ID field of the DNS message. This number is set by client software, and is copied into the response by the server in order for clients to be able to track queries. Note that the Posadis resolver sets this value for you, so there's no need to do that yourself in client applications.

u_int4 DnsMessage::OPCODE

operation

This is the type of operation the query is. The most common are OPCODE_QUERY for queries, OPCODE_UPDATE for dynamic updates, and OPCODE_NOTIFY for DNS notifications. Possible values are in dnsdefs.h.

bool DnsMessage::QR

query bit

This bit is set to false for queries, and true for answers.

std::list< DnsQuestion > DnsMessage::questions

question section

This section should contain exactly one DnsQuestion object for common DNS queries. This query is usually copied into the response by the server.

bool DnsMessage::RA

recursion available

Set to the server indicating whether it is willing to provide recursive service. Note that, even if recursion was not desired (see RD), this value might still be set.

u_int4 DnsMessage::RCODE

return code

Code indicating whether the query was succesful. Some famous RCODEs, which are defined in dnsdefs.h, are: RCODE_NOERROR to indicate success, RCODE_NXDOMAIN if the domain name queried for didn't exist, or RCODE_SERVFAIL in case of a server failure.

bool DnsMessage::RD

recursion desired

Set this to true to instruct the server to do recursive operation (e.g. consult other nameservers to find the right answer). Note that servers may refuse to do this, and will set the RA field accordingly.

std::string DnsMessage::sign_key

TSIG key for message.

Key to use when signing or verifying a signed message; see tsig_rr.

bool DnsMessage::TC

truncated

Set to true by the server if the answer was cut off because it didn't fit in a UDP packet. Unless you instruct it not to, the Posadis resolver will automatically retry using TCP to get the complete answer.

DnsRR* DnsMessage::tsig_rr

TSIG record for message.

When compiling a message, if tsig_rr is non-null, this TSIG record will be used to sign the DNS message, in combination with the key sign_key.

When reading a message, if tsig_rr is non-null, this TSIG record will be used to verify the DNS message, in combination with the key sign_key (i.e., verify_signature will be called automatically). If it is set to NULL and the message is signed, instead, it will be set to the TSIG record found in the message.

When calling verify_signature, this record will be used to verify the DNS message.

time_t DnsMessage::tsig_rr_signtime

optional tsig_rr signing time (if set to 0, time(NULL) will be used

u_int3 DnsMessage::Z

reserved bits

This the value of three currently reserved bits in the DNS message. Though these bits currently have no meaning and servers might require them to be zero, Poslib is able to read and write them.


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