59 uint16_t pointer_target;
60 uint8_t pointer_target_buf[2];
62 size_t uncompressed_length = 0;
63 size_t compression_pos = 0;
65 unsigned int pointer_count = 0;
73 label_size = wire[*pos];
74 while (label_size > 0) {
76 while (label_size >= 192) {
77 if (compression_pos == 0) {
78 compression_pos = *pos + 2;
87 pointer_target_buf[0] = wire[*pos] & 63;
88 pointer_target_buf[1] = wire[*pos + 1];
89 pointer_target = ldns_read_uint16(pointer_target_buf);
91 if (pointer_target == 0) {
93 }
else if (pointer_target >= max) {
98 *pos = pointer_target;
99 label_size = wire[*pos];
106 if (*pos + 1 + label_size > max) {
114 tmp_dname[dname_pos] = label_size;
115 if (label_size > 0) {
122 memcpy(&tmp_dname[dname_pos], &wire[*pos], label_size);
123 uncompressed_length += label_size + 1;
124 dname_pos += label_size;
125 *pos = *pos + label_size;
128 label_size = wire[*pos];
132 if (compression_pos > 0) {
133 *pos = compression_pos;
142 tmp_dname[dname_pos] = 0;
146 (uint16_t) dname_pos, tmp_dname);
154 #define LDNS_STATUS_CHECK_RETURN(st) {if (st != LDNS_STATUS_OK) { return st; }}
155 #define LDNS_STATUS_CHECK_GOTO(st, label) {if (st != LDNS_STATUS_OK) { goto label; }}
161 size_t cur_rdf_length;
174 if (*pos + 2 > max) {
178 rd_length = ldns_read_uint16(&wire[*pos]);
181 if (*pos + rd_length > max) {
185 end = *pos + (size_t) rd_length;
194 descriptor, rdf_index);
198 switch (cur_rdf_type) {
240 cur_rdf_length = ((size_t) wire[*pos]) + 1;
244 if (*pos + 2 > end) {
248 (size_t) ldns_read_uint16(&wire[*pos]) + 2;
251 if (*pos + 4 > end) {
255 (size_t) wire[*pos] +
256 (
size_t) ldns_read_uint16(&wire[*pos + 2]) + 4;
261 cur_rdf_length = ((size_t) wire[*pos]) + 1;
279 cur_rdf_length = end - *pos;
284 if (cur_rdf_length > 0) {
285 if (cur_rdf_length + *pos > end) {
292 memcpy(data, &wire[*pos], cur_rdf_length);
295 cur_rdf_length, data);
296 *pos = *pos + cur_rdf_length;
331 if (*pos + 4 > max) {
343 if (*pos + 4 > max) {
367 ldns_wire2pkt_hdr(
ldns_pkt *packet,
const uint8_t *wire,
size_t max,
size_t *pos)
399 ldns_buffer_limit(buffer));
411 uint8_t have_edns = 0;
415 status = ldns_wire2pkt_hdr(packet, wire, max, &pos);
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet's an count.
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
implementation of buffers to ease operations
#define LDNS_AD_WIRE(wirebuf)
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
void ldns_pkt_set_ra(ldns_pkt *packet, _Bool ra)
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
#define LDNS_RD_WIRE(wirebuf)
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet's qd count.
void ldns_pkt_set_cd(ldns_pkt *packet, _Bool cd)
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t index)
returns the rdf type for the given rdata field number of the rr type for the given descriptor...
#define LDNS_XMALLOC(type, count)
void ldns_pkt_set_rd(ldns_pkt *packet, _Bool rd)
#define LDNS_RDF_SIZE_DOUBLEWORD
#define LDNS_TC_WIRE(wirebuf)
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
#define LDNS_RDF_SIZE_6BYTES
#define LDNS_QDCOUNT(wirebuf)
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
#define LDNS_AA_WIRE(wirebuf)
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
#define LDNS_RDF_SIZE_BYTE
#define LDNS_NSCOUNT(wirebuf)
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet's tsig rr.
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
protocol and port bitmaps
A non-zero sequence of US-ASCII letters and numbers in lower case.
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet's respons code.
A encoding of the value field as specified [RFC1035], Section 5.1., encoded as remaining rdata.
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet's size.
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet's arcount.
Including this file will include all ldns files, and define some lookup tables.
#define LDNS_RDF_SIZE_16BYTES
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
void ldns_pkt_set_ad(ldns_pkt *packet, _Bool ad)
ldns_status ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
enum ldns_enum_rdf_type ldns_rdf_type
#define LDNS_STATUS_CHECK_RETURN(st)
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
void ldns_pkt_set_aa(ldns_pkt *packet, _Bool aa)
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
ldns_status ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
variable length any type rdata where the length is specified by the first 2 bytes ...
_Bool ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
ldns_status ldns_buffer2pkt_wire(ldns_pkt **packet, const ldns_buffer *buffer)
converts the data in the ldns_buffer (in wire format) to a DNS packet.
#define LDNS_QR_WIRE(wirebuf)
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet's ns count.
#define LDNS_CD_WIRE(wirebuf)
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's edns data.
size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
returns the maximum number of rdata fields of the rr type this descriptor describes.
#define LDNS_MAX_LABELLEN
Maximum length of a dname label.
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet's id.
void ldns_pkt_set_qr(ldns_pkt *packet, _Bool qr)
Contains all information about resource record types.
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet's opcode.
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet's edns extended rcode.
nsec3 base32 string (with length byte on wire
void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
sets the ttl in the rr structure.
enum ldns_enum_status ldns_status
ldns_rdf * ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data)
allocates a new rdf structure and fills it.
ldns_rdf * ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
allocates a new rdf structure and fills it.
#define LDNS_RDF_SIZE_WORD
#define LDNS_RDF_SIZE_8BYTES
_Bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Resource record data field.
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
#define LDNS_OPCODE_WIRE(wirebuf)
#define LDNS_ID_WIRE(wirebuf)
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
#define LDNS_RA_WIRE(wirebuf)
void ldns_rr_set_question(ldns_rr *rr, _Bool question)
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
#define LDNS_MAX_POINTERS
Maximum number of pointers in 1 dname.
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
#define LDNS_ANCOUNT(wirebuf)
#define LDNS_ARCOUNT(wirebuf)
enum ldns_enum_pkt_section ldns_pkt_section
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
8 * 8 bit hex numbers separated by dashes.
6 * 8 bit hex numbers separated by dashes.
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
#define LDNS_RCODE_WIRE(wirebuf)
ldns_status ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max, size_t *pos, ldns_pkt_section section)
converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.
ldns_status ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the...
#define LDNS_STATUS_CHECK_GOTO(st, label)
void ldns_pkt_set_tc(ldns_pkt *packet, _Bool tc)