ldns documentation

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

wire2host.c
Go to the documentation of this file.
1 /*
2 * wire2host.c
3 *
4 * conversion routines from the wire to the host
5 * format.
6 * This will usually just a re-ordering of the
7 * data (as we store it in network format)
8 *
9 * a Net::DNS like library for C
10 *
11 * (c) NLnet Labs, 2004-2006
12 *
13 * See the file LICENSE for the license
14 */
15
16
17 #include <ldns/config.h>
18
19 #include <ldns/ldns.h>
20 /*#include <ldns/wire2host.h>*/
21
22 #include <strings.h>
23 #include <limits.h>
24
25
26
27 /*
28 * Set of macro's to deal with the dns message header as specified
29 * in RFC1035 in portable way.
30 *
31 */
32
33 /*
34 *
35 * 1 1 1 1 1 1
36 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
37 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
38 * | ID |
39 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
40 * |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE |
41 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
42 * | QDCOUNT |
43 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
44 * | ANCOUNT |
45 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
46 * | NSCOUNT |
47 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
48 * | ARCOUNT |
49 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
50 *
51 */
52
53
54 /* allocates memory to *dname! */
55 ldns_status
56 ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
57 {
58 uint8_t label_size;
59 uint16_t pointer_target;
60 uint8_t pointer_target_buf[2];
61 size_t dname_pos = 0;
62 size_t uncompressed_length = 0;
63 size_t compression_pos = 0;
64 uint8_t tmp_dname[LDNS_MAX_DOMAINLEN];
65 unsigned int pointer_count = 0;
66
67 if (pos == NULL) {
68 return LDNS_STATUS_WIRE_RDATA_ERR;
69 }
70 if (*pos >= max) {
71 return LDNS_STATUS_PACKET_OVERFLOW;
72 }
73 label_size = wire[*pos];
74 while (label_size > 0) {
75 /* compression */
76 while (label_size >= 192) {
77 if (compression_pos == 0) {
78 compression_pos = *pos + 2;
79 }
80
81 pointer_count++;
82
83 /* remove first two bits */
84 if (*pos + 2 > max) {
85 return LDNS_STATUS_PACKET_OVERFLOW;
86 }
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);
90
91 if (pointer_target == 0) {
92 return LDNS_STATUS_INVALID_POINTER;
93 } else if (pointer_target >= max) {
94 return LDNS_STATUS_INVALID_POINTER;
95 } else if (pointer_count > LDNS_MAX_POINTERS) {
96 return LDNS_STATUS_INVALID_POINTER;
97 }
98 *pos = pointer_target;
99 label_size = wire[*pos];
100 }
101 if(label_size == 0)
102 break; /* break from pointer to 0 byte */
103 if (label_size > LDNS_MAX_LABELLEN) {
104 return LDNS_STATUS_LABEL_OVERFLOW;
105 }
106 if (*pos + 1 + label_size > max) {
107 return LDNS_STATUS_LABEL_OVERFLOW;
108 }
109
110 /* check space for labelcount itself */
111 if (dname_pos + 1 > LDNS_MAX_DOMAINLEN) {
112 return LDNS_STATUS_DOMAINNAME_OVERFLOW;
113 }
114 tmp_dname[dname_pos] = label_size;
115 if (label_size > 0) {
116 dname_pos++;
117 }
118 *pos = *pos + 1;
119 if (dname_pos + label_size > LDNS_MAX_DOMAINLEN) {
120 return LDNS_STATUS_DOMAINNAME_OVERFLOW;
121 }
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;
126
127 if (*pos < max) {
128 label_size = wire[*pos];
129 }
130 }
131
132 if (compression_pos > 0) {
133 *pos = compression_pos;
134 } else {
135 *pos = *pos + 1;
136 }
137
138 if (dname_pos >= LDNS_MAX_DOMAINLEN) {
139 return LDNS_STATUS_DOMAINNAME_OVERFLOW;
140 }
141
142 tmp_dname[dname_pos] = 0;
143 dname_pos++;
144
145 *dname = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_DNAME,
146 (uint16_t) dname_pos, tmp_dname);
147 if (!*dname) {
148 return LDNS_STATUS_MEM_ERR;
149 }
150 return LDNS_STATUS_OK;
151 }
152
153 /* maybe make this a goto error so data can be freed or something/ */
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) { /*printf("STG %s:%d: status code %d\n", __FILE__, __LINE__, st);*/ goto label; }}
156
157 ldns_status
158 ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
159 {
160 size_t end;
161 size_t cur_rdf_length;
162 uint8_t rdf_index;
163 uint8_t *data;
164 uint16_t rd_length;
165 ldns_rdf *cur_rdf = NULL;
166 ldns_rdf_type cur_rdf_type;
167 const ldns_rr_descriptor *descriptor;
168 ldns_status status;
169
170 assert(rr != NULL);
171
172 descriptor = ldns_rr_descript(ldns_rr_get_type(rr));
173
174 if (*pos + 2 > max) {
175 return LDNS_STATUS_PACKET_OVERFLOW;
176 }
177
178 rd_length = ldns_read_uint16(&wire[*pos]);
179 *pos = *pos + 2;
180
181 if (*pos + rd_length > max) {
182 return LDNS_STATUS_PACKET_OVERFLOW;
183 }
184
185 end = *pos + (size_t) rd_length;
186
187 rdf_index = 0;
188 while (*pos < end &&
189 rdf_index < ldns_rr_descriptor_maximum(descriptor)) {
190
191 cur_rdf_length = 0;
192
193 cur_rdf_type = ldns_rr_descriptor_field_type(
194 descriptor, rdf_index);
195
196 /* handle special cases immediately, set length
197 for fixed length rdata and do them below */
198 switch (cur_rdf_type) {
199 case LDNS_RDF_TYPE_DNAME:
200 status = ldns_wire2dname(&cur_rdf, wire, max, pos);
201 LDNS_STATUS_CHECK_RETURN(status);
202 break;
203 case LDNS_RDF_TYPE_CLASS:
204 case LDNS_RDF_TYPE_ALG:
205 case LDNS_RDF_TYPE_INT8:
206 cur_rdf_length = LDNS_RDF_SIZE_BYTE;
207 break;
208 case LDNS_RDF_TYPE_TYPE:
209 case LDNS_RDF_TYPE_INT16:
210 case LDNS_RDF_TYPE_CERT_ALG:
211 cur_rdf_length = LDNS_RDF_SIZE_WORD;
212 break;
213 case LDNS_RDF_TYPE_TIME:
214 case LDNS_RDF_TYPE_INT32:
215 case LDNS_RDF_TYPE_A:
216 case LDNS_RDF_TYPE_PERIOD:
217 cur_rdf_length = LDNS_RDF_SIZE_DOUBLEWORD;
218 break;
219 case LDNS_RDF_TYPE_TSIGTIME:
220 case LDNS_RDF_TYPE_EUI48:
221 cur_rdf_length = LDNS_RDF_SIZE_6BYTES;
222 break;
223 case LDNS_RDF_TYPE_ILNP64:
224 case LDNS_RDF_TYPE_EUI64:
225 cur_rdf_length = LDNS_RDF_SIZE_8BYTES;
226 break;
227 case LDNS_RDF_TYPE_AAAA:
228 cur_rdf_length = LDNS_RDF_SIZE_16BYTES;
229 break;
230 case LDNS_RDF_TYPE_STR:
231 case LDNS_RDF_TYPE_NSEC3_SALT:
232 case LDNS_RDF_TYPE_TAG:
233 /* len is stored in first byte
234 * it should be in the rdf too, so just
235 * copy len+1 from this position
236 */
237 cur_rdf_length = ((size_t) wire[*pos]) + 1;
238 break;
239
240 case LDNS_RDF_TYPE_INT16_DATA:
241 if (*pos + 2 > end) {
242 return LDNS_STATUS_PACKET_OVERFLOW;
243 }
244 cur_rdf_length =
245 (size_t) ldns_read_uint16(&wire[*pos]) + 2;
246 break;
247 case LDNS_RDF_TYPE_HIP:
248 if (*pos + 4 > end) {
249 return LDNS_STATUS_PACKET_OVERFLOW;
250 }
251 cur_rdf_length =
252 (size_t) wire[*pos] +
253 (size_t) ldns_read_uint16(&wire[*pos + 2]) + 4;
254 break;
255 case LDNS_RDF_TYPE_B32_EXT:
256 case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER:
257 /* length is stored in first byte */
258 cur_rdf_length = ((size_t) wire[*pos]) + 1;
259 break;
260 case LDNS_RDF_TYPE_APL:
261 case LDNS_RDF_TYPE_B64:
262 case LDNS_RDF_TYPE_HEX:
263 case LDNS_RDF_TYPE_NSEC:
264 case LDNS_RDF_TYPE_UNKNOWN:
265 case LDNS_RDF_TYPE_SERVICE:
266 case LDNS_RDF_TYPE_LOC:
267 case LDNS_RDF_TYPE_WKS:
268 case LDNS_RDF_TYPE_NSAP:
269 case LDNS_RDF_TYPE_ATMA:
270 case LDNS_RDF_TYPE_IPSECKEY:
271 case LDNS_RDF_TYPE_LONG_STR:
272 case LDNS_RDF_TYPE_NONE:
273 /*
274 * Read to end of rr rdata
275 */
276 cur_rdf_length = end - *pos;
277 break;
278 }
279
280 /* fixed length rdata */
281 if (cur_rdf_length > 0) {
282 if (cur_rdf_length + *pos > end) {
283 return LDNS_STATUS_PACKET_OVERFLOW;
284 }
285 data = LDNS_XMALLOC(uint8_t, rd_length);
286 if (!data) {
287 return LDNS_STATUS_MEM_ERR;
288 }
289 memcpy(data, &wire[*pos], cur_rdf_length);
290
291 cur_rdf = ldns_rdf_new(cur_rdf_type,
292 cur_rdf_length, data);
293 *pos = *pos + cur_rdf_length;
294 }
295
296 if (cur_rdf) {
297 ldns_rr_push_rdf(rr, cur_rdf);
298 cur_rdf = NULL;
299 }
300
301 rdf_index++;
302
303 } /* while (rdf_index < ldns_rr_descriptor_maximum(descriptor)) */
304
305
306 return LDNS_STATUS_OK;
307 }
308
309
310 /* TODO:
311 can *pos be incremented at READ_INT? or maybe use something like
312 RR_CLASS(wire)?
313 uhhm Jelte??
314 */
315 ldns_status
316 ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max,
317 size_t *pos, ldns_pkt_section section)
318 {
319 ldns_rdf *owner = NULL;
320 ldns_rr *rr = ldns_rr_new();
321 ldns_status status;
322
323 status = ldns_wire2dname(&owner, wire, max, pos);
324 LDNS_STATUS_CHECK_GOTO(status, status_error);
325
326 ldns_rr_set_owner(rr, owner);
327
328 if (*pos + 4 > max) {
329 status = LDNS_STATUS_PACKET_OVERFLOW;
330 goto status_error;
331 }
332
333 ldns_rr_set_type(rr, ldns_read_uint16(&wire[*pos]));
334 *pos = *pos + 2;
335
336 ldns_rr_set_class(rr, ldns_read_uint16(&wire[*pos]));
337 *pos = *pos + 2;
338
339 if (section != LDNS_SECTION_QUESTION) {
340 if (*pos + 4 > max) {
341 status = LDNS_STATUS_PACKET_OVERFLOW;
342 goto status_error;
343 }
344 ldns_rr_set_ttl(rr, ldns_read_uint32(&wire[*pos]));
345
346 *pos = *pos + 4;
347 status = ldns_wire2rdf(rr, wire, max, pos);
348
349 LDNS_STATUS_CHECK_GOTO(status, status_error);
350 ldns_rr_set_question(rr, false);
351 } else {
352 ldns_rr_set_question(rr, true);
353 }
354
355 *rr_p = rr;
356 return LDNS_STATUS_OK;
357
358 status_error:
359 ldns_rr_free(rr);
360 return status;
361 }
362
363 static ldns_status
364 ldns_wire2pkt_hdr(ldns_pkt *packet, const uint8_t *wire, size_t max, size_t *pos)
365 {
366 if (*pos + LDNS_HEADER_SIZE > max) {
367 return LDNS_STATUS_WIRE_INCOMPLETE_HEADER;
368 } else {
369 ldns_pkt_set_id(packet, LDNS_ID_WIRE(wire));
370 ldns_pkt_set_qr(packet, LDNS_QR_WIRE(wire));
371 ldns_pkt_set_opcode(packet, LDNS_OPCODE_WIRE(wire));
372 ldns_pkt_set_aa(packet, LDNS_AA_WIRE(wire));
373 ldns_pkt_set_tc(packet, LDNS_TC_WIRE(wire));
374 ldns_pkt_set_rd(packet, LDNS_RD_WIRE(wire));
375 ldns_pkt_set_ra(packet, LDNS_RA_WIRE(wire));
376 ldns_pkt_set_ad(packet, LDNS_AD_WIRE(wire));
377 ldns_pkt_set_cd(packet, LDNS_CD_WIRE(wire));
378 ldns_pkt_set_rcode(packet, LDNS_RCODE_WIRE(wire));
379
380 ldns_pkt_set_qdcount(packet, LDNS_QDCOUNT(wire));
381 ldns_pkt_set_ancount(packet, LDNS_ANCOUNT(wire));
382 ldns_pkt_set_nscount(packet, LDNS_NSCOUNT(wire));
383 ldns_pkt_set_arcount(packet, LDNS_ARCOUNT(wire));
384
385 *pos += LDNS_HEADER_SIZE;
386
387 return LDNS_STATUS_OK;
388 }
389 }
390
391 ldns_status
392 ldns_buffer2pkt_wire(ldns_pkt **packet, ldns_buffer *buffer)
393 {
394 /* lazy */
395 return ldns_wire2pkt(packet, ldns_buffer_begin(buffer),
396 ldns_buffer_limit(buffer));
397
398 }
399
400 ldns_status
401 ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
402 {
403 size_t pos = 0;
404 uint16_t i;
405 ldns_rr *rr;
406 ldns_pkt *packet = ldns_pkt_new();
407 ldns_status status = LDNS_STATUS_OK;
408 int have_edns = 0;
409
410 uint8_t data[4];
411
412 status = ldns_wire2pkt_hdr(packet, wire, max, &pos);
413 LDNS_STATUS_CHECK_GOTO(status, status_error);
414
415 for (i = 0; i < ldns_pkt_qdcount(packet); i++) {
416
417 status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_QUESTION);
418 if (status == LDNS_STATUS_PACKET_OVERFLOW) {
419 status = LDNS_STATUS_WIRE_INCOMPLETE_QUESTION;
420 }
421 LDNS_STATUS_CHECK_GOTO(status, status_error);
422 if (!ldns_rr_list_push_rr(ldns_pkt_question(packet), rr)) {
423 ldns_pkt_free(packet);
424 return LDNS_STATUS_INTERNAL_ERR;
425 }
426 }
427 for (i = 0; i < ldns_pkt_ancount(packet); i++) {
428 status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_ANSWER);
429 if (status == LDNS_STATUS_PACKET_OVERFLOW) {
430 status = LDNS_STATUS_WIRE_INCOMPLETE_ANSWER;
431 }
432 LDNS_STATUS_CHECK_GOTO(status, status_error);
433 if (!ldns_rr_list_push_rr(ldns_pkt_answer(packet), rr)) {
434 ldns_pkt_free(packet);
435 return LDNS_STATUS_INTERNAL_ERR;
436 }
437 }
438 for (i = 0; i < ldns_pkt_nscount(packet); i++) {
439 status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_AUTHORITY);
440 if (status == LDNS_STATUS_PACKET_OVERFLOW) {
441 status = LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY;
442 }
443 LDNS_STATUS_CHECK_GOTO(status, status_error);
444 if (!ldns_rr_list_push_rr(ldns_pkt_authority(packet), rr)) {
445 ldns_pkt_free(packet);
446 return LDNS_STATUS_INTERNAL_ERR;
447 }
448 }
449 for (i = 0; i < ldns_pkt_arcount(packet); i++) {
450 status = ldns_wire2rr(&rr, wire, max, &pos, LDNS_SECTION_ADDITIONAL);
451 if (status == LDNS_STATUS_PACKET_OVERFLOW) {
452 status = LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL;
453 }
454 LDNS_STATUS_CHECK_GOTO(status, status_error);
455
456 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_OPT) {
457 ldns_pkt_set_edns_udp_size(packet, ldns_rr_get_class(rr));
458 ldns_write_uint32(data, ldns_rr_ttl(rr));
459 ldns_pkt_set_edns_extended_rcode(packet, data[0]);
460 ldns_pkt_set_edns_version(packet, data[1]);
461 ldns_pkt_set_edns_z(packet, ldns_read_uint16(&data[2]));
462 /* edns might not have rdfs */
463 if (ldns_rr_rdf(rr, 0)) {
464 ldns_pkt_set_edns_data(packet, ldns_rdf_clone(ldns_rr_rdf(rr, 0)));
465 }
466 ldns_rr_free(rr);
467 have_edns += 1;
468 } else if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_TSIG) {
469 ldns_pkt_set_tsig(packet, rr);
470 ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet) - 1);
471 } else if (!ldns_rr_list_push_rr(ldns_pkt_additional(packet), rr)) {
472 ldns_pkt_free(packet);
473 return LDNS_STATUS_INTERNAL_ERR;
474 }
475 }
476 ldns_pkt_set_size(packet, max);
477 if(have_edns)
478 ldns_pkt_set_arcount(packet, ldns_pkt_arcount(packet)
479 - have_edns);
480
481 *packet_p = packet;
482 return status;
483
484 status_error:
485 ldns_pkt_free(packet);
486 return status;
487 }
ldns_pkt_set_ancount
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet&#39;s an count.
Definition: packet.c:548
ldns_rr_rdf
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition: rr.c:873
ldns_struct_buffer
implementation of buffers to ease operations
Definition: buffer.h:50
LDNS_AD_WIRE
#define LDNS_AD_WIRE(wirebuf)
Definition: wire2host.h:80
LDNS_RDF_TYPE_TIME
time (32 bits)
Definition: rdata.h:84
LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY
Definition: error.h:75
ldns_pkt_new
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
Definition: packet.c:732
ldns_pkt_arcount
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet&#39;s ar count.
Definition: packet.c:117
ldns_rr_set_type
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
Definition: rr.c:792
ldns_pkt_set_ad
void ldns_pkt_set_ad(ldns_pkt *packet, bool ad)
Definition: packet.c:524
LDNS_SECTION_ANSWER
Definition: packet.h:274
LDNS_RDF_TYPE_B64
b64 string
Definition: rdata.h:68
ldns_pkt_set_tc
void ldns_pkt_set_tc(ldns_pkt *packet, bool tc)
Definition: packet.c:476
ldns_pkt_question
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet&#39;s question section.
Definition: packet.c:123
LDNS_RD_WIRE
#define LDNS_RD_WIRE(wirebuf)
Definition: wire2host.h:37
LDNS_RR_TYPE_OPT
Pseudo OPT record...
Definition: rr.h:163
ldns_rr_list_push_rr
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
Definition: rr.c:1096
ldns_pkt_set_qdcount
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet&#39;s qd count.
Definition: packet.c:542
LDNS_RDF_TYPE_UNKNOWN
unknown types
Definition: rdata.h:82
LDNS_STATUS_OK
Definition: error.h:26
ldns_pkt_qdcount
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet&#39;s qd count.
Definition: packet.c:99
ldns_rr_descriptor_field_type
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...
Definition: rr.c:2579
ldns_buffer2pkt_wire
ldns_status ldns_buffer2pkt_wire(ldns_pkt **packet, ldns_buffer *buffer)
converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
Definition: wire2host.c:392
LDNS_RDF_TYPE_TYPE
a RR type
Definition: rdata.h:74
LDNS_RDF_TYPE_NONE
none
Definition: rdata.h:48
LDNS_XMALLOC
#define LDNS_XMALLOC(type, count)
Definition: util.h:51
LDNS_HEADER_SIZE
#define LDNS_HEADER_SIZE
Definition: wire2host.h:32
ldns_pkt_set_ra
void ldns_pkt_set_ra(ldns_pkt *packet, bool ra)
Definition: packet.c:518
LDNS_STATUS_LABEL_OVERFLOW
Definition: error.h:28
LDNS_RDF_SIZE_DOUBLEWORD
#define LDNS_RDF_SIZE_DOUBLEWORD
Definition: rdata.h:35
LDNS_TC_WIRE
#define LDNS_TC_WIRE(wirebuf)
Definition: wire2host.h:43
ldns_rdf_clone
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition: rdata.c:222
LDNS_RDF_TYPE_CLASS
a class
Definition: rdata.h:76
LDNS_RDF_SIZE_6BYTES
#define LDNS_RDF_SIZE_6BYTES
Definition: rdata.h:36
LDNS_QDCOUNT
#define LDNS_QDCOUNT(wirebuf)
Definition: wire2host.h:105
ldns_rr_free
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
Definition: rr.c:75
ldns_pkt_set_qr
void ldns_pkt_set_qr(ldns_pkt *packet, bool qr)
Definition: packet.c:464
LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
Definition: rdata.h:107
LDNS_AA_WIRE
#define LDNS_AA_WIRE(wirebuf)
Definition: wire2host.h:49
ldns_pkt_set_edns_udp_size
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet&#39;s edns udp size.
Definition: packet.c:591
LDNS_RDF_SIZE_BYTE
#define LDNS_RDF_SIZE_BYTE
Definition: rdata.h:33
LDNS_NSCOUNT
#define LDNS_NSCOUNT(wirebuf)
Definition: wire2host.h:113
LDNS_STATUS_INVALID_POINTER
Definition: error.h:33
LDNS_STATUS_WIRE_INCOMPLETE_QUESTION
Definition: error.h:73
ldns_pkt_set_tsig
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet&#39;s tsig rr.
Definition: packet.c:642
ldns_rr_descript
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition: rr.c:2535
LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
Definition: rdata.h:97
LDNS_RDF_TYPE_TAG
A non-zero sequence of US-ASCII letters and numbers in lower case.
Definition: rdata.h:126
ldns_pkt_set_rcode
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet&#39;s respons code.
Definition: packet.c:536
LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5.1., encoded as remaining rdata.
Definition: rdata.h:132
LDNS_RDF_TYPE_APL
apl data
Definition: rdata.h:64
ldns_struct_rr
Resource Record.
Definition: rr.h:299
ldns_pkt_set_size
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet&#39;s size.
Definition: packet.c:585
ldns_pkt_set_arcount
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet&#39;s arcount.
Definition: packet.c:560
ldns.h
Including this file will include all ldns files, and define some lookup tables.
LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
Definition: rdata.h:78
LDNS_RDF_SIZE_16BYTES
#define LDNS_RDF_SIZE_16BYTES
Definition: rdata.h:38
ldns_pkt_nscount
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet&#39;s ns count.
Definition: packet.c:111
ldns_wire2dname
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.
Definition: wire2host.c:56
ldns_rr_set_class
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
Definition: rr.c:798
ldns_rdf_type
enum ldns_enum_rdf_type ldns_rdf_type
Definition: rdata.h:137
LDNS_RDF_TYPE_INT16
16 bits
Definition: rdata.h:54
LDNS_STATUS_CHECK_RETURN
#define LDNS_STATUS_CHECK_RETURN(st)
Definition: wire2host.c:154
ldns_rr_set_question
void ldns_rr_set_question(ldns_rr *rr, bool question)
Definition: rr.c:774
LDNS_MAX_DOMAINLEN
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
Definition: rr.h:33
ldns_wire2pkt
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.
Definition: wire2host.c:401
ldns_pkt_set_edns_z
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet&#39;s edns z value.
Definition: packet.c:609
ldns_pkt_ancount
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet&#39;s an count.
Definition: packet.c:105
LDNS_RDF_TYPE_NSAP
NSAP.
Definition: rdata.h:103
ldns_pkt_set_edns_version
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet&#39;s edns version.
Definition: packet.c:603
LDNS_RDF_TYPE_INT16_DATA
variable length any type rdata where the length is specified by the first 2 bytes ...
Definition: rdata.h:95
LDNS_RDF_TYPE_ALG
a key algorithm
Definition: rdata.h:80
LDNS_STATUS_WIRE_RDATA_ERR
Definition: error.h:125
LDNS_RDF_TYPE_B32_EXT
b32 string
Definition: rdata.h:66
LDNS_RDF_TYPE_A
A record.
Definition: rdata.h:58
LDNS_RDF_TYPE_NSEC
nsec type codes
Definition: rdata.h:72
LDNS_QR_WIRE
#define LDNS_QR_WIRE(wirebuf)
Definition: wire2host.h:61
ldns_pkt_set_nscount
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet&#39;s ns count.
Definition: packet.c:554
LDNS_CD_WIRE
#define LDNS_CD_WIRE(wirebuf)
Definition: wire2host.h:74
ldns_pkt_set_edns_data
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet&#39;s edns data.
Definition: packet.c:615
ldns_rr_descriptor_maximum
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.
Definition: rr.c:2564
LDNS_RDF_TYPE_AAAA
AAAA record.
Definition: rdata.h:60
LDNS_MAX_LABELLEN
#define LDNS_MAX_LABELLEN
Maximum length of a dname label.
Definition: rr.h:31
LDNS_RDF_TYPE_INT32
32 bits
Definition: rdata.h:56
ldns_pkt_set_id
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet&#39;s id.
Definition: packet.c:450
LDNS_SECTION_AUTHORITY
Definition: packet.h:275
ldns_struct_rr_descriptor
Contains all information about resource record types.
Definition: rr.h:340
LDNS_RDF_TYPE_HEX
hex string
Definition: rdata.h:70
ldns_pkt_set_opcode
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet&#39;s opcode.
Definition: packet.c:530
ldns_struct_pkt
DNS packet.
Definition: packet.h:233
ldns_rr_set_owner
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
Definition: rr.c:768
LDNS_RDF_TYPE_PERIOD
period
Definition: rdata.h:86
LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL
Definition: error.h:76
LDNS_RDF_TYPE_STR
txt string
Definition: rdata.h:62
ldns_rr_get_type
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition: rr.c:907
ldns_pkt_set_edns_extended_rcode
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet&#39;s edns extended rcode.
Definition: packet.c:597
LDNS_RR_TYPE_TSIG
Definition: rr.h:211
LDNS_RDF_TYPE_TSIGTIME
tsig time 48 bits
Definition: rdata.h:88
LDNS_STATUS_WIRE_INCOMPLETE_ANSWER
Definition: error.h:74
ldns_pkt_set_rd
void ldns_pkt_set_rd(ldns_pkt *packet, bool rd)
Definition: packet.c:482
LDNS_STATUS_MEM_ERR
Definition: error.h:34
LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
Definition: rdata.h:111
ldns_rr_set_ttl
void ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
sets the ttl in the rr structure.
Definition: rr.c:780
ldns_status
enum ldns_enum_status ldns_status
Definition: error.h:131
ldns_rdf_new_frm_data
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.
Definition: rdata.c:193
ldns_pkt_set_cd
void ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
Definition: packet.c:512
ldns_rdf_new
ldns_rdf * ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
allocates a new rdf structure and fills it.
Definition: rdata.c:179
LDNS_RDF_SIZE_WORD
#define LDNS_RDF_SIZE_WORD
Definition: rdata.h:34
LDNS_RDF_SIZE_8BYTES
#define LDNS_RDF_SIZE_8BYTES
Definition: rdata.h:37
LDNS_RDF_TYPE_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition: rdata.h:116
LDNS_STATUS_DOMAINNAME_OVERFLOW
Definition: error.h:29
ldns_rr_push_rdf
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.
Definition: rr.c:821
ldns_struct_rdf
Resource record data field.
Definition: rdata.h:166
LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition: rdata.h:92
LDNS_OPCODE_WIRE
#define LDNS_OPCODE_WIRE(wirebuf)
Definition: wire2host.h:55
LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
Definition: rdata.h:109
LDNS_RDF_TYPE_INT8
8 bits
Definition: rdata.h:52
LDNS_ID_WIRE
#define LDNS_ID_WIRE(wirebuf)
Definition: wire2host.h:97
ldns_rr_new
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
Definition: rr.c:24
ldns_pkt_authority
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet&#39;s authority section.
Definition: packet.c:135
LDNS_RA_WIRE
#define LDNS_RA_WIRE(wirebuf)
Definition: wire2host.h:92
LDNS_STATUS_WIRE_INCOMPLETE_HEADER
Definition: error.h:72
ldns_pkt_set_aa
void ldns_pkt_set_aa(ldns_pkt *packet, bool aa)
Definition: packet.c:470
ldns_rr_ttl
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition: rr.c:895
LDNS_MAX_POINTERS
#define LDNS_MAX_POINTERS
Maximum number of pointers in 1 dname.
Definition: rr.h:35
ldns_rr_get_class
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition: rr.c:913
LDNS_ANCOUNT
#define LDNS_ANCOUNT(wirebuf)
Definition: wire2host.h:109
LDNS_ARCOUNT
#define LDNS_ARCOUNT(wirebuf)
Definition: wire2host.h:117
ldns_pkt_section
enum ldns_enum_pkt_section ldns_pkt_section
Definition: packet.h:282
LDNS_RDF_TYPE_DNAME
domain name
Definition: rdata.h:50
LDNS_RDF_TYPE_LOC
location data
Definition: rdata.h:99
ldns_pkt_additional
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet&#39;s additional section.
Definition: packet.c:141
ldns_pkt_answer
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet&#39;s answer section.
Definition: packet.c:129
LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:121
LDNS_STATUS_INTERNAL_ERR
Definition: error.h:35
LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:119
ldns_pkt_free
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
Definition: packet.c:784
LDNS_STATUS_PACKET_OVERFLOW
Definition: error.h:32
LDNS_RDF_TYPE_WKS
well known services
Definition: rdata.h:101
LDNS_RDF_TYPE_ATMA
ATMA.
Definition: rdata.h:105
LDNS_RCODE_WIRE
#define LDNS_RCODE_WIRE(wirebuf)
Definition: wire2host.h:68
LDNS_SECTION_QUESTION
Definition: packet.h:273
ldns_wire2rr
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.
Definition: wire2host.c:316
config.h
ldns_wire2rdf
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...
Definition: wire2host.c:158
LDNS_SECTION_ADDITIONAL
Definition: packet.h:276
LDNS_STATUS_CHECK_GOTO
#define LDNS_STATUS_CHECK_GOTO(st, label)
Definition: wire2host.c:155