---
name: "resparse"
section: "3bind"
platform: "linux"
package: "bind-dev"
version: "1:8.4.7-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/resparse"
---

# resparse(3bind)

parse and manipulate DNS resolver responses

## NAME

res\_parse, res\_copy, res\_print, res\_free - parse and manipulate DNS resolver responses

## SYNOPSIS

**#include rr.h**\

res\_response \* **res\_parse(msg)** char \*msg;

res\_response \* **res\_copy(resp)** res\_response \*resp;

**res\_print(resp)** res\_response \*resp;

**res\_free(resp)** res\_response \*resp;

## DESCRIPTION

These routines are used for parsing the response from a call to the DNS *resolver* routines into a C structure suitable for programmer use, and to manipulate such structures.

**Res\_parse** takes the result of a call to res\_query or res\_search. This is then parsed into an appropriate structure, and domain names unpacked into standard null-terminated C strings. It then returns a pointer to this structure.

**Res\_copy** takes a pointer to a **res\_response** structure, makes a copy of it and returns a pointer to the copy.

**Res\_print** prints out the specified **res\_response** structure, using a similar style to *nslookup*.

**Res\_free** takes a pointer to a **res\_response** structure, frees all memory allocated to it and clears the counts of the number of records of each type present.

## DATA STRUCTURES

The structures used are as follows:

**res\_response {** **HEADER header;** The header as defined in \<**arpa/nameser.h**\>. **s\_question \*\*question;** Pointer to an array of question records. **s\_rr \*\*answer;** Pointer to an array of answer resource records. **s\_rr \*\*authority;** Pointer to an array of nameserver resource records. **s\_rr \*\*additional;** Pointer to an array of additional resource records (the addresses of the authoritative nameservers). **}**

**s\_question {** **char \*qname;** The name that the query was sent for. **u\_short qtype**\
 **u\_short qclass** The type and class of query, as defined in \<**arpa/nameser.h**\>. **}**

**s\_rr {** **char \*name;** The name of the resource record. **u\_short type**\
 **u\_short class** The type and class of the record, as defined in \<**arpa/nameser.h**\>. **u\_long ttl** How long (in seconds) this record may be cached. **u\_long dlen;** The length of the type-specific data.\
 This need not be the same as the size of the *unpacked* data - particularly for domain names. **union u\_rdata rdata;** The type-specific data (see **rr.h** for details). **}**

## RETURN VALUES

**Res\_parse** and **res\_copy** will return a pointer to the new structure, or a NULL pointer in case of errors.\
 **Res\_print** and **res\_free** do not return anything.

## WARNINGS

**Res\_parse** now returns a pointer to a dynamically assigned area, (previous releases used a static area which which would be overwritten by subsequent calls).\
 The pointer returned by **res\_parse** should be  freed using **res\_free** (contrary to the instructions with earlier releases of this library).

If **res\_print** is called with a pointer that has been freed, it will (probably) print out an "empty" header.\
 This is a Bad Thing to do anyway!

## FILES

**/usr/local/lib/libresparse.a**

## SEE ALSO

[resolver(3)](/resolver/3.md), [gethostbyname(3)](/gethostbyname/3.md)\
 *DNS and BIND*

## AUTHOR

Dave Shield	\<D.T.Shield@csc.liv.ac.uk\>
