DESCRIPTION

A DNS domain name is a sequence of components.
Each component is a string of bytes, of length between 1 and 63 inclusive.
The total length of all the components, plus the number of components, is
between 0 and 254 inclusive.

A component is packet-encoded as a self-delimiting sequence of bytes, the
first byte being the length of the component, the remaining bytes being the
bytes in the component.
A DNS domain name is packet-encoded as a sequence of bytes obtained by
concatenating the encodings of the components and a terminating \0.
Beware that \0 can appear inside components.
The total length of a packet-encoded DNS domain name is between 1 and 255
inclusive.

dns_domain_length
returns the number of bytes in the packet-encoded DNS name that
dn
points to.

dns_domain_equal
compares the packet-encoded DNS names that
dn
and
dn2
point to.
It returns 1 if the names are the same, 0 if not.
Lowercase ASCII and uppercase ASCII are considered the same.

dns_domain_copy
reads the packet-encoded DNS name that
in
points to, copies the name into dynamically allocated space, points
dn
to that space, and returns 1.
If not enough memory is available,
dns_domain_copy
returns 0, setting
errno
appropriately, and leaves
dn
alone.

You can call
dns_domain_copy
repeatedly.
If
dn
is nonzero,
dns_domain_copy
frees it before replacing it with the new pointer. Initially
dn
must be 0.

dns_domain_fromdot
reads a dot-encoded DNS name of length
len
from
buf,
copies the name in packet-encoded format into dynamically allocated space,
points
dn
to that space, and returns 1.