59 uint16_t pointer_target;
60 uint8_t pointer_target_buf[2];
62 size_t compression_pos = 0;
64 unsigned int pointer_count = 0;
72 label_size = wire[*pos];
73 while (label_size > 0) {
75 while (label_size >= 192) {
76 if (compression_pos == 0) {
77 compression_pos = *pos + 2;
86 pointer_target_buf[0] = wire[*pos] & 63;
87 pointer_target_buf[1] = wire[*pos + 1];
88 pointer_target = ldns_read_uint16(pointer_target_buf);
90 if (pointer_target == 0) {
92 }
else if (pointer_target >= max) {
97 *pos = pointer_target;
98 label_size = wire[*pos];
105 if (*pos + 1 + label_size > max) {
113 tmp_dname[dname_pos] = label_size;
114 if (label_size > 0) {
121 memcpy(&tmp_dname[dname_pos], &wire[*pos], label_size);
122 dname_pos += label_size;
123 *pos = *pos + label_size;
126 label_size = wire[*pos];
130 if (compression_pos > 0) {
131 *pos = compression_pos;
140 tmp_dname[dname_pos] = 0;
144 (uint16_t) dname_pos, tmp_dname);
152 #define LDNS_STATUS_CHECK_RETURN(st) {if (st != LDNS_STATUS_OK) { return st; }}
153 #define LDNS_STATUS_CHECK_GOTO(st, label) {if (st != LDNS_STATUS_OK) { goto label; }}
159 size_t cur_rdf_length;
172 if (*pos + 2 > max) {
176 rd_length = ldns_read_uint16(&wire[*pos]);
179 if (*pos + rd_length > max) {
183 end = *pos + (size_t) rd_length;
192 descriptor, rdf_index);
196 switch (cur_rdf_type) {
238 cur_rdf_length = ((size_t) wire[*pos]) + 1;
242 if (*pos + 2 > end) {
246 (size_t) ldns_read_uint16(&wire[*pos]) + 2;
249 if (*pos + 4 > end) {
253 (size_t) wire[*pos] +
254 (
size_t) ldns_read_uint16(&wire[*pos + 2]) + 4;
259 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;
330 if (*pos + 4 > max) {
342 if (*pos + 4 > max) {
366 ldns_wire2pkt_hdr(
ldns_pkt *packet,
const uint8_t *wire,
size_t max,
size_t *pos)
398 ldns_buffer_limit(buffer));
410 uint8_t have_edns = 0;
418 status = ldns_wire2pkt_hdr(packet, wire, max, &pos);
@ LDNS_STATUS_WIRE_INCOMPLETE_QUESTION
@ LDNS_STATUS_WIRE_RDATA_ERR
@ LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL
@ LDNS_STATUS_WIRE_INCOMPLETE_HEADER
@ LDNS_STATUS_LABEL_OVERFLOW
@ LDNS_STATUS_INTERNAL_ERR
@ LDNS_STATUS_WIRE_INCOMPLETE_ANSWER
@ LDNS_STATUS_INVALID_POINTER
@ LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY
@ LDNS_STATUS_PACKET_OVERFLOW
@ LDNS_STATUS_DOMAINNAME_OVERFLOW
enum ldns_enum_status ldns_status
Including this file will include all ldns files, and define some lookup tables.
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
void ldns_pkt_set_ad(ldns_pkt *p, signed char b)
Set the packet's ad bit.
void ldns_pkt_set_size(ldns_pkt *p, size_t s)
Set the packet's size.
void ldns_pkt_set_cd(ldns_pkt *p, signed char b)
Set the packet's cd bit.
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
ldns_rr_list * ldns_pkt_question(const ldns_pkt *p)
Return the packet's question section.
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *p)
Return the packet's authority section.
void ldns_pkt_set_qr(ldns_pkt *p, signed char b)
Set the packet's qr bit.
uint16_t ldns_pkt_ancount(const ldns_pkt *p)
Return the packet's an count.
uint16_t ldns_pkt_nscount(const ldns_pkt *p)
Return the packet's ns count.
void ldns_pkt_set_aa(ldns_pkt *p, signed char b)
Set the packet's aa bit.
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *p)
Return the packet's answer section.
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
void ldns_pkt_set_rd(ldns_pkt *p, signed char b)
Set the packet's rd bit.
void ldns_pkt_set_tc(ldns_pkt *p, signed char b)
Set the packet's tc bit.
void ldns_pkt_set_rcode(ldns_pkt *p, uint8_t c)
Set the packet's response code.
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
enum ldns_enum_pkt_section ldns_pkt_section
void ldns_pkt_set_qdcount(ldns_pkt *p, uint16_t c)
Set the packet's qd count.
uint16_t ldns_pkt_qdcount(const ldns_pkt *p)
Return the packet's qd count.
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's EDNS data.
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *p)
Return the packet's additional section.
void ldns_pkt_set_arcount(ldns_pkt *p, uint16_t c)
Set the packet's arcount.
void ldns_pkt_set_opcode(ldns_pkt *p, ldns_pkt_opcode c)
Set the packet's opcode.
uint16_t ldns_pkt_arcount(const ldns_pkt *p)
Return the packet's ar count.
void ldns_pkt_set_id(ldns_pkt *p, uint16_t id)
Set the packet's id.
void ldns_pkt_set_ancount(ldns_pkt *p, uint16_t c)
Set the packet's an count.
void ldns_pkt_set_ra(ldns_pkt *p, signed char b)
Set the packet's ra bit.
void ldns_pkt_set_tsig(ldns_pkt *p, ldns_rr *t)
Set the packet's tsig rr.
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet's edns extended rcode.
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
@ LDNS_SECTION_ADDITIONAL
void ldns_pkt_set_nscount(ldns_pkt *p, uint16_t c)
Set the packet's ns count.
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
#define LDNS_RDF_SIZE_WORD
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
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_BYTE
#define LDNS_RDF_SIZE_6BYTES
#define LDNS_RDF_SIZE_16BYTES
#define LDNS_RDF_SIZE_8BYTES
@ LDNS_RDF_TYPE_INT32
32 bits
@ LDNS_RDF_TYPE_TAG
A non-zero sequence of US-ASCII letters and numbers in lower case.
@ LDNS_RDF_TYPE_NSAP
NSAP.
@ LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
@ LDNS_RDF_TYPE_B32_EXT
b32 string
@ LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
@ LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
@ LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
@ LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
@ LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
@ LDNS_RDF_TYPE_PERIOD
period
@ LDNS_RDF_TYPE_B64
b64 string
@ LDNS_RDF_TYPE_AAAA
AAAA record.
@ LDNS_RDF_TYPE_UNKNOWN
unknown types
@ LDNS_RDF_TYPE_WKS
well known services
@ LDNS_RDF_TYPE_DNAME
domain name
@ LDNS_RDF_TYPE_TIME
time (32 bits)
@ LDNS_RDF_TYPE_SVCPARAMS
draft-ietf-dnsop-svcb-https
@ LDNS_RDF_TYPE_NSEC
nsec type codes
@ LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
@ LDNS_RDF_TYPE_APL
apl data
@ LDNS_RDF_TYPE_A
A record.
@ LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5....
@ LDNS_RDF_TYPE_LOC
location data
@ LDNS_RDF_TYPE_INT16_DATA
variable length any type rdata where the length is specified by the first 2 bytes
@ LDNS_RDF_TYPE_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
@ LDNS_RDF_TYPE_ATMA
ATMA.
@ LDNS_RDF_TYPE_HEX
hex string
@ LDNS_RDF_TYPE_CLASS
a class
@ LDNS_RDF_TYPE_INT8
8 bits
@ LDNS_RDF_TYPE_MATCHING_TYPE
@ LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
@ LDNS_RDF_TYPE_CERTIFICATE_USAGE
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
@ LDNS_RDF_TYPE_STR
txt string
@ LDNS_RDF_TYPE_INT16
16 bits
@ LDNS_RDF_TYPE_ALG
a key algorithm
@ LDNS_RDF_TYPE_AMTRELAY
draft-ietf-mboned-driad-amt-discovery
@ LDNS_RDF_TYPE_TSIGTIME
tsig time 48 bits
@ LDNS_RDF_TYPE_TYPE
a RR type
#define LDNS_RDF_SIZE_DOUBLEWORD
enum ldns_enum_rdf_type ldns_rdf_type
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
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.
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
#define LDNS_MAX_LABELLEN
Maximum length of a dname label.
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
@ LDNS_RR_TYPE_OPT
OPT record RFC 6891.
signed char ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field)
returns the rdf type for the given rdata field number of the rr type for the given descriptor.
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
sets the ttl in the rr structure.
void ldns_rr_set_question(ldns_rr *rr, signed char question)
sets the question flag in the rr structure.
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.
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
#define LDNS_MAX_POINTERS
Maximum number of pointers in 1 dname.
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
signed char ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
implementation of buffers to ease operations
Resource record data field.
Contains all information about resource record types.
#define LDNS_XMALLOC(type, count)
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.
#define LDNS_STATUS_CHECK_RETURN(st)
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)
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.
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.
#define LDNS_OPCODE_WIRE(wirebuf)
#define LDNS_ID_WIRE(wirebuf)
#define LDNS_CD_WIRE(wirebuf)
#define LDNS_AD_WIRE(wirebuf)
#define LDNS_AA_WIRE(wirebuf)
#define LDNS_RCODE_WIRE(wirebuf)
#define LDNS_QDCOUNT(wirebuf)
#define LDNS_RD_WIRE(wirebuf)
#define LDNS_RA_WIRE(wirebuf)
#define LDNS_NSCOUNT(wirebuf)
#define LDNS_ANCOUNT(wirebuf)
#define LDNS_ARCOUNT(wirebuf)
#define LDNS_QR_WIRE(wirebuf)
#define LDNS_TC_WIRE(wirebuf)