buffer.c File Reference
`#include "config.h"`
`#include "log.h"`
`#include "wire/buffer.h"`
`#include <string.h>`

Go to the source code of this file.

## Functions

buffer_type * | buffer_create (size_t capacity)
void | buffer_clear (buffer_type *buffer)
void | buffer_flip (buffer_type *buffer)
size_t | buffer_position (buffer_type *buffer)
void | buffer_set_position (buffer_type *buffer, size_t pos)
void | buffer_skip (buffer_type *buffer, ssize_t count)
size_t | buffer_read_dname (buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
int | buffer_skip_dname (buffer_type *buffer)
int | buffer_skip_rr (buffer_type *buffer, unsigned qrr)
size_t | buffer_limit (buffer_type *buffer)
void | buffer_set_limit (buffer_type *buffer, size_t limit)
size_t | buffer_capacity (buffer_type *buffer)
uint8_t * | buffer_at (buffer_type *buffer, size_t at)
uint8_t * | buffer_begin (buffer_type *buffer)
uint8_t * | buffer_current (buffer_type *buffer)
size_t | buffer_remaining (buffer_type *buffer)
int | buffer_available (buffer_type *buffer, size_t count)
void | buffer_write_u16_at (buffer_type *buffer, size_t at, uint16_t data)
void | buffer_write (buffer_type *buffer, const void *data, size_t count)
void | buffer_write_u8 (buffer_type *buffer, uint8_t data)
void | buffer_write_u16 (buffer_type *buffer, uint16_t data)
void | buffer_write_u32 (buffer_type *buffer, uint32_t data)
void | buffer_write_rdf (buffer_type *buffer, ldns_rdf *rdf)
int | buffer_write_rr (buffer_type *buffer, ldns_rr *rr)
void | buffer_read (buffer_type *buffer, void *data, size_t count)
uint8_t | buffer_read_u8 (buffer_type *buffer)
uint16_t | buffer_read_u16 (buffer_type *buffer)
uint32_t | buffer_read_u32 (buffer_type *buffer)
uint16_t | buffer_pkt_id (buffer_type *buffer)
void | buffer_pkt_set_random_id (buffer_type *buffer)
uint16_t | buffer_pkt_flags (buffer_type *buffer)
void | buffer_pkt_set_flags (buffer_type *buffer, uint16_t flags)
int | buffer_pkt_qr (buffer_type *buffer)
void | buffer_pkt_set_qr (buffer_type *buffer)
void | buffer_pkt_clear_qr (buffer_type *buffer)
ldns_pkt_opcode | buffer_pkt_opcode (buffer_type *buffer)
void | buffer_pkt_set_opcode (buffer_type *buffer, ldns_pkt_opcode opcode)
int | buffer_pkt_aa (buffer_type *buffer)
void | buffer_pkt_set_aa (buffer_type *buffer)
int | buffer_pkt_tc (buffer_type *buffer)
int | buffer_pkt_rd (buffer_type *buffer)
int | buffer_pkt_ra (buffer_type *buffer)
int | buffer_pkt_ad (buffer_type *buffer)
int | buffer_pkt_cd (buffer_type *buffer)
ldns_pkt_rcode | buffer_pkt_rcode (buffer_type *buffer)
void | buffer_pkt_set_rcode (buffer_type *buffer, ldns_pkt_rcode rcode)
const char * | buffer_rcode2str (ldns_pkt_rcode rcode)
uint16_t | buffer_pkt_qdcount (buffer_type *buffer)
void | buffer_pkt_set_qdcount (buffer_type *buffer, uint16_t count)
uint16_t | buffer_pkt_ancount (buffer_type *buffer)
void | buffer_pkt_set_ancount (buffer_type *buffer, uint16_t count)
uint16_t | buffer_pkt_nscount (buffer_type *buffer)
void | buffer_pkt_set_nscount (buffer_type *buffer, uint16_t count)
uint16_t | buffer_pkt_arcount (buffer_type *buffer)
void | buffer_pkt_set_arcount (buffer_type *buffer, uint16_t count)
void | buffer_pkt_query (buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
void | buffer_pkt_notify (buffer_type *buffer, ldns_rdf *qname, ldns_rr_class qclass)
void | buffer_cleanup (buffer_type *buffer)

## Variables

ods_lookup_table | ods_rcode_str []

## Function Documentation

## buffer_at()

uint8_t * buffer_at | ( | buffer_type * | buffer,
|  | size_t | at )

Return a pointer to the data at the indicated position.

Definition at line 413 of file buffer.c.

References buffer_struct::data.

Referenced by buffer_begin(), buffer_current(), and tsig_rr_update().

## buffer_available()

int buffer_available | ( | buffer_type * | buffer,
|  | size_t | count )

Check if the buffer has enough bytes available.

Definition at line 487 of file buffer.c.

References buffer_struct::position.

Referenced by buffer_read(), buffer_read_dname(), buffer_skip_dname(), buffer_skip_rr(), buffer_write(), buffer_write_rr(), edns_rr_parse(), query_add_rr(), and tsig_rr_parse().

## buffer_begin()

uint8_t * buffer_begin | ( | buffer_type * | buffer | ) |

Return a pointer to the data at the beginning of the buffer.

Definition at line 426 of file buffer.c.

References buffer_at().

Referenced by sock_handle_udp().

## buffer_capacity()

size_t buffer_capacity | ( | buffer_type * | buffer | ) |

Get the buffer's capacity.

Definition at line 401 of file buffer.c.

References buffer_struct::capacity.

Referenced by query_prepare(), and tcp_conn_read().

## buffer_cleanup()

void buffer_cleanup | ( | buffer_type * | buffer | ) |

Clean up buffer.

Definition at line 1145 of file buffer.c.

References buffer_struct::data.

Referenced by query_cleanup(), and xfrhandler_cleanup().

## buffer_clear()

void buffer_clear | ( | buffer_type * | buffer | ) |

Clear the buffer and make it ready for writing.

Definition at line 99 of file buffer.c.

References buffer_struct::capacity, buffer_struct::limit, and buffer_struct::position.

Referenced by query_prepare(), query_reset(), sock_handle_tcp_write(), and tcp_conn_ready().

## buffer_create()

buffer_type * buffer_create | ( | size_t | capacity | ) |

Create a new buffer with the specified capacity.

Definition at line 78 of file buffer.c.

References buffer_struct::capacity, buffer_struct::data, buffer_struct::fixed, buffer_struct::limit, and buffer_struct::position.

Referenced by query_create(), tcp_conn_create(), and xfrhandler_create().

## buffer_current()

uint8_t * buffer_current | ( | buffer_type * | buffer | ) |

Return a pointer to the data at the buffer's current position.

Definition at line 438 of file buffer.c.

References buffer_at(), and buffer_struct::position.

Referenced by buffer_read_dname(), query_process(), sock_handle_tcp_read(), sock_handle_tcp_write(), tcp_conn_read(), tcp_conn_write(), and tsig_rr_parse().

## buffer_flip()

void buffer_flip | ( | buffer_type * | buffer | ) |

Flip the buffer and make it ready for reading.

Definition at line 112 of file buffer.c.

References buffer_struct::limit, and buffer_struct::position.

Referenced by notify_send(), sock_handle_tcp_read(), sock_handle_tcp_write(), and sock_handle_udp().

## buffer_limit()

size_t buffer_limit | ( | buffer_type * | buffer | ) |

Get the buffer's limit.

Definition at line 373 of file buffer.c.

References buffer_struct::limit.

Referenced by buffer_read_dname(), query_prepare(), query_process(), and tsig_rr_update().

## buffer_pkt_aa()

int buffer_pkt_aa | ( | buffer_type * | buffer | ) |

Get AA bit from buffer.

Definition at line 870 of file buffer.c.

References AA.

## buffer_pkt_ad()

int buffer_pkt_ad | ( | buffer_type * | buffer | ) |

Get AD bit from buffer.

Definition at line 930 of file buffer.c.

References AD.

## buffer_pkt_ancount()

uint16_t buffer_pkt_ancount | ( | buffer_type * | buffer | ) |

Get ANCOUNT from buffer.

Definition at line 1018 of file buffer.c.

Referenced by axfr(), ixfr(), soa_request(), and tsig_rr_find().

## buffer_pkt_arcount()

uint16_t buffer_pkt_arcount | ( | buffer_type * | buffer | ) |

Get ARCOUNT from buffer.

Definition at line 1066 of file buffer.c.

Referenced by query_add_optional(), and tsig_rr_find().

## buffer_pkt_cd()

int buffer_pkt_cd | ( | buffer_type * | buffer | ) |

Get CD bit from buffer.

Definition at line 942 of file buffer.c.

References CD.

## buffer_pkt_clear_qr()

void buffer_pkt_clear_qr | ( | buffer_type * | buffer | ) |

Clear QR bit in buffer.

Definition at line 834 of file buffer.c.

References QR_CLR.

## buffer_pkt_flags()

uint16_t buffer_pkt_flags | ( | buffer_type * | buffer | ) |

Get flags from buffer.

Definition at line 786 of file buffer.c.

Referenced by query_prepare().

## buffer_pkt_id()

uint16_t buffer_pkt_id | ( | buffer_type * | buffer | ) |

Get query id from buffer.

Definition at line 751 of file buffer.c.

Referenced by notify_send().

## buffer_pkt_notify()

void buffer_pkt_notify | ( | buffer_type * | buffer,
|  | ldns_rdf * | qname,
|  | ldns_rr_class | qclass )

Make a new notify.

Definition at line 1133 of file buffer.c.

Referenced by notify_send().

## buffer_pkt_nscount()

uint16_t buffer_pkt_nscount | ( | buffer_type * | buffer | ) |

Get NSCOUNT from buffer.

Definition at line 1042 of file buffer.c.

Referenced by tsig_rr_find().

## buffer_pkt_opcode()

ldns_pkt_opcode buffer_pkt_opcode | ( | buffer_type * | buffer | ) |

Get OPCODE from buffer.

Definition at line 846 of file buffer.c.

References OPCODE.

## buffer_pkt_qdcount()

uint16_t buffer_pkt_qdcount | ( | buffer_type * | buffer | ) |

Get QDCOUNT from buffer.

Definition at line 994 of file buffer.c.

Referenced by tsig_rr_find().

## buffer_pkt_qr()

int buffer_pkt_qr | ( | buffer_type * | buffer | ) |

Get QR bit from buffer.

Definition at line 810 of file buffer.c.

References QR.

Referenced by query_process(), and tsig_rr_update().

## buffer_pkt_query()

void buffer_pkt_query | ( | buffer_type * | buffer,
|  | ldns_rdf * | qname,
|  | ldns_rr_type | qtype,
|  | ldns_rr_class | qclass )

Make a new query.

Definition at line 1120 of file buffer.c.

References buffer_pkt_set_flags().

## buffer_pkt_ra()

int buffer_pkt_ra | ( | buffer_type * | buffer | ) |

Get RA bit from buffer.

Definition at line 918 of file buffer.c.

References RA.

## buffer_pkt_rcode()

ldns_pkt_rcode buffer_pkt_rcode | ( | buffer_type * | buffer | ) |

Get RCODE from buffer.

Definition at line 954 of file buffer.c.

References RCODE.

## buffer_pkt_rd()

int buffer_pkt_rd | ( | buffer_type * | buffer | ) |

Get RD bit from buffer.

Definition at line 906 of file buffer.c.

References RD.

## buffer_pkt_set_aa()

void buffer_pkt_set_aa | ( | buffer_type * | buffer | ) |

Set AA bit in buffer.

Definition at line 882 of file buffer.c.

References AA_SET.

Referenced by axfr(), notify_send(), and soa_request().

## buffer_pkt_set_ancount()

void buffer_pkt_set_ancount | ( | buffer_type * | buffer,
|  | uint16_t | count )

Set ANCOUNT in buffer.

Definition at line 1030 of file buffer.c.

References buffer_write_u16_at().

Referenced by axfr(), ixfr(), notify_send(), and soa_request().

## buffer_pkt_set_arcount()

void buffer_pkt_set_arcount | ( | buffer_type * | buffer,
|  | uint16_t | count )

Set ARCOUNT in buffer.

Definition at line 1078 of file buffer.c.

References buffer_write_u16_at().

Referenced by axfr(), ixfr(), query_add_optional(), and soa_request().

## buffer_pkt_set_flags()

void buffer_pkt_set_flags | ( | buffer_type * | buffer,
|  | uint16_t | flags )

Set flags in buffer.

Definition at line 798 of file buffer.c.

References buffer_write_u16_at().

Referenced by buffer_pkt_query(), and query_prepare().

## buffer_pkt_set_nscount()

void buffer_pkt_set_nscount | ( | buffer_type * | buffer,
|  | uint16_t | count )

Set NSCOUNT in buffer.

Definition at line 1054 of file buffer.c.

References buffer_write_u16_at().

Referenced by axfr(), ixfr(), and soa_request().

## buffer_pkt_set_opcode()

void buffer_pkt_set_opcode | ( | buffer_type * | buffer,
|  | ldns_pkt_opcode | opcode )

Set OPCODE in buffer.

Definition at line 858 of file buffer.c.

References OPCODE_SET.

## buffer_pkt_set_qdcount()

void buffer_pkt_set_qdcount | ( | buffer_type * | buffer,
|  | uint16_t | count )

Set QDCOUNT in buffer.

Definition at line 1006 of file buffer.c.

References buffer_write_u16_at().

Referenced by axfr(), and ixfr().

## buffer_pkt_set_qr()

void buffer_pkt_set_qr | ( | buffer_type * | buffer | ) |

Set QR bit in buffer.

Definition at line 822 of file buffer.c.

References QR_SET.

## buffer_pkt_set_random_id()

void buffer_pkt_set_random_id | ( | buffer_type * | buffer | ) |

Set random query id in buffer.

Definition at line 772 of file buffer.c.

References buffer_write_u16_at().

## buffer_pkt_set_rcode()

void buffer_pkt_set_rcode | ( | buffer_type * | buffer,
|  | ldns_pkt_rcode | rcode )

Set RCODE in buffer.

Definition at line 966 of file buffer.c.

References RCODE_SET.

Referenced by axfr(), ixfr(), and soa_request().

## buffer_pkt_tc()

int buffer_pkt_tc | ( | buffer_type * | buffer | ) |

Get TC bit from buffer.

Definition at line 894 of file buffer.c.

References TC.

## buffer_position()

size_t buffer_position | ( | buffer_type * | buffer | ) |

Get the buffer's position.

Definition at line 125 of file buffer.c.

References buffer_struct::position.

Referenced by axfr(), buffer_read_dname(), buffer_write_rr(), edns_rr_parse(), ixfr(), query_add_optional(), query_add_rr(), sock_handle_tcp_read(), tcp_conn_read(), tsig_rr_append(), tsig_rr_find(), and tsig_rr_parse().

## buffer_rcode2str()

const char * buffer_rcode2str | ( | ldns_pkt_rcode | rcode | ) |

Look up a descriptive text by each rcode.

Definition at line 978 of file buffer.c.

References ods_rcode_str.

## buffer_read()

void buffer_read | ( | buffer_type * | buffer,
|  | void * | data,
|  | size_t | count )

Read from buffer.

Definition at line 692 of file buffer.c.

References buffer_available(), buffer_struct::data, and buffer_struct::position.

Referenced by buffer_read_dname().

## buffer_read_dname()

size_t buffer_read_dname | ( | buffer_type * | buffer,
|  | uint8_t * | dname,
|  | unsigned | allow_pointers )

Read dname from buffer.

Definition at line 246 of file buffer.c.

References buffer_available(), buffer_current(), buffer_limit(), buffer_position(), buffer_read(), buffer_set_position(), buffer_skip(), MAX_PACKET_SIZE, and MAXDOMAINLEN.

## buffer_read_u16()

uint16_t buffer_read_u16 | ( | buffer_type * | buffer | ) |

Read uint16_t from buffer.

Definition at line 721 of file buffer.c.

References buffer_struct::position.

Referenced by buffer_skip_rr(), edns_rr_parse(), and tsig_rr_parse().

## buffer_read_u32()

uint32_t buffer_read_u32 | ( | buffer_type * | buffer | ) |

Read uint32_t from buffer.

Definition at line 736 of file buffer.c.

References buffer_struct::position.

Referenced by tsig_rr_parse().

## buffer_read_u8()

uint8_t buffer_read_u8 | ( | buffer_type * | buffer | ) |

Read uint8_t from buffer.

Definition at line 706 of file buffer.c.

References buffer_struct::position.

Referenced by buffer_skip_dname(), and edns_rr_parse().

## buffer_remaining()

size_t buffer_remaining | ( | buffer_type * | buffer | ) |

The number of bytes remaining between the buffer's position and limit.

Definition at line 463 of file buffer.c.

References buffer_struct::position.

Referenced by query_process(), sock_handle_tcp_read(), sock_handle_tcp_write(), sock_handle_udp(), tcp_conn_read(), and tcp_conn_write().

## buffer_set_limit()

void buffer_set_limit | ( | buffer_type * | buffer,
|  | size_t | limit )

Set the buffer's limit.

Definition at line 385 of file buffer.c.

References buffer_struct::limit, and buffer_struct::position.

Referenced by axfr(), ixfr(), query_prepare(), sock_handle_tcp_read(), and tcp_conn_read().

## buffer_set_position()

void buffer_set_position | ( | buffer_type * | buffer,
|  | size_t | pos )

Set the buffer's position.

Definition at line 137 of file buffer.c.

References buffer_struct::position.

Referenced by axfr(), buffer_read_dname(), buffer_write_rr(), edns_rr_parse(), ixfr(), query_add_rr(), query_prepare(), tsig_rr_find(), and tsig_rr_parse().

## buffer_skip()

void buffer_skip | ( | buffer_type * | buffer,
|  | ssize_t | count )

Change the buffer's position.

Definition at line 150 of file buffer.c.

References buffer_struct::position.

Referenced by buffer_read_dname(), buffer_skip_dname(), buffer_skip_rr(), buffer_write_rr(), edns_rr_parse(), query_add_rr(), sock_handle_tcp_read(), sock_handle_tcp_write(), sock_handle_udp(), tcp_conn_read(), tcp_conn_write(), tsig_rr_append(), and tsig_rr_parse().

## buffer_skip_dname()

int buffer_skip_dname | ( | buffer_type * | buffer | ) |

Change the buffer's position so that one dname is skipped.

Definition at line 310 of file buffer.c.

References buffer_available(), buffer_read_u8(), and buffer_skip().

Referenced by buffer_skip_rr(), and tsig_rr_parse().

## buffer_skip_rr()

int buffer_skip_rr | ( | buffer_type * | buffer,
|  | unsigned | qrr )

Change the buffer's position so that one RR is skipped.

Definition at line 342 of file buffer.c.

References buffer_available(), buffer_read_u16(), buffer_skip(), and buffer_skip_dname().

Referenced by tsig_rr_find().

## buffer_write()

void buffer_write | ( | buffer_type * | buffer,
|  | const void * | data,
|  | size_t | count )

Write to buffer.

Definition at line 538 of file buffer.c.

References buffer_available(), buffer_struct::data, and buffer_struct::position.

Referenced by buffer_write_rdf(), query_add_optional(), and tsig_rr_append().

## buffer_write_rdf()

void buffer_write_rdf | ( | buffer_type * | buffer,
|  | ldns_rdf * | rdf )

Write rdf to buffer.

Definition at line 591 of file buffer.c.

References buffer_write().

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

## buffer_write_rr()

int buffer_write_rr | ( | buffer_type * | buffer,
|  | ldns_rr * | rr )

Write rr to buffer.

Definition at line 605 of file buffer.c.

References buffer_available(), buffer_position(), buffer_set_position(), buffer_skip(), buffer_write_rdf(), buffer_write_u16(), buffer_write_u16_at(), and buffer_write_u32().

Referenced by notify_send().

## buffer_write_u16()

void buffer_write_u16 | ( | buffer_type * | buffer,
|  | uint16_t | data )

Write uint16_t to buffer.

Definition at line 565 of file buffer.c.

References buffer_write_u16_at(), and buffer_struct::position.

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

## buffer_write_u16_at()

void buffer_write_u16_at | ( | buffer_type * | buffer,
|  | size_t | at,
|  | uint16_t | data )

Write to buffer at indicated position.

Definition at line 512 of file buffer.c.

References buffer_struct::data.

Referenced by buffer_pkt_set_ancount(), buffer_pkt_set_arcount(), buffer_pkt_set_flags(), buffer_pkt_set_nscount(), buffer_pkt_set_qdcount(), buffer_pkt_set_random_id(), buffer_write_rr(), buffer_write_u16(), query_add_rr(), and tsig_rr_append().

## buffer_write_u32()

void buffer_write_u32 | ( | buffer_type * | buffer,
|  | uint32_t | data )

Write uint32_t to buffer.

Definition at line 578 of file buffer.c.

References buffer_struct::position.

Referenced by buffer_write_rr(), query_add_rr(), and tsig_rr_append().

## buffer_write_u8()

void buffer_write_u8 | ( | buffer_type * | buffer,
|  | uint8_t | data )

Write uint8_t to buffer.

Definition at line 552 of file buffer.c.

References buffer_struct::position.

Referenced by tsig_rr_append().

## Variable Documentation

## ods_rcode_str

ods_lookup_table ods_rcode_str[]

Initial value:
= {
{ LDNS_RCODE_NOERROR, "NOERROR" },
{ LDNS_RCODE_FORMERR, "FORMERR" },
{ LDNS_RCODE_SERVFAIL, "SERVFAIL" },
{ LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
{ LDNS_RCODE_NOTIMPL, "NOTIMPL" },
{ LDNS_RCODE_REFUSED, "REFUSED" },
{ LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
{ LDNS_RCODE_YXRRSET, "YXRRSET" },
{ LDNS_RCODE_NXRRSET, "NXRRSET" },
{ LDNS_RCODE_NOTAUTH, "NOTAUTH" },
{ LDNS_RCODE_NOTZONE, "NOTZONE" },
{ 0, NULL }
}

Definition at line 57 of file buffer.c.

Referenced by buffer_rcode2str().