---
name: "dns_packet"
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_packet"
---

# dns\_packet(3)

The dns\_packet library interface

## NAME

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

## SYNOPSIS

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

newpos = **dns\_packet\_copy**(buf, len, pos, out, outlen);\
\
   char \**buf;*\
   unsigned int *len*;\
   unsigned int *pos*;\
   unsigned int *newpos*;\
   char \**out;*\
   unsigned int *outlen*;

newpos = **dns\_packet\_getname**(buf, len, pos, &dn);\
\
   char \**buf;*\
   unsigned int *len*;\
   unsigned int *pos*;\
   unsigned int *newpos*;\
   char \**dn* = 0;

newpos = **dns\_packet\_skipname**(buf, len, pos);\
\
   char \**buf;*\
   unsigned int *len*;\
   unsigned int *pos*;\
   unsigned int *newpos*;

## DESCRIPTION

**dns\_packet\_copy** reads *outlen* bytes from position *pos* of a DNS packet stored at *buf*, copies the bytes into *out*, and returns *pos* + *outlen*. However, if reading the bytes would require reading past the first *len* bytes of the packet, **dns\_packet\_copy** returns 0, setting *errno* appropriately.

**dns\_packet\_getname** reads a compressed domain name from position *pos* of a DNS packet stored at *buf*, copies the name into *dn*, and returns the position in the packet immediately after the name.

If the name is misformatted, or if reading the name would require reading past the first *len* bytes of the packet, or if there is not enough memory for *dn*, **dns\_packet\_getname** returns 0, setting *errno* appropriately, and leaves *dn* alone.

**dns\_packet\_skipname** is like **dns\_packet\_getname** but discards the resulting domain name. It does not allocate memory.

Beware that, even if **dns\_packet\_skipname** returns nonzero, a future **dns\_packet\_getname** from the same position may fail: it may run out of memory, or encounter a format error not detected by **dns\_packet\_skipname**.

## SEE ALSO

[dns\_domain(3)](/dns_domain/3.md), [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\_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
