---
name: "dns_domain_copy"
section: "3"
platform: "linux"
package: "libdjbdns1-dev"
version: "1.05-5+b1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/dns_domain"
---

# dns\_domain\_copy(3)

The dns\_domain library interface

Part of [dns\_domain(3)](/dns_domain/3.md).

## NAME

dns\_domain\_\* - The dns\_domain library interface

## SYNOPSIS

**#include \<dns.h\>**

len = **dns\_domain\_length**(dn);\
\
   char \**dn;*\
   unsigned int *len*;

**dns\_domain\_equal**(dn, dn2);\
\
   char \**dn;*\
   char \**dn2;*

**dns\_domain\_copy**(&dn, in);\
\
   char \**dn* = 0;\
   char \**in;*

**dns\_domain\_fromdot**(&dn, buf, len);\
\
   char \**dn* = 0;\
   char \**buf;*\
   unsigned int *len*;

## 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.

If *buf* violates DNS name length restrictions, or if not enough memory is available, **dns\_domain\_fromdot** leaves *dn* alone and returns 0, setting *errno* appropriately.

Like **dns\_domain\_copy**, **dns\_domain\_fromdot** frees *dn* before changing it, if *dn* is nonzero.

## SEE ALSO

[dns\_ip4(3)](/dns_ip4/3.md), [dns\_ip4\_qualify(3)](/dns_ip4_qualify/3.md), [dns\_mx(3)](/dns_mx/3.md), [dns\_name4(3)](/dns_name4/3.md), [dns\_packet(3)](/dns_packet/3.md), [dns\_random(3)](/dns_random/3.md), [dns\_transmit(3)](/dns_transmit/3.md), [dns\_txt(3)](/dns_txt/3.md)

http://cr.yp.to/djbdns/blurb/library.html
