buffer.h File Reference
`#include "config.h"`
`#include "status.h"`
`#include "log.h"`
`#include <ldns/ldns.h>`
`#include <stdint.h>`

Go to the source code of this file.

## Data Structures

struct | buffer_struct

## Macros

#define | BUFFER_PKT_HEADER_SIZE 12
#define | MAXDOMAINLEN 255
#define | MAXLABELLEN 63
#define | MAX_RDLENGTH 65535
#define | MAX_RR_SIZE (MAXDOMAINLEN + sizeof(uint32_t) + 4*sizeof(uint16_t) + MAX_RDLENGTH)
#define | MAX_PACKET_SIZE 65535
#define | PACKET_BUFFER_SIZE (MAX_PACKET_SIZE + MAX_RR_SIZE)
#define | QR_MASK 0x80U
#define | QR_SHIFT 7
#define | QR(packet)
#define | QR_SET(packet)
#define | QR_CLR(packet)
#define | OPCODE_MASK 0x78U
#define | OPCODE_SHIFT 3
#define | OPCODE(packet)
#define | OPCODE_SET(packet, opcode)
#define | AA_MASK 0x04U
#define | AA_SHIFT 2
#define | AA(packet)
#define | AA_SET(packet)
#define | AA_CLR(packet)
#define | TC_MASK 0x02U
#define | TC_SHIFT 1
#define | TC(packet)
#define | TC_SET(packet)
#define | TC_CLR(packet)
#define | RD_MASK 0x01U
#define | RD_SHIFT 0
#define | RD(packet)
#define | RD_SET(packet)
#define | RD_CLR(packet)
#define | RA_MASK 0x80U
#define | RA_SHIFT 7
#define | RA(packet)
#define | RA_SET(packet)
#define | RA_CLR(packet)
#define | AD_MASK 0x20U
#define | AD_SHIFT 5
#define | AD(packet)
#define | AD_SET(packet)
#define | AD_CLR(packet)
#define | CD_MASK 0x10U
#define | CD_SHIFT 4
#define | CD(packet)
#define | CD_SET(packet)
#define | CD_CLR(packet)
#define | RCODE_MASK 0x0fU
#define | RCODE_SHIFT 0
#define | RCODE(packet)
#define | RCODE_SET(packet, rcode)

## Typedefs

typedef struct buffer_struct | buffer_type

## 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)
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 (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_u16_at (buffer_type *buffer, size_t at, 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)
size_t | buffer_read_dname (buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
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)
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_opcode | buffer_pkt_opcode (buffer_type *buffer)
void | buffer_pkt_set_opcode (buffer_type *buffer, ldns_pkt_opcode opcode)
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 []

## Macro Definition Documentation

## AA

#define AA | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) & AA_MASK)
buffer_at
uint8_t * buffer_at(buffer_type *buffer, size_t at)
Definition buffer.c:413
AA_MASK
#define AA_MASK
Definition buffer.h:64

Definition at line 66 of file buffer.h.

Referenced by buffer_pkt_aa().

## AA_CLR

#define AA_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) &= ~AA_MASK)

Definition at line 68 of file buffer.h.

## AA_MASK

#define AA_MASK 0x04U

Definition at line 64 of file buffer.h.

## AA_SET

#define AA_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) |= AA_MASK)

Definition at line 67 of file buffer.h.

Referenced by buffer_pkt_set_aa().

## AA_SHIFT

#define AA_SHIFT 2

Definition at line 65 of file buffer.h.

## AD

#define AD | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) & AD_MASK)
AD_MASK
#define AD_MASK
Definition buffer.h:88

Definition at line 90 of file buffer.h.

Referenced by buffer_pkt_ad().

## AD_CLR

#define AD_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) &= ~AD_MASK)

Definition at line 92 of file buffer.h.

## AD_MASK

#define AD_MASK 0x20U

Definition at line 88 of file buffer.h.

## AD_SET

#define AD_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) |= AD_MASK)

Definition at line 91 of file buffer.h.

## AD_SHIFT

#define AD_SHIFT 5

Definition at line 89 of file buffer.h.

## BUFFER_PKT_HEADER_SIZE

#define BUFFER_PKT_HEADER_SIZE 12

Packet buffer.

Definition at line 43 of file buffer.h.

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

## CD

#define CD | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) & CD_MASK)
CD_MASK
#define CD_MASK
Definition buffer.h:94

Definition at line 96 of file buffer.h.

Referenced by buffer_pkt_cd().

## CD_CLR

#define CD_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) &= ~CD_MASK)

Definition at line 98 of file buffer.h.

## CD_MASK

#define CD_MASK 0x10U

Definition at line 94 of file buffer.h.

## CD_SET

#define CD_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) |= CD_MASK)

Definition at line 97 of file buffer.h.

## CD_SHIFT

#define CD_SHIFT 4

Definition at line 95 of file buffer.h.

## MAX_PACKET_SIZE

#define MAX_PACKET_SIZE 65535

Definition at line 49 of file buffer.h.

Referenced by buffer_read_dname().

## MAX_RDLENGTH

#define MAX_RDLENGTH 65535

Definition at line 46 of file buffer.h.

## MAX_RR_SIZE

#define MAX_RR_SIZE (MAXDOMAINLEN + sizeof(uint32_t) + 4*sizeof(uint16_t) + MAX_RDLENGTH)

Definition at line 47 of file buffer.h.

## MAXDOMAINLEN

#define MAXDOMAINLEN 255

Definition at line 44 of file buffer.h.

Referenced by buffer_read_dname().

## MAXLABELLEN

#define MAXLABELLEN 63

Definition at line 45 of file buffer.h.

## OPCODE

#define OPCODE | ( |  | packet | ) |

Value:
((*buffer_at((packet), 2) & OPCODE_MASK) >> OPCODE_SHIFT)
OPCODE_SHIFT
#define OPCODE_SHIFT
Definition buffer.h:59
OPCODE_MASK
#define OPCODE_MASK
Definition buffer.h:58

Definition at line 60 of file buffer.h.

Referenced by buffer_pkt_opcode().

## OPCODE_MASK

#define OPCODE_MASK 0x78U

Definition at line 58 of file buffer.h.

## OPCODE_SET

#define OPCODE_SET | ( |  | packet,
|  |  | opcode )

Value:
(*buffer_at((packet), 2) = (*buffer_at((packet), 2) & ~OPCODE_MASK) | ((opcode) << OPCODE_SHIFT))

Definition at line 61 of file buffer.h.

Referenced by buffer_pkt_set_opcode().

## OPCODE_SHIFT

#define OPCODE_SHIFT 3

Definition at line 59 of file buffer.h.

## PACKET_BUFFER_SIZE

#define PACKET_BUFFER_SIZE (MAX_PACKET_SIZE + MAX_RR_SIZE)

Definition at line 50 of file buffer.h.

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

## QR

#define QR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) & QR_MASK)
QR_MASK
#define QR_MASK
Definition buffer.h:52

Definition at line 54 of file buffer.h.

Referenced by buffer_pkt_qr().

## QR_CLR

#define QR_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) &= ~QR_MASK)

Definition at line 56 of file buffer.h.

Referenced by buffer_pkt_clear_qr().

## QR_MASK

#define QR_MASK 0x80U

Definition at line 52 of file buffer.h.

## QR_SET

#define QR_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) |= QR_MASK)

Definition at line 55 of file buffer.h.

Referenced by buffer_pkt_set_qr().

## QR_SHIFT

#define QR_SHIFT 7

Definition at line 53 of file buffer.h.

## RA

#define RA | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) & RA_MASK)
RA_MASK
#define RA_MASK
Definition buffer.h:82

Definition at line 84 of file buffer.h.

Referenced by buffer_pkt_ra().

## RA_CLR

#define RA_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) &= ~RA_MASK)

Definition at line 86 of file buffer.h.

## RA_MASK

#define RA_MASK 0x80U

Definition at line 82 of file buffer.h.

## RA_SET

#define RA_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) |= RA_MASK)

Definition at line 85 of file buffer.h.

## RA_SHIFT

#define RA_SHIFT 7

Definition at line 83 of file buffer.h.

## RCODE

#define RCODE | ( |  | packet | ) |

Value:
(*buffer_at((packet), 3) & RCODE_MASK)
RCODE_MASK
#define RCODE_MASK
Definition buffer.h:100

Definition at line 102 of file buffer.h.

Referenced by buffer_pkt_rcode().

## RCODE_MASK

#define RCODE_MASK 0x0fU

Definition at line 100 of file buffer.h.

## RCODE_SET

#define RCODE_SET | ( |  | packet,
|  |  | rcode )

Value:
(*buffer_at((packet), 3) = (*buffer_at((packet), 3) & ~RCODE_MASK) | (rcode))

Definition at line 103 of file buffer.h.

Referenced by buffer_pkt_set_rcode().

## RCODE_SHIFT

#define RCODE_SHIFT 0

Definition at line 101 of file buffer.h.

## RD

#define RD | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) & RD_MASK)
RD_MASK
#define RD_MASK
Definition buffer.h:76

Definition at line 78 of file buffer.h.

Referenced by buffer_pkt_rd().

## RD_CLR

#define RD_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) &= ~RD_MASK)

Definition at line 80 of file buffer.h.

## RD_MASK

#define RD_MASK 0x01U

Definition at line 76 of file buffer.h.

## RD_SET

#define RD_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) |= RD_MASK)

Definition at line 79 of file buffer.h.

## RD_SHIFT

#define RD_SHIFT 0

Definition at line 77 of file buffer.h.

## TC

#define TC | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) & TC_MASK)
TC_MASK
#define TC_MASK
Definition buffer.h:70

Definition at line 72 of file buffer.h.

Referenced by buffer_pkt_tc().

## TC_CLR

#define TC_CLR | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) &= ~TC_MASK)

Definition at line 74 of file buffer.h.

## TC_MASK

#define TC_MASK 0x02U

Definition at line 70 of file buffer.h.

## TC_SET

#define TC_SET | ( |  | packet | ) |

Value:
(*buffer_at((packet), 2) |= TC_MASK)

Definition at line 73 of file buffer.h.

## TC_SHIFT

#define TC_SHIFT 1

Definition at line 71 of file buffer.h.

## Typedef Documentation

## buffer_type

typedef struct buffer_struct buffer_type

Buffer.

Definition at line 111 of file buffer.h.

## Function Documentation

## buffer_at()

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

extern

Return a pointer to the data at the indicated position.

Parameters

  [in] | buffer | buffer
  [in] | at | indicated position

Returns
  uint8_t* pointer to the data at the indicated position

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 )

extern

Check if the buffer has enough bytes available.

Parameters

  [in] | buffer | buffer
  [in] | count | number of bytes that needs to be available

Returns
  int 0 if not enough bytes are available 1 otherwise

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 | ) |

extern

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

Parameters

  [in] | buffer | buffer

Returns
  uint8_t* pointer to the data at the begin of the 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 | ) |

extern

Get the buffer's capacity.

Parameters

  [in] | buffer | buffer

Returns
  size_t capacity

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 | ) |

extern

Clean up buffer.

Parameters

  [in] | buffer | buffer
  [in] | allocator | memory allocator

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 | ) |

extern

Clear the buffer and make it ready for writing. The buffer's limit is set to the capacity and the position is set to 0.

Parameters

  [in] | buffer | 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 | ) |

extern

Create a new buffer with the specified capacity.

Parameters

  [in] | allocator | memory allocator
  [in] | capacity | specified capacity

Returns
  buffer_type* buffer

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 | ) |

extern

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

Parameters

  [in] | buffer | buffer

Returns
  uint8_t* pointer to the data at the buffer's current position

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. The data that has been written to the buffer. The buffer's limit is set to the current position and the position is set to 0.

Parameters

  [in] | buffer | 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 | ) |

extern

Get the buffer's limit.

Parameters

  [in] | buffer | buffer

Returns
  size_t limit

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 | ) |

extern

Get AA bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if AA bit is clear 1 if AA bit is set

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 | ) |

extern

Get AD bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if AD bit is clear 1 if AD bit is set

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 | ) |

extern

Get ANCOUNT from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t ANCOUNT

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 | ) |

extern

Get ARCOUNT from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t ARCOUNT

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 | ) |

extern

Get CD bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if CD bit is clear 1 if CD bit is set

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 | ) |

extern

Clear QR bit in buffer.

Parameters

  [in] | buffer | 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 | ) |

extern

Get flags from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t flags

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 | ) |

extern

Get query id from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t query id

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 )

extern

Make a new notify.

Parameters

  [in] | buffer | buffer
  [in] | qname | qname
  [in] | qclass | 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 | ) |

extern

Get NSCOUNT from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t NSCOUNT

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 | ) |

extern

Get OPCODE from buffer.

Parameters

  [in] | buffer | buffer

Returns
  ldns_pkt_opcode OPCODE

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 | ) |

extern

Get QDCOUNT from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t QDCOUNT

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 | ) |

extern

Get QR bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if QR bit is clear 1 if QR bit is set

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 )

extern

Make a new query.

Parameters

  [in] | buffer | buffer
  [in] | qname | qname
  [in] | qtype | qtype
  [in] | qclass | 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 | ) |

extern

Get RA bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if RA bit is clear 1 if RA bit is set

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 | ) |

extern

Get RCODE from buffer.

Parameters

  [in] | buffer | buffer

Returns
  ldns_pkt_rcode RCODE

Get RCODE from buffer.

Definition at line 954 of file buffer.c.

References RCODE.

## buffer_pkt_rd()

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

extern

Get RD bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if RD bit is clear 1 if RD bit is set

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 | ) |

extern

Set AA bit in buffer.

Parameters

  [in] | buffer | 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 )

extern

Set ANCOUNT in buffer.

Parameters

  [in] | buffer | buffer
  [in] | count | ANCOUNT

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 )

extern

Set ARCOUNT in buffer.

Parameters

  [in] | buffer | buffer
  [in] | count | ARCOUNT

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 )

extern

Set flags in buffer.

Parameters

  [in] | buffer | buffer
  [in] | flags | 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 )

extern

Set NSCOUNT in buffer.

Parameters

  [in] | buffer | buffer
  [in] | count | NSCOUNT

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 )

extern

Set OPCODE in buffer.

Parameters

  [in] | buffer | buffer
  [in] | 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 )

extern

Set QDCOUNT in buffer.

Parameters

  [in] | buffer | buffer
  [in] | count | QDCOUNT

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 | ) |

extern

Set QR bit in buffer.

Parameters

  [in] | buffer | 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 | ) |

extern

Set random query id in buffer.

Parameters

  [in] | buffer | 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 )

extern

Set RCODE in buffer.

Parameters

  [in] | buffer | buffer
  [in] | 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 | ) |

extern

Get TC bit from buffer.

Parameters

  [in] | buffer | buffer

Returns
  int 0 if TC bit is clear 1 if TC bit is set

Get TC bit from buffer.

Definition at line 894 of file buffer.c.

References TC.

## buffer_position()

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

extern

Get the buffer's position.

Parameters

  [in] | buffer | buffer

Returns
  size_t position

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 | ) |

extern

Look up a descriptive text by each rcode.

Parameters

  [in] | rcode | rcode

Returns
  const char* descriptive text

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 )

extern

Read from buffer.

Parameters

  [in] | buffer | buffer
  [in] | data | read data
  [in] | count | number of bytes to read

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 )

extern

Read dname from buffer.

Parameters

  [in] | buffer | buffer
  [out] | dname | dname
  [in] | allow_pointers | allow pointer labels

Returns
  int dname length

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 | ) |

extern

Read uint16_t from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint16_t read data

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 | ) |

extern

Read uint32_t from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint32_t read data

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 | ) |

extern

Read uint8_t from buffer.

Parameters

  [in] | buffer | buffer

Returns
  uint8_t read data

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 | ) |

extern

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

Parameters

  [in] | buffer | buffer

Returns
  size_t remaining number of bytes

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 )

extern

Set the buffer's limit. If the buffer's position is greater than the new limit, the position is set to the limit.

Parameters

  [in] | buffer | buffer
  [in] | limit | 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 )

extern

Set the buffer's position. The position must be less than or equal to the buffer's limit.

Parameters

  [in] | buffer | buffer
  [in] | pos | position

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 )

extern

Change the buffer's position. The position must not be moved behind the buffer's limit or before the beginning of the buffer.

Parameters

  [in] | buffer | buffer
  [in] | count | number of bytes to skip

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 | ) |

extern

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

Parameters

  [in] | buffer | buffer

Returns
  int 0 if dname skipping failed 1 otherwise

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 )

extern

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

Parameters

  [in] | buffer | buffer
  [in] | qrr | 1 if we skip RRs in the question section.

Returns
  int 0 if RR skipping failed 1 otherwise

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 )

extern

Write to buffer.

Parameters

  [in] | buffer | buffer
  [in] | data | data to write
  [in] | count | number of bytes to write

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 )

extern

Write rdf to buffer.

Parameters

  [in] | buffer | buffer
  [in] | rdf | data to write

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 )

extern

Write rr to buffer.

Parameters

  [in] | buffer | buffer
  [in] | rr | data to write

Returns
  int 1 if rr fits, 0 otherwise

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 )

extern

Write uint16_t to buffer.

Parameters

  [in] | buffer | buffer
  [in] | data | data to write

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 )

extern

Write uint16_t to buffer at indicated position.

Parameters

  [in] | buffer | buffer
  [in] | at | indicated position
  [in] | data | data to write

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 )

extern

Write uint32_t to buffer.

Parameters

  [in] | buffer | buffer
  [in] | data | data to write

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 )

extern

Write uint8_t to buffer.

Parameters

  [in] | buffer | buffer
  [in] | data | data to write

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[]

extern

Definition at line 57 of file buffer.c.

Referenced by buffer_rcode2str().