---
name: "ldns_buffer"
section: "3"
platform: "linux"
package: "ldns"
version: "1.9.2-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ldns_buffer"
---

# ldns\_buffer(3)

buffers

## NAME

ldns\_buffer, ldns\_buffer\_new, ldns\_buffer\_new\_frm\_data, ldns\_buffer\_clear, ldns\_buffer\_printf, ldns\_buffer\_free, ldns\_buffer\_copy, ldns\_buffer\_export, ldns\_buffer\_export2str, ldns\_buffer2str - buffers

## SYNOPSIS

\#include \<stdint.h\>\
 \#include \<stdbool.h\>\

\#include \<ldns/ldns.h\>

ldns\_buffer\* ldns\_buffer\_new(size\_t capacity);

void ldns\_buffer\_new\_frm\_data(ldns\_buffer \*buffer, const void \*data, size\_t size);

void ldns\_buffer\_clear(ldns\_buffer \*buffer);

int ldns\_buffer\_printf(ldns\_buffer \*buffer, const char \*format, ...);

void ldns\_buffer\_free(ldns\_buffer \*buffer);

void ldns\_buffer\_copy(ldns\_buffer\* result, const ldns\_buffer\* from);

void\* ldns\_buffer\_export(ldns\_buffer \*buffer);

char\* ldns\_buffer\_export2str(ldns\_buffer \*buffer);

char\* ldns\_buffer2str(ldns\_buffer \*buffer);

## DESCRIPTION

*ldns\_buffer*\
 implementation of buffers to ease operations\

ldns\_buffers can contain arbitrary information, per octet. You can write\
 to the current end of a buffer, read from the current position, and\
 access any data within it.\

Example use of buffers is in the source code of \\ref host2str.c\
 struct ldns\_struct\_buffer\
 {\
\
 	**The current position used for reading/writing:** \
\
 	size\_t   \_position;\

	**The read/write limit:**\
\
 	size\_t   \_limit;\

	**The amount of data the buffer can contain:**\
\
 	size\_t   \_capacity;\

	**The data contained in the buffer:**\
\
 	uint8\_t \*\_data;\

	**If the buffer is fixed it cannot be resized:**\
\
 	unsigned \_fixed : 1;\

	/\*\* The current state of the buffer. If writing to the buffer fails\
\
 	 \* for any reason, this value is changed. This way, you can perform\
\
 	 \* multiple writes in sequence and check for success afterwards. \*/\
\
 	ldns\_status \_status;\
 };\
 typedef struct ldns\_struct\_buffer ldns\_buffer;

*ldns\_buffer\_new*() creates a new buffer with the specified capacity.

.br **capacity**: the size (in bytes) to allocate for the buffer .br Returns the created buffer

*ldns\_buffer\_new\_frm\_data*() creates a buffer with the specified data.  The data IS copied and MEMORY allocations are done.  The buffer is not fixed and can be resized using buffer\_reserve().

.br **buffer**: pointer to the buffer to put the data in .br **data**: the data to encapsulate in the buffer .br **size**: the size of the data

*ldns\_buffer\_clear*() clears the buffer and make it ready for writing.  The buffer's limit is set to the capacity and the position is set to 0. .br **buffer**: the buffer to clear

*ldns\_buffer\_printf*() prints to the buffer, increasing the capacity if required using buffer\_reserve(). The buffer's position is set to the terminating '\\\\0' Returns the number of characters written (not including the terminating '\\\\0') or -1 on failure.

*ldns\_buffer\_free*() frees the buffer. .br **\*buffer**: the buffer to be freed .br Returns void

*ldns\_buffer\_copy*() Copy contents of the from buffer to the result buffer and then flips  the result buffer. Data will be silently truncated if the result buffer is too small. .br **\*result**: resulting buffer which is copied to. .br **\*from**: what to copy to result.

*ldns\_buffer\_export*() Makes the buffer fixed and returns a pointer to the data.  The caller is responsible for free'ing the result. .br **\*buffer**: the buffer to be exported .br Returns void

*ldns\_buffer\_export2str*() Exports and returns the data in the buffer as a null terminated char \* string. The returned string must be freed by the caller. The buffer must be in write modus and may thus not have been flipped. The buffer is fixed after this function returns.

.br **buffer**: buffer containing char \* data .br Returns null terminated char \* data, or NULL on error

*ldns\_buffer2str*() Returns a copy of the data in the buffer as a null terminated char \* string. The returned string must be freed by the caller. The buffer must be in write modus and may thus not have been flipped.

.br **buffer**: buffer containing char \* data .br Returns null terminated char \* data, or NULL on error

## AUTHOR

The ldns team at NLnet Labs.

## REPORTING BUGS

Please report bugs to dns-team@nlnetlabs.nl or on GitHub at https://github.com/NLnetLabs/ldns/issues

## COPYRIGHT

Copyright (c) 2004 - 2006 NLnet Labs.

Licensed under the BSD License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

## SEE ALSO

*ldns\_buffer\_flip*, *ldns\_buffer\_rewind*, *ldns\_buffer\_position*, *ldns\_buffer\_set\_position*, *ldns\_buffer\_skip*, *ldns\_buffer\_limit*, *ldns\_buffer\_set\_limit*, *ldns\_buffer\_capacity*, *ldns\_buffer\_set\_capacity*, *ldns\_buffer\_reserve*, *ldns\_buffer\_at*, *ldns\_buffer\_begin*, *ldns\_buffer\_end*, *ldns\_buffer\_current*, *ldns\_buffer\_remaining\_at*, *ldns\_buffer\_remaining*, *ldns\_buffer\_available\_at*, *ldns\_buffer\_available*, *ldns\_buffer\_status*, *ldns\_buffer\_status\_ok*, *ldns\_buffer\_write\_at*, *ldns\_buffer\_write*, *ldns\_buffer\_write\_string\_at*, *ldns\_buffer\_write\_string*, *ldns\_buffer\_write\_u8\_at*, *ldns\_buffer\_write\_u8*, *ldns\_buffer\_write\_u16\_at*, *ldns\_buffer\_write\_u16*, *ldns\_buffer\_read\_at*, *ldns\_buffer\_read*, *ldns\_buffer\_read\_u8\_at*, *ldns\_buffer\_read\_u8*, *ldns\_buffer\_read\_u16\_at*, *ldns\_buffer\_read\_u16*, *ldns\_buffer\_read\_u32\_at*, *ldns\_buffer\_read\_u32*, *ldns\_buffer\_write\_u32*, *ldns\_buffer\_write\_u32\_at*. And **perldoc Net::DNS**, **RFC1034**, **RFC1035**, **RFC4033**, **RFC4034**  and **RFC4035**.

## REMARKS

This manpage was automatically generated from the ldns source code.
