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;
281 cur_rdf_length = end - *pos;
286 if (cur_rdf_length > 0) {
287 if (cur_rdf_length + *pos > end) {
294 memcpy(data, &wire[*pos], cur_rdf_length);
297 cur_rdf_length, data);
298 *pos = *pos + cur_rdf_length;
332 if (*pos + 4 > max) {
344 if (*pos + 4 > max) {
368 ldns_wire2pkt_hdr(
ldns_pkt *packet,
const uint8_t *wire,
size_t max,
size_t *pos)
400 ldns_buffer_limit(buffer));
412 uint8_t have_edns = 0;
420 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_tc(ldns_pkt *packet, bool tc)
Set the packet's tc bit.
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet's an count.
void ldns_pkt_set_rd(ldns_pkt *packet, bool rd)
Set the packet's rd bit.
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet's tsig rr.
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet's opcode.
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
void ldns_pkt_set_aa(ldns_pkt *packet, bool aa)
Set the packet's aa bit.
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet's ns count.
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet's size.
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
void ldns_pkt_set_ad(ldns_pkt *packet, bool ad)
Set the packet's ad bit.
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
void ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
Set the packet's cd bit.
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet's qd count.
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's EDNS data.
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
void ldns_pkt_set_ra(ldns_pkt *packet, bool ra)
Set the packet's ra bit.
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet's id.
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
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
void ldns_pkt_set_qr(ldns_pkt *packet, bool qr)
Set the packet's qr bit.
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet's arcount.
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet's response code.
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
enum ldns_enum_pkt_section ldns_pkt_section
@ LDNS_SECTION_ADDITIONAL
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.
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.
#define LDNS_RDF_SIZE_WORD
#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
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.
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
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.
void ldns_rr_set_question(ldns_rr *rr, bool question)
sets the question flag in the rr structure.
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.
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
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.
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
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_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.
#define LDNS_MAX_LABELLEN
Maximum length of a dname label.
@ LDNS_RR_TYPE_OPT
OPT record RFC 6891.
#define LDNS_MAX_POINTERS
Maximum number of pointers in 1 dname.
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
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)