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

class representing a domain name More...

#include <domainfn.h>

+ Collaboration diagram for domainname:

Public Member Functions

 domainname ()
 default constructor
 domainname (const char *text, const domainname &origin)
 constructor from human-readable text
 domainname (const char *text, _cdomain origin=(unsigned char *)"")
 constructor from human-readable text
 domainname (message_buff &buff, int ix)
 constructor from data in a DNS message
 domainname (bool is_binary, const unsigned char *dom)
 constructor from binary domain name
 domainname (const domainname &nam)
 copy constructor
 ~domainname ()
 destructor
_domain c_str () const
 binary representation of domain
std::string canonical () const
 RFC 2345 canonical form.
domainname from (int ix) const
 domain-name portion
std::string label (int ix) const
 label in domain name
int len () const
 length of binary representation
int ncommon (const domainname &dom) const
 check label match count
int nlabels () const
 number of labels of the domain name
bool operator!= (const domainname &nam) const
 negatice equality test
domainnameoperator+ (const domainname &dom)
 concatenation using +
domainnameoperator+= (const domainname &dom)
 concatenation using +=
domainnameoperator= (const domainname &nam)
 assignment
domainnameoperator= (const char *buff)
 assignment from human-readable text
bool operator== (const domainname &nam) const
 equality test
bool operator> (const domainname &dom) const
 parent-child test
bool operator>= (const domainname &dom) const
 parent-child test
domainname to (int labels) const
 domain-name portion
std::string torelstring (const domainname &root) const
 return relative representation
std::string tostring () const
 convert to human-readable string

Private Attributes

unsigned char * domain

Detailed Description

class representing a domain name

This class represents a domain name. It offers functions to add domain names together, retrieving labels from the domainname, and converting it to human-readable strings and the binary format used in DNS messages.

Constructor & Destructor Documentation

domainname::domainname ( )

default constructor

This constructor sets the domain name to ".", the root domain.

domainname::domainname ( const char *  text,
const domainname origin 
)

constructor from human-readable text

This constructor takes a domain name in human-readable notation, e.g. "www.acdam.net", and an origin. If a relative domain name is given, it will be considered relative to the specified origin.

Parameters
textHuman-readable domain name
originOrigin to which relative domain names are relative
domainname::domainname ( const char *  text,
_cdomain  origin = (unsigned char*)"" 
)

constructor from human-readable text

This constructor takes a domain name in human-readable notation, e.g. "www.acdam.net", and optionally an origin. The origin is in the binary _domain format as found in DNS messages. In case of a relative domain name, it is considered relative to this origin (or to the root domain, if no origin is given).

Parameters
textHuman-readable domain name
originOrigin, in binary format, to which relative domain names are relative
domainname::domainname ( message_buff buff,
int  ix 
)

constructor from data in a DNS message

This constructor takes a DNS message, stored in a message_buff structor, and an offset in this message where the domain name is to begin. This function will decompress the domain name if nessecary.

Parameters
buffA DNS message
ixOffset in the DNS message
domainname::domainname ( bool  is_binary,
const unsigned char *  dom 
)

constructor from binary domain name

This constructor takes a domain name in binary form. Since a domain name in binary form is a char *, just like a human-readable domain name, this contructor takes a boolean value as well to prevent it from being ambiguous. The value of the boolean is silently ignored.

Parameters
is_binaryIgnored
domThe binary domain name
domainname::domainname ( const domainname nam)

copy constructor

This constructor just copies the given domainname structore.

Parameters
namThe domain name
domainname::~domainname ( )

destructor

Frees resources associated with the domain name

Member Function Documentation

_domain domainname::c_str ( ) const

binary representation of domain

Returns the binary representation of the domain name as it would appear in DNS messages (though in uncompressed form).

Returns
Binary representation for the domain name
std::string domainname::canonical ( ) const

RFC 2345 canonical form.

Returns the RFC 2535 canonical form of the domain name. The canonical form is a unique binary representation of a domain name that is used for checksummming domain names.

Returns
The Canonical form of the RR
domainname domainname::from ( int  ix) const

domain-name portion

Returns the portion of the domain name from the label specified by ix.

Parameters
ixLabel index (inclusive)
Returns
The domain name portion
See Also
nlabels(), to()
std::string domainname::label ( int  ix) const

label in domain name

Returns a label in the domain name. This is just plain human-readable text. It does not contain dots.

Parameters
ixLabel index (0 <= ix < nlabels())
Returns
The label at the specified index
See Also
nlabels()
int domainname::len ( ) const

length of binary representation

Returns the length, in bytes, also counting the terminating \r \0 character, of the binary representation of the domain name.

Returns
Length of binary representation
int domainname::ncommon ( const domainname dom) const

check label match count

Returns the number of labels the two domain names have in common at their ends; for example this returns 2 for www.acdam.net and www.foo.acdam.net .

Parameters
domThe domain name to check with
Returns
Number of common labels
See Also
nlabels()
int domainname::nlabels ( ) const

number of labels of the domain name

Returns the number of labels in the domain name, also counting the root '\0' label at the end,

Returns
Number of labels
See Also
label()
bool domainname::operator!= ( const domainname nam) const

negatice equality test

Tests whether the two domain names are the same. Comparison is done in a case-insensitive way.

Parameters
namDomain name to compare with
Returns
True if the domain names are not the same
domainname & domainname::operator+ ( const domainname dom)

concatenation using +

Appends two domain names, returning a third. The first domain name becomes a child domain of the second one.

Parameters
domThe domain name to append
Returns
The result of the concaternation.
domainname & domainname::operator+= ( const domainname dom)

concatenation using +=

Appends another domain name to the current domain name. The current domain name becomes a child domain of the appended domain name, for example, domainname("www") += domainname("acdam.net") would become www.acdam.net.

Parameters
domDomain name to append
Returns
The resulting domain name
See Also
operator+
domainname & domainname::operator= ( const domainname nam)

assignment

Assigns another domain name

Parameters
namThe domain name to assign
Returns
The assigned domain name
domainname & domainname::operator= ( const char *  buff)

assignment from human-readable text

Assigns another domain name, given in human-readable text. Relative domain names are considered relative to the root domain

Parameters
buffThe domain name in human-readable text
Returns
The assigned domain name
bool domainname::operator== ( const domainname nam) const

equality test

Tests whether the two domain names are the same. Comparison is done in a case-insensitive way.

Parameters
namDomain name to compare with
Returns
True if the domain names are the same
bool domainname::operator> ( const domainname dom) const

parent-child test

Tests whether we are the child domain of the given domain name. Returns false if the child and parent domain names given are the same.

Parameters
domDomain name to test
Returns
True if we are the parent
See Also
operator>=
bool domainname::operator>= ( const domainname dom) const

parent-child test

Tests whether we are the child domain of the given domain name. This function also returns true if the child and parent domains are the same.

Parameters
domDomain name to test
Returns
True if we are the parent
See Also
operator>
domainname domainname::to ( int  labels) const

domain-name portion

Returns a domain name consisting of the first label labels of the given domain name.

Parameters
labelsNumber of labels
Returns
The domain name portion
See Also
from()
std::string domainname::torelstring ( const domainname root) const

return relative representation

Returns a string representation of the domain name, relative to the given origin. If the domain is not a child of the given root, the complete, absolte domain name is returned. If we are the domain name queried itself, an "@" is returned.

Parameters
rootDomain name this domain is relative to
Returns
Relative string representation
See Also
tostring()
std::string domainname::tostring ( ) const

convert to human-readable string

Converts the domain name to a human-readable string. The string will always have a trailing dot.

Returns
Human-readable domain name
See Also
tocstr()

Member Data Documentation

unsigned char* domainname::domain
private

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