Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rr.cpp File Reference
#include "dnsmessage.h"
#include "domainfn.h"
#include "sysstring.h"
#include "exception.h"
#include "bits.h"
#include "lexfn.h"
#include "rr.h"
+ Include dependency graph for rr.cpp:

Functions

bool answers_qtype (unsigned short rrtype, unsigned short qtype)
 check whether RR type answers QTYPE
bool is_common_rr (unsigned short rrtype)
 check whether the RR type is a common RR
unsigned short qtype_getcode (const char *name, bool allow_qtype)
 retrieves qtype code
std::string read_entry (char *&data)
 read next item in a space-delimited string
void read_line (char *buff, FILE *f, int *linenum, int *linenum_old, int buffsz)
 read line from master/configuration file
std::string rr_fromstring (u_int16 RRTYPE, const char *_data, _domain origin)
 convert a string to binary RR data
std::string rr_fromstring (u_int16 RRTYPE, const char *data, domainname origin)
 convert a string to binary RR data
_domain rr_getbindomain (const unsigned char *_RDATA, u_int16 RRTYPE, int ix)
 reads a domain name from RR data
_domain rr_getbinmail (const unsigned char *RDATA, u_int16 RRTYPE, int ix)
 reads an email address from RR data
unsigned char * rr_getdata (const unsigned char *_RDATA, unsigned short RRTYPE, int ix)
 return pointer to start of data in RR
domainname rr_getdomain (const unsigned char *RDATA, u_int16 RRTYPE, int ix)
 reads a domain name from RR data
unsigned char * rr_getip4 (const unsigned char *_RDATA, u_int16 RRTYPE, int ix)
 read an IP address from RR data
unsigned char * rr_getip6 (const unsigned char *_RDATA, unsigned short RRTYPE, int ix)
 read an IPv6 address from RR data
u_int32 rr_getlong (const unsigned char *_RDATA, u_int16 RRTYPE, int ix)
 read a 32-bit value from RR data
u_int48 rr_getlonglong (const unsigned char *_RDATA, u_int16 RRTYPE, int ix)
domainname rr_getmail (const unsigned char *RDATA, u_int16 RRTYPE, int ix)
u_int16 rr_getshort (const unsigned char *_RDATA, u_int16 RRTYPE, int ix)
 read a 16-bit value from RR data
void rr_goto (unsigned char *&RDATA, u_int16 RRTYPE, int ix)
int rr_len (char prop, message_buff &buff, int ix, int len)
std::string rr_property_to_string (char type, const unsigned char *&RDATA, int RDLENGTH, domainname &zone)
 Convert RR property to strings.
void rr_read (u_int16 RRTYPE, unsigned char *&RDATA, unsigned short &RDLEN, message_buff &buff, int ix, int len)
 read a Resource Record from a DNS message
std::string rr_torelstring (u_int16 RRTYPE, const unsigned char *_RDATA, int RDLENGTH, domainname zone)
 convert a binary RR to string
std::string rr_tostring (u_int16 RRTYPE, const unsigned char *_RDATA, int RDLENGTH)
 convert a binary RR to string
void rr_write (u_int16 RRTYPE, unsigned char *RDATA, unsigned short RDLEN, std::string &dnsmessage, std::list< dom_compr_info > *comprinfo)
 write a Resource Record to a DNS message
rr_typerrtype_getinfo (u_int16 type)
 retrieves RR information
rr_typerrtype_getinfo (const char *name)
 retrieves RR information by name
char * rrtype_getname (u_int16 type)
 retrieves RR name

Variables

const int n_rr_types = sizeof(rr_types) / sizeof(rr_type)
 number of supported rr types
const rr_type rr_types []
 array of supported rr types

Function Documentation

bool answers_qtype ( unsigned short  rrtype,
unsigned short  qtype 
)

check whether RR type answers QTYPE

This function checks whether the given RR type provides an answer to the given QTYPE. This is the case if qtype matches rrtype, or if qtype is QTYPE_ANY , or if qtype is QTYPE_MAILB or QTYPE_MAILA and rrtype is an appropriate RR type.

Parameters
rrtypeResource Record type
qtypeQuestion type
Returns
true if the rrtype provides an answer to the qtype.

< All RR types QTYPE

< Mail agent RRs QTYPE (deprecated)

< Mail Forwarder RR type (deprecated)

< Mail Domain RR type (deprecated)

< Mailbox-related RRs QTYPE (experimental)

< Mail Box RR type (experimental)

< Mail Rename RR type (experimental)

bool is_common_rr ( unsigned short  rrtype)

check whether the RR type is a common RR

This function returns true if rrtype is a common RR type (that is, not a query type like QTYPE_ANY or QTYPE_IXFR . Note that this does not nessecarily mean Poslib supports the given RR type.

Parameters
rrtypeResource Record type to check
Returns
true if the rrtype is a common RR type

< Incremental Zone Transfer QTYPE

unsigned short qtype_getcode ( const char *  name,
bool  allow_qtype = true 
)

retrieves qtype code

This function tries to return the QTYPE code for a given string, that can either be a RR, "any", "ixfr", "axfr", "maila" or "mailb", or a numeric value.

Parameters
name
allow_qtypeIf set to false (default true), only allow common types
Returns
The 16-bit QTYPE value for the given string

< Mail agent RRs QTYPE (deprecated)

< Mailbox-related RRs QTYPE (experimental)

< Incremental Zone Transfer QTYPE

< Complete Zone Transfer QTYPE

< All RR types QTYPE

< All RR types QTYPE

std::string read_entry ( char *&  data)

read next item in a space-delimited string

This function reads the next item from a space-delimited string. It will raise an exception if none is found, and it will update the char pointer on the way. Quotes, unless escaped by a backslash, will not be included in the resulting string. Note that currently the maximum length of an entry is 256 bytes.

Parameters
dataPointer to string (gets updated)
Returns
The next entry in the string
See Also
read_line
void read_line ( char *  buff,
FILE *  f,
int *  linenum = NULL,
int *  linenum2 = NULL,
int  buffsz = 1024 
)

read line from master/configuration file

This function attempts to read a line from the file pointed to by f, placing the results in the "buff" buffer of "buffsz" bytes. This function, which is suitable for reading entries in a DNS master file, can automagically detect escaping characters with special meaning, and it can read multi-line lines with "(" and ")". The results that are placed in the buffer are suitable for use in the read_entry function.

One important thing in this context is the line number counter: as you can see there are two line number counters, which is nessecary because the line read function will always go to the beginning of the next source line before exiting. Thus, the line number counter would point to the beginning of the next (non-read) line. To prevent this, another pointer is given which is at the beginning of the function set to the current, accurate, line number. For this, a right value of the first pointer is required, though. Note that linenum should be initially set to 1 before the first read_line call.

Parameters
buffBuffer to place the results in
fThe file to read from
linenumPointer to line number counter (may be NULL; points to next source line)
linenum2Pointer to current line number.
buffszSize in bytes of the buffer (defaults to 1024)
See Also
read_entry
std::string rr_fromstring ( u_int16  rrtype,
const char *  data,
_domain  origin = (unsigned char *)"" 
)

convert a string to binary RR data

This function converts a string describing a Resource Record to binary RR data. The string should be in master file format - that is, if multiple arguments are to be put in the RR data, they should be separated by any number of spaces and tabs. For example, MX data might be "10 mail.yo.net.". You can specify an origin to which domain names are considered relative by means of the origin parameter.

Parameters
rrtypeType of the RR
dataThe text describing the RR
originIf given, the domain name relative domain names are considered relative to. This should be a binary domain name, like the domainname::domain field. If not given, domain names are considered relative to the root domain.
Returns
Binary data describing the RR
See Also
rr_tostring()
std::string rr_fromstring ( u_int16  RRTYPE,
const char *  data,
domainname  origin 
)

convert a string to binary RR data

This function converts a string describing a Resource Record to binary RR data. The string should be in master file format - that is, if multiple arguments are to be put in the RR data, they should be separated by any number of spaces and tabs. For example, MX data might be "10 mail.yo.net.". You can specify an origin to which domain names are considered relative by means of the origin parameter.

Parameters
RRTYPEType of the RR
dataThe text describing the RR
originIf given, the domain name relative domain names are considered relative to. This should be a binary domain name, like the domainname::domain field. If not given, domain names are considered relative to the root domain.
Returns
The domainname
See Also
rr_tostring()
_domain rr_getbindomain ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

reads a domain name from RR data

This function will read a domain name, in binary for, from RR data. The _domain it returns is dynamically allocated. The index is the property index in the RR data, beginning with 0, e.g. the domain name in the MX RR is one.

Parameters
RDATAThe RR data
RRTYPEType of RR
ixIf given, property index in the RR (defaults to zero)
Returns
Domain name at the specified position in the RR
_domain rr_getbinmail ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

reads an email address from RR data

This is currently an alias for rr_getdomain().

unsigned char* rr_getdata ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

return pointer to start of data in RR

For details, see rr_getdomain().

domainname rr_getdomain ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

reads a domain name from RR data

Variant of the rr_getbindomain() function returning a domainname structure.

unsigned char* rr_getip4 ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

read an IP address from RR data

For details, see rr_getdomain(). Data is dynamically allocated.

unsigned char* rr_getip6 ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

read an IPv6 address from RR data

For details, see rr_getdomain(). Data is dynamically allocated.

u_int32 rr_getlong ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

read a 32-bit value from RR data

For details, see rr_getdomain().

u_int48 rr_getlonglong ( const unsigned char *  _RDATA,
u_int16  RRTYPE,
int  ix 
)
domainname rr_getmail ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix 
)
u_int16 rr_getshort ( const unsigned char *  RDATA,
u_int16  RRTYPE,
int  ix = 0 
)

read a 16-bit value from RR data

For details, see rr_getdomain().

void rr_goto ( unsigned char *&  RDATA,
u_int16  RRTYPE,
int  ix 
)
int rr_len ( char  prop,
message_buff buff,
int  ix,
int  len 
)
std::string rr_property_to_string ( char  type,
const unsigned char *&  RDATA,
int  RDLENGTH,
domainname zone 
)

Convert RR property to strings.

Converts a RR property as in rr_type.property, to string.

Parameters
typeProperty type (see rr_type.property)
RDATARR data
RDLENGTHLenth of rest of RR
zoneZone to make domains relative to
void rr_read ( u_int16  RRTYPE,
unsigned char *&  RDATA,
unsigned short &  RDLEN,
message_buff buff,
int  ix,
int  len 
)

read a Resource Record from a DNS message

This function reads a Resource Record from a DNS message or other binary data source. It will decompress compressed domain names in the RR on the way, and return the data in the RDLEN and RDATA arguments.

Parameters
RRTYPEThe type of RR to read
RDATAThis will hold the RR data if the function succeeds
RDLENThis will hold the length of the RR if the function succeeds
buffThe message_buff the RR is stored in
ixIndex in the buffer the RR begins
lenLength the RR takes in the buffer
std::string rr_torelstring ( u_int16  RRTYPE,
const unsigned char *  RDATA,
int  RDLENGTH,
domainname  zone 
)

convert a binary RR to string

This function converts the binary RR to a human-readable string in master file format.

Parameters
RRTYPEThe RR type
RDATAThe binary RR data
RDLENGTHLength of the binary RR data
zoneIf given, domain names in the RR will be relative to that zone where possible.
Returns
A string describing the RR
See Also
rr_fromstring()
std::string rr_tostring ( u_int16  RRTYPE,
const unsigned char *  RDATA,
int  RDLENGTH 
)

convert a binary RR to string

This function converts the binary RR to a human-readable string in master file format.

Parameters
RRTYPEThe RR type
RDATAThe binary RR data
RDLENGTHLength of the binary RR data
Returns
A string describing the RR
See Also
rr_fromstring()
void rr_write ( u_int16  RRTYPE,
unsigned char *  RDATA,
unsigned short  RDLEN,
std::string &  dnsmessage,
std::list< dom_compr_info > *  comprinfo 
)

write a Resource Record to a DNS message

This function writes a Resource Record to a DNS message. It will compress domain names along the way.

Parameters
RRTYPEThe type of RR to write
RDATAPointer to the RR data
RDLENLength of the RR data
dnsmessageThe message to write to
comprinfoList of compressed domain names in DNS message, or NULL for no compression
rr_type* rrtype_getinfo ( u_int16  type)

retrieves RR information

This function retrieves information about a Resource Record by its 16-bit unique identifier as found in DNS messages. If no matching RR type is found, this function returnes NULL.

Parameters
typeThe RR type code
Returns
The RR type information, or NULL if none was found
rr_type* rrtype_getinfo ( const char *  name)

retrieves RR information by name

This function retrieves information a Resource Record by its name. If no matching RR type is found, this function returns NULL.

Parameters
nameThe RR name (case insensitive)
Returns
The RR type information, or NULL if none was found
char* rrtype_getname ( u_int16  type)

retrieves RR name

This function returns the name for a RR type by its 16-bit code. If no matching RR type is found, this function returns NULL.

Parameters
typeThe 16-bit RR code
Returns
Name of the RR, or NULL if none was found

Variable Documentation

const int n_rr_types = sizeof(rr_types) / sizeof(rr_type)

number of supported rr types

This is the number of RR types supported by Poslib. Thus, it is also the number of entries in the rr_types array.

See Also
rr_types
const rr_type rr_types[]
Initial value:
{
{ "A", 1, "i", R_NONE },
{ "NS", 2, "d", R_ASPCOMPRESS },
{ "MD", 3, "d", R_ASPCOMPRESS },
{ "MF", 4, "d", R_ASPCOMPRESS },
{ "CNAME", 5, "d", R_COMPRESS },
{ "SOA", 6, "dmltttt", R_COMPRESS },
{ "NULL", 10, "n", R_NONE },
{ "WKS", 11, "iw", R_NONE },
{ "PTR", 12, "d", R_COMPRESS },
{ "HINFO", 13, "cc", R_NONE },
{ "MX", 15, "sd", R_ASPCOMPRESS },
{ "TXT", 16, "h", R_NONE },
{ "RP", 17, "md", R_NONE },
{ "AFSDB", 18, "sd", R_ASP, },
{ "PX", 26, "sdd", R_NONE },
{ "AAAA", 28, "6", R_NONE },
{ "LOC", 29, "o", R_NONE },
{ "SRV", 33, "sssd", R_ASP, },
{ "NAPTR", 35, "sscccd", R_NONE },
{ "A6", 38, "7", R_NONE },
{ "DNAME", 39, "d", R_ASP },
{ "KEY", 250, "d4s*ss*", R_NONE },
}

array of supported rr types

This array contains information for all RR types supported by Poslib. For information about the meaning of the fields, see the rr_type documentation. This array contains exactly n_rr_types elements.

See Also
n_rr_types
rr_type