unbound: sldns/sbuffer.h File Reference

unbound 0.1

Data Structures | Macros | Typedefs | Functions
sbuffer.h File Reference

This file contains the definition of sldns_buffer, and functions to manipulate those. More...

## Data Structures
struct | sldns_buffer
| implementation of buffers to ease operations More...

## Macros
#define | INLINE static inline

## Typedefs
typedef struct sldns_buffer | sldns_buffer

## Functions
INLINE uint16_t | sldns_read_uint16 (const void *src)
INLINE uint32_t | sldns_read_uint32 (const void *src)
INLINE void | sldns_write_uint16 (void *dst, uint16_t data)
INLINE void | sldns_write_uint32 (void *dst, uint32_t data)
INLINE void | sldns_write_uint48 (void *dst, uint64_t data)
INLINE void | sldns_buffer_invariant (sldns_buffer *buffer)
sldns_buffer * | sldns_buffer_new (size_t capacity)
| creates a new buffer with the specified capacity.
void | sldns_buffer_new_frm_data (sldns_buffer *buffer, void *data, size_t size)
| creates a buffer with the specified data.
void | sldns_buffer_init_frm_data (sldns_buffer *buffer, void *data, size_t size)
| Setup a buffer with the data pointed to.
INLINE void | sldns_buffer_clear (sldns_buffer *buffer)
| clears the buffer and make it ready for writing.
INLINE void | sldns_buffer_flip (sldns_buffer *buffer)
| makes the buffer ready for reading the data that has been written to the buffer.
INLINE void | sldns_buffer_rewind (sldns_buffer *buffer)
| make the buffer ready for re-reading the data.
INLINE size_t | sldns_buffer_position (sldns_buffer *buffer)
| returns the current position in the buffer (as a number of bytes)
INLINE void | sldns_buffer_set_position (sldns_buffer *buffer, size_t mark)
| sets the buffer's position to MARK.
INLINE void | sldns_buffer_skip (sldns_buffer *buffer, ssize_t count)
| changes the buffer's position by COUNT bytes.
INLINE size_t | sldns_buffer_limit (sldns_buffer *buffer)
| returns the maximum size of the buffer
INLINE void | sldns_buffer_set_limit (sldns_buffer *buffer, size_t limit)
| changes the buffer's limit.
INLINE size_t | sldns_buffer_capacity (sldns_buffer *buffer)
| returns the number of bytes the buffer can hold.
int | sldns_buffer_set_capacity (sldns_buffer *buffer, size_t capacity)
| changes the buffer's capacity.
int | sldns_buffer_reserve (sldns_buffer *buffer, size_t amount)
| ensures BUFFER can contain at least AMOUNT more bytes.
INLINE uint8_t * | sldns_buffer_at (const sldns_buffer *buffer, size_t at)
| returns a pointer to the data at the indicated position.
INLINE uint8_t * | sldns_buffer_begin (const sldns_buffer *buffer)
| returns a pointer to the beginning of the buffer (the data at position 0).
INLINE uint8_t * | sldns_buffer_end (sldns_buffer *buffer)
| returns a pointer to the end of the buffer (the data at the buffer's limit).
INLINE uint8_t * | sldns_buffer_current (sldns_buffer *buffer)
| returns a pointer to the data at the buffer's current position.
INLINE size_t | sldns_buffer_remaining_at (sldns_buffer *buffer, size_t at)
| returns the number of bytes remaining between the indicated position and the limit.
INLINE size_t | sldns_buffer_remaining (sldns_buffer *buffer)
| returns the number of bytes remaining between the buffer's position and limit.
INLINE int | sldns_buffer_available_at (sldns_buffer *buffer, size_t at, size_t count)
| checks if the buffer has at least COUNT more bytes available.
INLINE int | sldns_buffer_available (sldns_buffer *buffer, size_t count)
| checks if the buffer has count bytes available at the current position
INLINE void | sldns_buffer_write_at (sldns_buffer *buffer, size_t at, const void *data, size_t count)
| writes the given data to the buffer at the specified position
INLINE void | sldns_buffer_set_at (sldns_buffer *buffer, size_t at, int c, size_t count)
| set the given byte to the buffer at the specified position
INLINE void | sldns_buffer_write (sldns_buffer *buffer, const void *data, size_t count)
| writes count bytes of data to the current position of the buffer
INLINE void | sldns_buffer_write_string_at (sldns_buffer *buffer, size_t at, const char *str)
| copies the given (null-delimited) string to the specified position at the buffer
INLINE void | sldns_buffer_write_string (sldns_buffer *buffer, const char *str)
| copies the given (null-delimited) string to the current position at the buffer
INLINE void | sldns_buffer_write_u8_at (sldns_buffer *buffer, size_t at, uint8_t data)
| writes the given byte of data at the given position in the buffer
INLINE void | sldns_buffer_write_u8 (sldns_buffer *buffer, uint8_t data)
| writes the given byte of data at the current position in the buffer
INLINE void | sldns_buffer_write_u16_at (sldns_buffer *buffer, size_t at, uint16_t data)
| writes the given 2 byte integer at the given position in the buffer
INLINE void | sldns_buffer_write_u16 (sldns_buffer *buffer, uint16_t data)
| writes the given 2 byte integer at the current position in the buffer
INLINE void | sldns_buffer_write_u32_at (sldns_buffer *buffer, size_t at, uint32_t data)
| writes the given 4 byte integer at the given position in the buffer
INLINE void | sldns_buffer_write_u48_at (sldns_buffer *buffer, size_t at, uint64_t data)
| writes the given 6 byte integer at the given position in the buffer
INLINE void | sldns_buffer_write_u32 (sldns_buffer *buffer, uint32_t data)
| writes the given 4 byte integer at the current position in the buffer
INLINE void | sldns_buffer_write_u48 (sldns_buffer *buffer, uint64_t data)
| writes the given 6 byte integer at the current position in the buffer
INLINE void | sldns_buffer_read_at (sldns_buffer *buffer, size_t at, void *data, size_t count)
| copies count bytes of data at the given position to the given data-array
INLINE void | sldns_buffer_read (sldns_buffer *buffer, void *data, size_t count)
| copies count bytes of data at the current position to the given data-array
INLINE uint8_t | sldns_buffer_read_u8_at (sldns_buffer *buffer, size_t at)
| returns the byte value at the given position in the buffer
INLINE uint8_t | sldns_buffer_read_u8 (sldns_buffer *buffer)
| returns the byte value at the current position in the buffer
INLINE uint16_t | sldns_buffer_read_u16_at (sldns_buffer *buffer, size_t at)
| returns the 2-byte integer value at the given position in the buffer
INLINE uint16_t | sldns_buffer_read_u16 (sldns_buffer *buffer)
| returns the 2-byte integer value at the current position in the buffer
INLINE uint32_t | sldns_buffer_read_u32_at (sldns_buffer *buffer, size_t at)
| returns the 4-byte integer value at the given position in the buffer
INLINE uint32_t | sldns_buffer_read_u32 (sldns_buffer *buffer)
| returns the 4-byte integer value at the current position in the buffer
INLINE int | sldns_buffer_status (sldns_buffer *buffer)
| returns the status of the buffer
INLINE int | sldns_buffer_status_ok (sldns_buffer *buffer)
| returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise
int | sldns_buffer_printf (sldns_buffer *buffer, const char *format,...) ATTR_FORMAT(printf
| prints to the buffer, increasing the capacity if required using buffer_reserve().
int void | sldns_buffer_free (sldns_buffer *buffer)
| frees the buffer.
void | sldns_buffer_copy (sldns_buffer *result, sldns_buffer *from)
| Copy contents of the from buffer to the result buffer and then flips the result buffer.

## Detailed Description

This file contains the definition of sldns_buffer, and functions to manipulate those.

## Function Documentation

## ◆ sldns_buffer_new()

sldns_buffer * sldns_buffer_new | ( | size_t | capacity | ) |

creates a new buffer with the specified capacity.

Parameters

  [in] | capacity | the size (in bytes) to allocate for the buffer

Returns
  the created buffer

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by anchors_apply_cfg(), anchors_test(), answer_callback_from_entry(), check_mod(), comm_point_create_http_out(), comm_point_create_local(), comm_point_create_tcp_handler(), comm_point_create_tcp_out(), comm_point_tcp_handle_callback(), dname_test(), dstest_file(), fake_front_query(), fake_pending_callback(), hex_buffer2wire(), libworker_setup(), listen_create(), log_dns_msg(), main(), mesh_create(), msgparse_test(), msgtostr(), nsec3_hash_test(), outside_network_create(), pending_tcp_query(), pending_udp_query(), process_answer_detail(), read_entry(), send_em(), service(), verifytest_file(), worker_init(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ sldns_buffer_new_frm_data()

void sldns_buffer_new_frm_data | ( | sldns_buffer * | buffer,
|  | void * | data,
|  | size_t | size )

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

Parameters

  [in] | buffer | pointer to the buffer to put the data in
  [in] | data | the data to encapsulate in the buffer
  [in] | size | the size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by hex_buffer2wire().

## ◆ sldns_buffer_init_frm_data()

void sldns_buffer_init_frm_data | ( | sldns_buffer * | buffer,
|  | void * | data,
|  | size_t | size )

Setup a buffer with the data pointed to.

No data copied, no memory allocs. The buffer is fixed.

Parameters

  [in] | buffer | pointer to the buffer to put the data in
  [in] | data | the data to encapsulate in the buffer
  [in] | size | the size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, and sldns_buffer::_limit.

Referenced by chunk_rrlist_get_current(), decompress_rr_into_buffer(), log_rrlist_position(), pending_tcp_query(), sldns_str2wire_ipseckey_buf(), sldns_str2wire_nsec_buf(), sldns_str2wire_wks_buf(), and use_free_buffer().

## ◆ sldns_buffer_clear()

INLINE void sldns_buffer_clear | ( | sldns_buffer * | buffer | ) |

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.

Parameters

  [in] | buffer | the buffer to clear

References sldns_buffer::_capacity, sldns_buffer::_limit, and sldns_buffer::_position.

Referenced by anchor_read_bind_file(), auth_xfer_transfer_http_callback(), auth_xfer_transfer_tcp_callback(), chaos_replystr(), chunkline_get_line_collated(), comm_point_http_handle_write(), comm_point_tcp_handle_read(), comm_point_udp_callback(), decompress_rr_into_buffer(), dname_test_pkt_dname_len(), dname_to_buf(), ds_create_dnskey_digest(), entry_to_buf(), extended_error_encode(), fill_buffer_with_reply(), hex_to_buf(), http_chunked_segment(), http_moveover_buffer(), http_nonchunk_segment(), load_rr(), local_zones_zone_answer(), mesh_do_callback(), nsec3_calc_b32(), nsec3_calc_hash(), nsec3_covers(), nsec3_get_hashed(), outnet_send_wait_udp(), process_answer_detail(), process_bind_contents(), qinfo_query_encode(), reclaim_tcp_handler(), recv_one(), reply_info_encode(), reuse_tcp_setup_read_and_timeout(), rrset_canonical(), rrset_canonicalize_to_buffer(), serviced_callbacks(), serviced_encode(), serviced_gen_query(), setup_http_request(), setup_tcp_handler(), skip_to_special(), sldns_buffer_copy(), ssl_handle_read(), tcp_callback_writer(), tcp_req_info_handle_readdone(), tcp_req_info_handle_writedone(), tcp_req_info_send_reply(), tcp_req_info_start_write_buf(), write_q(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_flip()

INLINE void sldns_buffer_flip | ( | sldns_buffer * | buffer | ) |

makes the buffer 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 | the buffer to flip

References sldns_buffer::_limit, and sldns_buffer::_position.

Referenced by anchors_test(), chaos_replystr(), chunkline_get_line_collated(), comm_point_http_handle_read(), comm_point_tcp_handle_read(), comm_point_udp_callback(), decompress_rr_into_buffer(), dname_setup_bufs(), dname_test(), dname_test_pkt_dname_len(), dname_to_buf(), ds_create_dnskey_digest(), entry_to_buf(), extended_error_encode(), fill_buffer_with_reply(), hex_to_buf(), http_chunked_segment(), http_process_chunk_header(), http_process_initial_header(), local_zones_zone_answer(), nsec3_calc_hash(), nsec3_get_hashed(), outnet_send_wait_udp(), pending_tcp_query(), pending_udp_query(), process_answer_detail(), qinfo_query_encode(), query_error(), reply_info_encode(), rrset_canonical(), rrset_canonicalize_to_buffer(), serviced_callbacks(), serviced_encode(), serviced_gen_query(), setup_http_request(), sldns_buffer_copy(), ssl_handle_read(), tcp_callback_reader(), tcp_req_info_send_reply(), tcp_req_info_start_write_buf(), write_q(), write_soa_serial_to_buf(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_rewind()

INLINE void sldns_buffer_rewind | ( | sldns_buffer * | buffer | ) |

make the buffer ready for re-reading the data.

The buffer's position is reset to 0.

Parameters

  [in] | buffer | the buffer to rewind

References sldns_buffer::_position.

Referenced by dnsc_handle_curved_request(), and worker_handle_request().

## ◆ sldns_buffer_position()

INLINE size_t sldns_buffer_position | ( | sldns_buffer * | buffer | ) |

returns the current position in the buffer (as a number of bytes)

Parameters

  [in] | buffer | the buffer

Returns
  the current position

References sldns_buffer::_position.

Referenced by analyze_dname(), analyze_rdata(), calc_size(), chaos_replystr(), check_xfer_packet(), chunk_rrlist_get_current(), chunkline_count_parens(), chunkline_get_line_collated(), chunkline_remove_trailcomment(), comm_point_http_handle_read(), compress_any_dname(), compress_rdata(), decompress_rr_into_buffer(), dname_test_pkt_dname_len(), get_additional_name(), hex_buffer2wire(), hex_to_buf(), http_chunked_segment(), http_header_done(), http_header_line(), http_moveover_buffer(), http_read_more(), insert_query(), insert_section(), nsec_at_apex(), packed_rrset_encode(), parse_get_cname_target(), pkt_dname_len(), pkt_rrsig_covered(), process_bind_contents(), query_info_parse(), rdata_copy(), readkeyword_bindfile(), rrinternal_get_class(), rrinternal_get_owner(), rrinternal_get_ttl(), rrinternal_get_type(), rrinternal_parse_rdata(), rrinternal_parse_rdf(), rrinternal_parse_unknown(), rrinternal_write_typeclassttl(), sanitize_nsec_is_overreach(), setup_http_request(), sig_is_double(), sldns_parse_rdf_token(), sldns_str2wire_ipseckey_buf(), sldns_str2wire_nsec_buf(), sldns_str2wire_wks_buf(), ssl_http_read_more(), and svcb_rr_contains_priv_addr().

## ◆ sldns_buffer_set_position()

INLINE void sldns_buffer_set_position | ( | sldns_buffer * | buffer,
|  | size_t | mark )

sets the buffer's position to MARK.

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

Parameters

  [in] | buffer | the buffer
  [in] | mark | the mark to use

References sldns_buffer::_limit, and sldns_buffer::_position.

Referenced by auth_zone_parse_notify_serial(), check_xfer_packet(), chunk_rrlist_get_current(), chunkline_remove_trailcomment(), comm_point_http_handle_read(), comm_point_tcp_handle_write(), createResponse(), decompress_rr_into_buffer(), dname_test_pkt_dname_len(), dname_to_buf(), dnscrypt_server_uncurve(), get_additional_name(), http_chunked_segment(), http_header_line(), http_moveover_buffer(), http_nonchunk_segment(), http_process_chunk_header(), insert_section(), log_rrlist_position(), nsec_at_apex(), parse_get_cname_target(), parse_reply_in_temp_region(), pkt_dname_len(), pkt_rrsig_covered(), process_response(), query_error(), rdata_copy(), reply_info_parse(), rrinternal_parse_unknown(), sanitize_nsec_is_overreach(), sig_is_double(), sldns_bgetc(), ssl_handle_write(), svcb_rr_contains_priv_addr(), write_soa_serial_to_buf(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_skip()

INLINE void sldns_buffer_skip | ( | sldns_buffer * | buffer,
|  | ssize_t | count )

changes the buffer's position by COUNT bytes.

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

Parameters

  [in] | buffer | the buffer
  [in] | count | the count to use

References sldns_buffer::_limit, and sldns_buffer::_position.

Referenced by analyze_rdata(), analyze_rr(), auth_zone_parse_notify_serial(), calc_size(), chaos_replystr(), check_packet_ok(), check_xfer_packet(), chunk_rrlist_get_current(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), comm_point_udp_callback(), compress_rdata(), decompress_rr_into_buffer(), extended_error_encode(), http_chunked_segment(), http_read_more(), http_write_more(), insert_query(), nsec_at_apex(), pkt_dname_len(), pkt_rrsig_covered(), process_bind_contents(), qinfo_query_encode(), query_dname_len(), query_info_parse(), rdata_copy(), readkeyword_bindfile(), rrinternal_get_quoted(), sig_is_double(), skip_pkt_rr(), skip_ttl_rdata(), sldns_parse_rdf_token(), ssl_handle_read(), ssl_handle_write(), ssl_http_read_more(), ssl_http_write_more(), and write_q().

## ◆ sldns_buffer_limit()

INLINE size_t sldns_buffer_limit | ( | sldns_buffer * | buffer | ) |

returns the maximum size of the buffer

Parameters

  [in] | buffer |

Returns
  the size

References sldns_buffer::_limit.

Referenced by analyze(), auth_xfer_transfer_http_callback(), az_insert_rr_decompress(), az_remove_rr_decompress(), chaos_replystr(), check_packet_ok(), check_xfer_packet(), checkformerr(), chunkline_get_line_collated(), chunkline_is_comment_line_or_empty(), chunkline_newline_removal(), comm_point_http_handle_read(), comm_point_send_reply(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), consume_pp2_header(), dname_pkt_compare(), dname_pkt_copy(), dname_pkt_hash(), dname_print(), dnsc_find_cert(), dnscrypt_server_curve(), dnscrypt_server_uncurve(), ds_create_dnskey_digest(), extended_error_encode(), fill_buffer_with_reply(), handle_query(), hex_to_buf(), http_chunked_segment(), http_header_done(), http_header_line(), http_nonchunk_segment(), libworker_event_done_cb(), libworker_fillup_fg(), log_buf(), log_dns_msg(), log_reply_info(), log_testpkt_reply_pkt(), lookup_serviced(), nsec3_calc_b32(), nsec3_calc_hash(), nsec3_covers(), nsec3_get_hashed(), outnet_tcp_cb(), outnet_udp_cb(), pending_tcp_query(), pending_udp_query(), pending_udp_query(), perf_encode(), perftestpkt(), pkt_dname_len(), pkt_dname_tolower(), qlist_add_line(), query_info_parse(), read_entry(), recv_one(), reply_info_answer_encode(), reply_info_encode(), ring_add(), send_em(), server_stats_insrcode(), service_send(), serviced_callbacks(), serviced_check_qname(), serviced_create(), sldns_bgetc(), sldns_buffer_copy(), smart_compare(), ssl_handle_read(), ssl_handle_write(), tcp_req_info_send_reply(), test_buffers(), testpkt(), worker_check_request(), worker_handle_request(), worker_handle_service_reply(), write_q(), write_soa_serial_to_buf(), xfer_link_data(), xfr_create_ixfr_packet(), zonemd_simple_rrset(), and zonemd_simple_rrsig().

## ◆ sldns_buffer_set_limit()

INLINE void sldns_buffer_set_limit | ( | sldns_buffer * | buffer,
|  | size_t | limit )

changes 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 | the buffer
  [in] | limit | the new limit

References sldns_buffer::_capacity, sldns_buffer::_limit, and sldns_buffer::_position.

Referenced by chunkline_newline_removal(), comm_point_tcp_handle_read(), consume_pp2_header(), dnscrypt_server_curve(), dnscrypt_server_uncurve(), do_proxy(), http_chunked_segment(), http_process_chunk_header(), recv_one(), reply_info_encode(), ring_pop(), service_recv(), ssl_handle_read(), tcp_req_info_handle_readdone(), write_q(), and write_soa_serial_to_buf().

## ◆ sldns_buffer_capacity()

INLINE size_t sldns_buffer_capacity | ( | sldns_buffer * | buffer | ) |

returns the number of bytes the buffer can hold.

Parameters

  [in] | buffer | the buffer

Returns
  the number of bytes

References sldns_buffer::_capacity.

Referenced by anchor_read_file(), anchor_store_str(), chaos_replystr(), comm_point_get_mem(), comm_point_tcp_handle_callback(), comm_point_tcp_handle_read(), dname_to_buf(), do_list_local_data(), do_proxy(), http_chunked_segment(), http_nonchunk_segment(), listen_get_mem(), mesh_get_mem(), outnet_get_mem(), pending_tcp_query(), pending_udp_query(), perfreply(), probe_anchor(), recv_one(), reply_info_answer_encode(), service_recv(), setup_http_request(), setup_qinfo_edns(), sldns_buffer_copy(), ssl_handle_read(), ssl_read_buf(), tcp_relay_read(), worker_mem_report(), write_q(), write_soa_serial_to_buf(), xfr_probe_lookup_host(), xfr_transfer_lookup_host(), and zonemd_lookup_dnskey().

## ◆ sldns_buffer_set_capacity()

int sldns_buffer_set_capacity | ( | sldns_buffer * | buffer,
|  | size_t | capacity )

changes the buffer's capacity.

The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.

Parameters

  [in] | buffer | the buffer
  [in] | capacity | the capacity to use

Returns
  whether this failed or succeeded

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by sldns_buffer_reserve().

## ◆ sldns_buffer_reserve()

int sldns_buffer_reserve | ( | sldns_buffer * | buffer,
|  | size_t | amount )

ensures BUFFER can contain at least AMOUNT more bytes.

The buffer's capacity is increased if necessary using buffer_set_capacity().

The buffer's limit is always set to the (possibly increased) capacity.

Parameters

  [in] | buffer | the buffer
  [in] | amount | amount to use

Returns
  whether this failed or succeeded

References sldns_buffer::_capacity, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, sldns_buffer::_status_err, and sldns_buffer_set_capacity().

## ◆ sldns_buffer_at()

INLINE uint8_t * sldns_buffer_at | ( | const sldns_buffer * | buffer,
|  | size_t | at )

returns a pointer to the data at the indicated position.

Parameters

  [in] | buffer | the buffer
  [in] | at | position

Returns
  the pointer to the data

References sldns_buffer::_data, and sldns_buffer::_limit.

Referenced by check_xfer_packet(), comm_point_tcp_handle_read(), dname_pkt_compare(), dname_pkt_copy(), dname_pkt_hash(), dname_print(), dname_test_pdtl(), dnscrypt_server_uncurve(), http_moveover_buffer(), perftestpkt(), pkt_dname_tolower(), serviced_callbacks(), serviced_check_qname(), sldns_buffer_begin(), sldns_buffer_current(), sldns_buffer_end(), smart_compare(), ssl_handle_read(), test_buffers(), and testpkt().

## ◆ sldns_buffer_begin()

INLINE uint8_t * sldns_buffer_begin | ( | const sldns_buffer * | buffer | ) |

returns a pointer to the beginning of the buffer (the data at position 0).

Parameters

  [in] | buffer | the buffer

Returns
  the pointer

References sldns_buffer_at().

Referenced by add_bg_result(), anchor_read_bind_file(), anchor_read_file(), anchor_store_str(), answer_notify(), apply_http(), auth_answer_encode(), auth_error_encode(), auth_zone_parse_notify_serial(), az_insert_rr_decompress(), az_remove_rr_decompress(), chaos_replystr(), check_packet_ok(), check_xfer_packet(), checkformerr(), comm_point_send_reply(), comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), comm_point_udp_callback(), consume_pp2_header(), context_serialize_answer(), decompress_rr_into_buffer(), dname_test_qdtl(), dname_to_buf(), dnsc_find_cert(), dnscrypt_server_curve(), dnscrypt_server_uncurve(), do_list_local_data(), do_proxy(), ds_create_dnskey_digest(), fill_buffer_with_reply(), get_additional_name(), handle_query(), hex_buffer2wire(), http_chunked_segment(), http_moveover_buffer(), http_parse_add_rr(), http_parse_origin(), http_parse_ttl(), http_zonefile_syntax_check(), libworker_event_done_cb(), libworker_fillup_fg(), libworker_handle_service_reply(), load_msg(), load_msg_cache(), load_ref(), load_rr(), load_rrset(), load_rrset_cache(), local_encode(), local_error_encode(), log_buf(), log_dns_msg(), log_rrlist_position(), log_testpkt_reply_pkt(), lookup_serviced(), mesh_send_reply(), msgtostr(), nsec3_calc_b32(), nsec3_calc_hash(), nsec3_covers(), nsec3_get_hashed(), outnet_tcp_cb(), outnet_udp_cb(), parse_edns_from_query_pkt(), parse_get_cname_target(), pending_tcp_query(), pending_udp_query(), pending_udp_query(), perfreply(), perftestpkt(), pkt_rrsig_covered(), process_bind_contents(), qlist_add_line(), qlist_parse_line(), query_error(), query_info_parse(), rdata_copy(), read_entry(), read_fixed(), recv_one(), reply_info_encode(), ring_add(), ring_pop(), rpz_local_encode(), rrset_canonical(), sanitize_nsec_is_overreach(), select_id(), send_em(), server_stats_insquery(), server_stats_insrcode(), service_recv(), service_send(), serviced_callbacks(), serviced_check_qname(), serviced_create(), serviced_encode(), serviced_tcp_callback(), serviced_udp_callback(), skip_to_special(), sldns_buffer_copy(), ssl_handle_read(), ssl_read_buf(), svcb_rr_contains_priv_addr(), tcp_relay_read(), tcp_req_info_send_reply(), test_buffers(), testpkt(), worker_check_request(), worker_handle_request(), worker_handle_service_reply(), write_q(), xfer_link_data(), zonemd_simple_rrset(), and zonemd_simple_rrsig().

## ◆ sldns_buffer_end()

INLINE uint8_t * sldns_buffer_end | ( | sldns_buffer * | buffer | ) |

returns a pointer to the end of the buffer (the data at the buffer's limit).

Parameters

  [in] | buffer | the buffer

Returns
  the pointer

References sldns_buffer::_limit, and sldns_buffer_at().

Referenced by pkt_dname_tolower().

## ◆ sldns_buffer_current()

INLINE uint8_t * sldns_buffer_current | ( | sldns_buffer * | buffer | ) |

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

Parameters

  [in] | buffer | the buffer

Returns
  the pointer

References sldns_buffer::_position, and sldns_buffer_at().

Referenced by add_rr_to_rrset(), analyze_dname(), analyze_rdata(), calc_size(), canonicalize_rdata(), check_packet_ok(), chunk_rrlist_get_current(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), decompress_rr_into_buffer(), extended_error_encode(), find_rrset(), http_chunked_segment(), http_header_line(), http_read_more(), http_write_more(), insert_can_owner(), insert_query(), parse_edns_from_query_pkt(), parse_query_section(), parse_section(), process_bind_contents(), query_info_parse(), rdata_copy(), rrinternal_get_quoted(), rrset_canonicalize_to_buffer(), sldns_parse_rdf_token(), sldns_str2wire_ipseckey_buf(), ssl_handle_read(), ssl_handle_write(), ssl_http_read_more(), and ssl_http_write_more().

## ◆ sldns_buffer_remaining_at()

INLINE size_t sldns_buffer_remaining_at | ( | sldns_buffer * | buffer,
|  | size_t | at )

returns the number of bytes remaining between the indicated position and the limit.

Parameters

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

Returns
  number of bytes

References sldns_buffer::_limit.

Referenced by sldns_buffer_available_at(), and sldns_buffer_remaining().

## ◆ sldns_buffer_remaining()

INLINE size_t sldns_buffer_remaining | ( | sldns_buffer * | buffer | ) |

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

Parameters

  [in] | buffer | the buffer

Returns
  the number of bytes

References sldns_buffer::_position, and sldns_buffer_remaining_at().

Referenced by add_bg_result(), analyze(), auth_zone_parse_notify_serial(), calc_size(), check_packet_ok(), check_xfer_packet(), chunk_rrlist_get_current(), chunkline_get_line(), chunkline_get_line_collated(), comm_point_http_handle_read(), comm_point_http_handle_write(), comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), comm_point_udp_callback(), compress_owner(), compress_rdata(), consume_pp2_header(), context_serialize_answer(), dname_buffer_write(), http_chunked_segment(), http_moveover_buffer(), http_read_more(), http_write_more(), insert_query(), nsec_at_apex(), packed_rrset_encode(), parse_edns_from_query_pkt(), parse_packet(), parse_query_section(), parse_section(), pkt_dname_len(), pkt_rrsig_covered(), process_bind_contents(), qinfo_query_encode(), query_dname_len(), query_info_parse(), rdata_copy(), readkeyword_bindfile(), reply_info_encode(), rrinternal_get_quoted(), rrset_canonical(), rrset_canonicalize_to_buffer(), sig_is_double(), skip_pkt_rr(), skip_ttl_rdata(), sldns_parse_rdf_token(), sldns_str2wire_nsec_buf(), ssl_handle_read(), ssl_handle_write(), ssl_http_read_more(), ssl_http_write_more(), and write_compressed_dname().

## ◆ sldns_buffer_available_at()

INLINE int sldns_buffer_available_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | size_t | count )

checks if the buffer has at least COUNT more bytes available.

Before reading or writing the caller needs to ensure enough space is available!

Parameters

  [in] | buffer | the buffer
  [in] | at | indicated position
  [in] | count | how much is available

Returns
  true or false (as int?)

References sldns_buffer_remaining_at().

Referenced by sldns_bgetc(), sldns_bskipcs(), sldns_buffer_available(), sldns_buffer_read_at(), sldns_buffer_read_u16_at(), sldns_buffer_read_u32_at(), sldns_buffer_read_u8_at(), sldns_buffer_set_at(), sldns_buffer_write_at(), sldns_buffer_write_u16_at(), sldns_buffer_write_u32_at(), sldns_buffer_write_u48_at(), and sldns_buffer_write_u8_at().

## ◆ sldns_buffer_available()

INLINE int sldns_buffer_available | ( | sldns_buffer * | buffer,
|  | size_t | count )

checks if the buffer has count bytes available at the current position

Parameters

  [in] | buffer | the buffer
  [in] | count | how much is available

Returns
  true or false (as int?)

References sldns_buffer::_position, and sldns_buffer_available_at().

Referenced by decompress_rr_into_buffer().

## ◆ sldns_buffer_write_at()

INLINE void sldns_buffer_write_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | const void * | data,
|  | size_t | count )

writes the given data to the buffer at the specified position

Parameters

  [in] | buffer | the buffer
  [in] | at | the position (in number of bytes) to write the data at
  [in] | data | pointer to the data to write to the buffer
  [in] | count | the number of bytes of data to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by dname_test_qdtl(), dnscrypt_server_curve(), mesh_send_reply(), sldns_buffer_write(), and sldns_buffer_write_string_at().

## ◆ sldns_buffer_set_at()

INLINE void sldns_buffer_set_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | int | c,
|  | size_t | count )

set the given byte to the buffer at the specified position

Parameters

  [in] | buffer | the buffer
  [in] | at | the position (in number of bytes) to write the data at
  [in] | c | the byte to set to the buffer
  [in] | count | the number of bytes of bytes to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by dnscrypt_server_curve().

## ◆ sldns_buffer_write()

INLINE void sldns_buffer_write | ( | sldns_buffer * | buffer,
|  | const void * | data,
|  | size_t | count )

writes count bytes of data to the current position of the buffer

Parameters

  [in] | buffer | the buffer
  [in] | data | the data to write
  [in] | count | the length of the data to write

References sldns_buffer::_position, and sldns_buffer_write_at().

Referenced by chaos_replystr(), compress_owner(), compress_rdata(), decompress_rr_into_buffer(), dname_buffer_write(), dname_test_pkt_dname_len(), ds_create_dnskey_digest(), entry_to_buf(), extended_error_encode(), fill_buffer_with_reply(), http_chunked_segment(), insert_can_owner(), insert_query(), nsec3_calc_hash(), nsec3_get_hashed(), outnet_send_wait_udp(), packed_rrset_encode(), pending_tcp_query(), pending_udp_query(), process_answer_detail(), process_bind_contents(), qinfo_query_encode(), reply_info_encode(), rrset_canonical(), rrset_canonicalize_to_buffer(), serviced_callbacks(), serviced_encode(), serviced_gen_query(), sldns_buffer_copy(), sldns_buffer_write_string(), tcp_req_info_send_reply(), tcp_req_info_start_write_buf(), write_compressed_dname(), and write_q().

## ◆ sldns_buffer_write_string_at()

INLINE void sldns_buffer_write_string_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | const char * | str )

copies the given (null-delimited) string to the specified position at the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer
  [in] | str | the string to write

References sldns_buffer_write_at().

## ◆ sldns_buffer_write_string()

INLINE void sldns_buffer_write_string | ( | sldns_buffer * | buffer,
|  | const char * | str )

copies the given (null-delimited) string to the current position at the buffer

Parameters

  [in] | buffer | the buffer
  [in] | str | the string to write

References sldns_buffer_write().

## ◆ sldns_buffer_write_u8_at()

INLINE void sldns_buffer_write_u8_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | uint8_t | data )

writes the given byte of data at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer
  [in] | data | the 8 bits to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by chunkline_get_line_collated(), chunkline_newline_removal(), http_header_line(), and sldns_buffer_write_u8().

## ◆ sldns_buffer_write_u8()

INLINE void sldns_buffer_write_u8 | ( | sldns_buffer * | buffer,
|  | uint8_t | data )

writes the given byte of data at the current position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | data | the 8 bits to write

References sldns_buffer::_position, and sldns_buffer_write_u8_at().

Referenced by chaos_replystr(), chunkline_get_line(), compress_owner(), dname_buffer_write(), dname_setup_bufs(), hex_to_buf(), process_bind_contents(), readkeyword_bindfile(), skip_to_special(), write_compressed_dname(), write_soa_serial_to_buf(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_write_u16_at()

INLINE void sldns_buffer_write_u16_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | uint16_t | data )

writes the given 2 byte integer at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer
  [in] | data | the 16 bits to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by chaos_replystr(), compress_rdata(), decompress_rr_into_buffer(), handle_newq(), libworker_attach_mesh(), libworker_fg(), qlist_add_line(), qlist_parse_line(), query_error(), reply_info_encode(), sldns_buffer_write_u16(), write_q(), xfr_create_ixfr_packet(), and xfr_create_soa_probe_packet().

## ◆ sldns_buffer_write_u16()

INLINE void sldns_buffer_write_u16 | ( | sldns_buffer * | buffer,
|  | uint16_t | data )

writes the given 2 byte integer at the current position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | data | the 16 bits to write

References sldns_buffer::_position, and sldns_buffer_write_u16_at().

Referenced by chaos_replystr(), decompress_rr_into_buffer(), dname_setup_bufs(), extended_error_encode(), insert_query(), packed_rrset_encode(), qinfo_query_encode(), reply_info_encode(), serviced_encode(), serviced_gen_query(), write_compressed_dname(), write_soa_serial_to_buf(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_write_u32_at()

INLINE void sldns_buffer_write_u32_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | uint32_t | data )

writes the given 4 byte integer at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer
  [in] | data | the 32 bits to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by sldns_buffer_write_u32().

## ◆ sldns_buffer_write_u48_at()

INLINE void sldns_buffer_write_u48_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | uint64_t | data )

writes the given 6 byte integer at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer
  [in] | data | the (lower) 48 bits to write

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by sldns_buffer_write_u48().

## ◆ sldns_buffer_write_u32()

INLINE void sldns_buffer_write_u32 | ( | sldns_buffer * | buffer,
|  | uint32_t | data )

writes the given 4 byte integer at the current position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | data | the 32 bits to write

References sldns_buffer::_position, and sldns_buffer_write_u32_at().

Referenced by chaos_replystr(), decompress_rr_into_buffer(), packed_rrset_encode(), rrset_canonicalize_to_buffer(), write_soa_serial_to_buf(), and xfr_create_ixfr_packet().

## ◆ sldns_buffer_write_u48()

INLINE void sldns_buffer_write_u48 | ( | sldns_buffer * | buffer,
|  | uint64_t | data )

writes the given 6 byte integer at the current position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | data | the 48 bits to write

References sldns_buffer::_position, and sldns_buffer_write_u48_at().

## ◆ sldns_buffer_read_at()

INLINE void sldns_buffer_read_at | ( | sldns_buffer * | buffer,
|  | size_t | at,
|  | void * | data,
|  | size_t | count )

copies count bytes of data at the given position to the given data-array

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer to start
  [out] | data | buffer to copy to
  [in] | count | the length of the data to copy

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by sldns_buffer_read().

## ◆ sldns_buffer_read()

INLINE void sldns_buffer_read | ( | sldns_buffer * | buffer,
|  | void * | data,
|  | size_t | count )

copies count bytes of data at the current position to the given data-array

Parameters

  [in] | buffer | the buffer
  [out] | data | buffer to copy to
  [in] | count | the length of the data to copy

References sldns_buffer::_position, and sldns_buffer_read_at().

Referenced by parse_packet(), and parse_section().

## ◆ sldns_buffer_read_u8_at()

INLINE uint8_t sldns_buffer_read_u8_at | ( | sldns_buffer * | buffer,
|  | size_t | at )

returns the byte value at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | the position in the buffer

Returns
  1 byte integer

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by chunkline_count_parens(), chunkline_is_comment_line_or_empty(), chunkline_newline_removal(), chunkline_remove_trailcomment(), http_header_done(), http_header_line(), readkeyword_bindfile(), recv_one(), sldns_bskipcs(), and sldns_buffer_read_u8().

## ◆ sldns_buffer_read_u8()

INLINE uint8_t sldns_buffer_read_u8 | ( | sldns_buffer * | buffer | ) |

returns the byte value at the current position in the buffer

Parameters

  [in] | buffer | the buffer

Returns
  1 byte integer

References sldns_buffer::_position, and sldns_buffer_read_u8_at().

Referenced by nsec_at_apex(), parse_edns_from_query_pkt(), pkt_dname_len(), query_dname_len(), and sldns_bgetc().

## ◆ sldns_buffer_read_u16_at()

INLINE uint16_t sldns_buffer_read_u16_at | ( | sldns_buffer * | buffer,
|  | size_t | at )

returns the 2-byte integer value at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | position in the buffer

Returns
  2 byte integer

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by answer_notify(), auth_answer_encode(), auth_error_encode(), comm_point_tcp_handle_read(), local_encode(), local_error_encode(), log_reply_info(), mesh_send_reply(), query_error(), rpz_local_encode(), server_stats_insquery(), serviced_callbacks(), sldns_buffer_read_u16(), ssl_handle_read(), and worker_handle_request().

## ◆ sldns_buffer_read_u16()

INLINE uint16_t sldns_buffer_read_u16 | ( | sldns_buffer * | buffer | ) |

returns the 2-byte integer value at the current position in the buffer

Parameters

  [in] | buffer | the buffer

Returns
  2 byte integer

References sldns_buffer::_position, and sldns_buffer_read_u16_at().

Referenced by analyze(), analyze_rr(), auth_zone_parse_notify_serial(), calc_size(), check_packet_ok(), check_xfer_packet(), chunk_rrlist_get_current(), nsec_at_apex(), parse_edns_from_query_pkt(), parse_packet(), parse_query_section(), parse_section(), pkt_rrsig_covered(), query_info_parse(), rdata_copy(), sig_is_double(), and skip_ttl_rdata().

## ◆ sldns_buffer_read_u32_at()

INLINE uint32_t sldns_buffer_read_u32_at | ( | sldns_buffer * | buffer,
|  | size_t | at )

returns the 4-byte integer value at the given position in the buffer

Parameters

  [in] | buffer | the buffer
  [in] | at | position in the buffer

Returns
  4 byte integer

References sldns_buffer::_data, and sldns_buffer_available_at().

Referenced by check_xfer_packet(), and sldns_buffer_read_u32().

## ◆ sldns_buffer_read_u32()

INLINE uint32_t sldns_buffer_read_u32 | ( | sldns_buffer * | buffer | ) |

returns the 4-byte integer value at the current position in the buffer

Parameters

  [in] | buffer | the buffer

Returns
  4 byte integer

References sldns_buffer::_position, and sldns_buffer_read_u32_at().

Referenced by analyze_rr(), auth_zone_parse_notify_serial(), check_packet_ok(), check_xfer_packet(), and chunk_rrlist_get_current().

## ◆ sldns_buffer_status()

INLINE int sldns_buffer_status | ( | sldns_buffer * | buffer | ) |

returns the status of the buffer

Parameters

  [in] | buffer |

Returns
  the status

References sldns_buffer::_status_err.

Referenced by sldns_buffer_status_ok().

## ◆ sldns_buffer_status_ok()

INLINE int sldns_buffer_status_ok | ( | sldns_buffer * | buffer | ) |

returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise

Parameters

  [in] | buffer | the buffer

Returns
  true or false

References sldns_buffer_status().

## ◆ sldns_buffer_printf()

int sldns_buffer_printf | ( | sldns_buffer * | buffer,
|  | const char * | format,
|  |  | ... )

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.

References sldns_buffer_copy(), and sldns_buffer_free().

## ◆ sldns_buffer_free()

int void sldns_buffer_free | ( | sldns_buffer * | buffer | ) |

frees the buffer.

Parameters

  [in] | *buffer | the buffer to be freed

References sldns_buffer::_data, and sldns_buffer::_fixed.

Referenced by anchors_apply_cfg(), anchors_test(), answer_callback_from_entry(), check_mod(), comm_point_create_http_out(), comm_point_create_tcp_handler(), comm_point_create_tcp_out(), comm_point_delete(), comm_point_drop_reply(), delete_fake_pending(), delete_replay_answer(), delete_replylist(), dname_test(), dstest_file(), fake_pending_callback(), libworker_delete_env(), libworker_setup(), listen_delete(), listen_delete(), log_dns_msg(), main(), mesh_delete(), msgparse_test(), msgtostr(), nsec3_hash_test(), outnet_serviced_query_stop(), outside_network_delete(), process_answer_detail(), read_entry(), send_em(), service(), sldns_buffer_printf(), verifytest_file(), worker_delete(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ sldns_buffer_copy()

void sldns_buffer_copy | ( | sldns_buffer * | result,
|  | sldns_buffer * | from )

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.

Parameters

  [out] | *result | resulting buffer which is copied to.
  [in] | *from | what to copy to result.

References sldns_buffer_begin(), sldns_buffer_capacity(), sldns_buffer_clear(), sldns_buffer_flip(), sldns_buffer_limit(), and sldns_buffer_write().

Referenced by entry_to_buf(), mesh_make_new_space(), mesh_send_reply(), outnet_comm_point_for_tcp(), reply_and_prefetch(), and sldns_buffer_printf().