Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

poslib/domainfn.h File Reference

domain-name manipulation More...

Go to the source code of this file.


Classes

class   domainname
  class representing a domain name More...

struct   dom_compr_info
  internal domain name compression structure More...


Defines

#define  DOM_LEN   255
  Maximum length of binary domain name.

#define  DOMLABEL_LEN   63
  Maximum length of domain name label.

#define  tocstr()   tostring().c_str()
  convert to human-readable character array


Typedefs

typedef char  _sdomain [DOM_LEN]
  static binary domain name


Functions

void *  memdup (const void *src, int len)
  dump memory

int  dom_comprlen (message_buff &buff, int ix)
  compressed length

_domain  dom_uncompress (message_buff &buff, int ix)
  uncompress domain name

void  dom_write (stl_string &ret, _domain dom, stl_slist(dom_compr_info)&compr)
  compress domain name

_domain  domfrom (_domain dom, int ix)
  domain name portion pointer

bool  domisparent (_domain parent, _domain child)
  test for parent<->child relationship

int  domlen (const _domain dom)
  length of binary domain name

_domain  domdup (const _domain dom)
  dynamic copy of binary domain name

bool  domlcmp (const _domain dom1, const _domain dom2)
  compare binary domain labels

bool  domcmp (const _domain dom1, const _domain dom2)
  compare binary domain names

void  domcat (_domain target, const _domain src)
  domain name concatenation

void  domcpy (_domain res, const _domain src)
  static copy of binary domain name

void  domfromlabel (_domain dom, const char *label, int len=-1)
  create domain name from label

stl_string  dom_tostring (const _domain dom)
  to-string conversion

int  dom_nlabels (const _domain dom)
  number of labels

stl_string  dom_label (const _domain dom, int label)
  label of domain name

const _domain  dom_plabel (const _domain dom, int label)
  label of domain name

int  domncommon (const _domain dom1, const _domain dom2)
  check label match count

int  domccmp (const _domain _dom1, const _domain _dom2)
  compare domain names

void  domto (_domain ret, const _domain src, int labels)
  return domain name portion


Detailed Description

domain-name manipulation

This source file offers various functions for domain-name manipulation. Firstly, it offers the domainname class, which is a C++ class representing a domain name. Secondly, it offers various functions for reading and writing domain names from and to DNS messages, and thirdly, it offers functions which can be used to manipulate domain names as they would appear in DNS messages. These functions use the _domain typedef to represent such a domain name. Usually you will not need to call these yourself.

Definition in file domainfn.h.


Define Documentation

#define DOM_LEN   255
 

Maximum length of binary domain name.

This is the maximum length of a decompressed binary domain name.

Definition at line 47 of file domainfn.h.

#define DOMLABEL_LEN   63
 

Maximum length of domain name label.

This is the maximum length of a domain name label, not including the length byte (in binary data), or the trailing ' ' label.

Definition at line 55 of file domainfn.h.

 
#define tocstr  )     tostring().c_str()
 

convert to human-readable character array

Converts the domain name to a human-readable character array. It will also have a trailing dot. This is static data, so if you want a copy, use a strdup().

See also:
tostring()

Definition at line 256 of file domainfn.h.


Typedef Documentation

typedef char _sdomain[DOM_LEN]
 

static binary domain name

Use this typedef if you want to declare a static _domain variable.

Definition at line 334 of file domainfn.h.


Function Documentation

int dom_comprlen message_buff buff,
int  ix
 

compressed length

This function returns the compressed length - that is, the length the domain takes up in the DNS message - of a domain name.

Parameters:
buff  A DNS messagee
ix  Index of the domain name
Returns:
Length in bytes the domain name takes up.

stl_string dom_label const _domain  dom,
int  label
 

label of domain name

Returns a label of the domain name in human-readable form.

Parameters:
dom  The domain name
label  Label index (0 <= label < #dom_nlabels(dom))
Returns:
The label
See also:
dom_nlabels()

int dom_nlabels const _domain  dom  ) 
 

number of labels

Returns the number of labels, also counting the empty ' ' label, of the domain name.

Parameters:
dom  The domain name
Returns:
Number of labels

const _domain dom_plabel const _domain  dom,
int  label
 

label of domain name

Returns a label of the domain name as a pointer to the position in the domain.

Parameters:
dom  The domain name
label  Label index (0 < label < #dom_nlabels(dom))
Returns:
The label
See also:
dom_nlabels()

stl_string dom_tostring const _domain  dom  ) 
 

to-string conversion

Converts the domain name to a human-readable string. Contains the trailing dot.

Parameters:
dom  The domain name
Returns:
Human-readable string.

_domain dom_uncompress message_buff buff,
int  ix
 

uncompress domain name

This function decompresses a domain name in a DNS message. It returns the binary, decompressed data describing the domain name.

Parameters:
buff  A DNS message
ix  Index of the domain name
Returns:
Uncompressed binary domain name (dynamically allocated)

void dom_write stl_string &  ret,
_domain  dom,
stl_slist(dom_compr_info)&  compr
 

compress domain name

This function writes a domain name to the end of a DNS message, compressing it if possible.

Parameters:
ret  A (partial) DNS message
dom  Domain name to write
compr  List of earlier compressed domain names

void domcat _domain  target,
const _domain  src
 

domain name concatenation

Appends src to target. Since it does not re-allocate memory, Make sure that target can hold at least #DOM_MAX bytes.

Parameters:
target  Target
src  Source

int domccmp const _domain  _dom1,
const _domain  _dom2
 

compare domain names

This function offers a way to compare domain names the way the strcmp do. It operates in such a way that child domains are greater than parent domains, and for for other domains, the first non-matching domain label is compared using strcmpi. For example, www.foo.acdam.net is greater than bar.acdam.net because foo is greater than bar which is the first non-matching label after the common acdam.net part of the domain names.

Parameters:
dom1  First domain name
dom2  Second domain name
Returns:
<0, 0 or >0 if the first domain name is smaller than, equal to, or larger than the second one, respectively.

bool domcmp const _domain  dom1,
const _domain  dom2
 

compare binary domain names

Checks whether both binary domain names are equal.

Parameters:
dom1  First domain name
dom2  Second domain name
Returns:
true if the domain names are equal

void domcpy _domain  res,
const _domain  src
 

static copy of binary domain name

Makes a static copy of a domain name. Make sure that res can hold at least #DOM_MAX bytes.

Parameters:
res  Target
src  Source
See also:
domdup()

_domain domdup const _domain  dom  ) 
 

dynamic copy of binary domain name

Makes a dynamically allocated copy of a domain name.

Parameters:
dom  Domain name
Returns:
Copy of domain name
See also:
domcpy()

_domain domfrom _domain  dom,
int  ix
 

domain name portion pointer

Returns a pointer to the portion of the domain name from the ix'th label.

Parameters:
dom  Domain name
ix  Index
Returns:
Domain name portion

void domfromlabel _domain  dom,
const char *  label,
int  len = -1
 

create domain name from label

Creates a domain name containing just one label: the string argument given. If a length is given, only the first few characters of the string are used. Make sure that dom can hold at least #DOM_MAX bytes.

Parameters:
dom  Result
label  String label
len  If given, length of string label (default: strlen(label)).

bool domisparent _domain  parent,
_domain  child
 

test for parent<->child relationship

Tests whether the first domain name is a parent of the second domain name.

Parameters:
parent  Parent domain
child  Child domain
Returns:
True if parent is indeed a parent of child .

bool domlcmp const _domain  dom1,
const _domain  dom2
 

compare binary domain labels

Checks whether both binary domain name start with the same label.

Parameters:
dom1  First domain name
dom2  Second domain name
Returns:
true if the domain names start with the same label

int domlen const _domain  dom  ) 
 

length of binary domain name

Returns the length, in bytes, including the trailing ' ' character, of the domain name.

Parameters:
dom  Domain name
Returns:
Length of the domain name

int domncommon const _domain  dom1,
const _domain  dom2
 

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:
dom  The domain name to check with
Returns:
Number of common labels
See also:
nlabels()

void domto _domain  ret,
const _domain  src,
int  labels
 

return domain name portion

Returns a domain name consisting of the first label labels of the given domain name. The ret buffer should be large enough to hold the result to prevent a buffer overflow.

Parameters:
ret  Result buffer
src  Source domain
labels  Number of labels to include

void* memdup const void *  src,
int  len
 

dump memory

This is an alternative to the c strdup() function, but instead it can dump any type of memory, as long as you give the right length.

Parameters:
src  Source memory location
len  Length of data
Returns:
A newly-allocated copy of src.

Generated on Fri Dec 24 19:55:15 2004 for Poslib by doxygen 1.3.7