rdata.c
Go to the documentation of this file.
1/*
2 * rdata.c
3 *
4 * rdata implementation
5 *
6 * a Net::DNS like library for C
7 *
8 * (c) NLnet Labs, 2004-2006
9 *
10 * See the file LICENSE for the license
11 */
12
13#include <ldns/config.h>
14
15#include <ldns/ldns.h>
16
17/*
18 * Access functions
19 * do this as functions to get type checking
20 */
21
22/* read */
23size_t
25{
26 assert(rd != NULL);
27 return rd->_size;
28}
29
32{
33 assert(rd != NULL);
34 return rd->_type;
35}
36
37uint8_t *
39{
40 assert(rd != NULL);
41 return rd->_data;
42}
43
44/* write */
45void
46ldns_rdf_set_size(ldns_rdf *rd, size_t size)
47{
48 assert(rd != NULL);
49 rd->_size = size;
50}
51
52void
54{
55 assert(rd != NULL);
56 rd->_type = type;
57}
58
59void
61{
62 /* only copy the pointer */
63 assert(rd != NULL);
64 rd->_data = data;
65}
66
67/* for types that allow it, return
68 * the native/host order type */
69uint8_t
71{
72 uint8_t data;
73
74 /* only allow 8 bit rdfs */
76 return 0;
77 }
78
79 memcpy(&data, ldns_rdf_data(rd), sizeof(data));
80 return data;
81}
82
83uint16_t
85{
86 uint16_t data;
87
88 /* only allow 16 bit rdfs */
90 return 0;
91 }
92
93 memcpy(&data, ldns_rdf_data(rd), sizeof(data));
94 return ntohs(data);
95}
96
97uint32_t
99{
100 uint32_t data;
101
102 /* only allow 32 bit rdfs */
104 return 0;
105 }
106
107 memcpy(&data, ldns_rdf_data(rd), sizeof(data));
108 return ntohl(data);
109}
110
111time_t
113{
114 uint32_t data;
115
116 /* only allow 32 bit rdfs */
119 return 0;
120 }
121 memcpy(&data, ldns_rdf_data(rd), sizeof(data));
122 return (time_t)ntohl(data);
123}
124
125ldns_rdf *
127{
128 return ldns_rdf_new_frm_data(type, LDNS_RDF_SIZE_BYTE, &value);
129}
130
131ldns_rdf *
133{
134 uint16_t *rdf_data = LDNS_XMALLOC(uint16_t, 1);
135 ldns_rdf* rdf;
136 if (!rdf_data) {
137 return NULL;
138 }
139 ldns_write_uint16(rdf_data, value);
140 rdf = ldns_rdf_new(type, LDNS_RDF_SIZE_WORD, rdf_data);
141 if(!rdf)
142 LDNS_FREE(rdf_data);
143 return rdf;
144}
145
146ldns_rdf *
148{
149 uint32_t *rdf_data = LDNS_XMALLOC(uint32_t, 1);
150 ldns_rdf* rdf;
151 if (!rdf_data) {
152 return NULL;
153 }
154 ldns_write_uint32(rdf_data, value);
155 rdf = ldns_rdf_new(type, LDNS_RDF_SIZE_DOUBLEWORD, rdf_data);
156 if(!rdf)
157 LDNS_FREE(rdf_data);
158 return rdf;
159}
160
161ldns_rdf *
162ldns_native2rdf_int16_data(size_t size, uint8_t *data)
163{
164 uint8_t *rdf_data = LDNS_XMALLOC(uint8_t, size + 2);
165 ldns_rdf* rdf;
166 if (!rdf_data) {
167 return NULL;
168 }
169 ldns_write_uint16(rdf_data, size);
170 memcpy(rdf_data + 2, data, size);
171 rdf = ldns_rdf_new(LDNS_RDF_TYPE_INT16_DATA, size + 2, rdf_data);
172 if(!rdf)
173 LDNS_FREE(rdf_data);
174 return rdf;
175}
176
177/* note: data must be allocated memory */
178ldns_rdf *
179ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
180{
181 ldns_rdf *rd;
182 rd = LDNS_MALLOC(ldns_rdf);
183 if (!rd) {
184 return NULL;
185 }
186 ldns_rdf_set_size(rd, size);
187 ldns_rdf_set_type(rd, type);
188 ldns_rdf_set_data(rd, data);
189 return rd;
190}
191
192ldns_rdf *
193ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data)
194{
195 ldns_rdf *rdf;
196
197 /* if the size is too big, fail */
198 if (size > LDNS_MAX_RDFLEN) {
199 return NULL;
200 }
201
202 /* allocate space */
203 rdf = LDNS_MALLOC(ldns_rdf);
204 if (!rdf) {
205 return NULL;
206 }
207 rdf->_data = LDNS_XMALLOC(uint8_t, size);
208 if (!rdf->_data) {
209 LDNS_FREE(rdf);
210 return NULL;
211 }
212
213 /* set the values */
214 ldns_rdf_set_type(rdf, type);
215 ldns_rdf_set_size(rdf, size);
216 memcpy(rdf->_data, data, size);
217
218 return rdf;
219}
220
221ldns_rdf *
223{
224 assert(rd != NULL);
226 ldns_rdf_size(rd), ldns_rdf_data(rd)));
227}
228
229void
231{
232 if (rd) {
233 if (rd->_data) {
234 LDNS_FREE(rd->_data);
235 }
236 LDNS_FREE(rd);
237 }
238}
239
240void
242{
243 if (rd) {
244 LDNS_FREE(rd);
245 }
246}
247
248ldns_rdf *
250{
251 ldns_rdf *rdf = NULL;
252 ldns_status status;
253
254 switch (type) {
256 status = ldns_str2rdf_dname(&rdf, str);
257 break;
259 status = ldns_str2rdf_int8(&rdf, str);
260 break;
262 status = ldns_str2rdf_int16(&rdf, str);
263 break;
265 status = ldns_str2rdf_int32(&rdf, str);
266 break;
267 case LDNS_RDF_TYPE_A:
268 status = ldns_str2rdf_a(&rdf, str);
269 break;
271 status = ldns_str2rdf_aaaa(&rdf, str);
272 break;
274 status = ldns_str2rdf_str(&rdf, str);
275 break;
277 status = ldns_str2rdf_apl(&rdf, str);
278 break;
280 status = ldns_str2rdf_b64(&rdf, str);
281 break;
283 status = ldns_str2rdf_b32_ext(&rdf, str);
284 break;
286 status = ldns_str2rdf_hex(&rdf, str);
287 break;
289 status = ldns_str2rdf_nsec(&rdf, str);
290 break;
292 status = ldns_str2rdf_type(&rdf, str);
293 break;
295 status = ldns_str2rdf_class(&rdf, str);
296 break;
298 status = ldns_str2rdf_cert_alg(&rdf, str);
299 break;
301 status = ldns_str2rdf_alg(&rdf, str);
302 break;
304 status = ldns_str2rdf_unknown(&rdf, str);
305 break;
307 status = ldns_str2rdf_time(&rdf, str);
308 break;
310 status = ldns_str2rdf_period(&rdf, str);
311 break;
313 status = ldns_str2rdf_hip(&rdf, str);
314 break;
316 status = ldns_str2rdf_service(&rdf, str);
317 break;
319 status = ldns_str2rdf_loc(&rdf, str);
320 break;
322 status = ldns_str2rdf_wks(&rdf, str);
323 break;
325 status = ldns_str2rdf_nsap(&rdf, str);
326 break;
328 status = ldns_str2rdf_atma(&rdf, str);
329 break;
331 status = ldns_str2rdf_ipseckey(&rdf, str);
332 break;
334 status = ldns_str2rdf_nsec3_salt(&rdf, str);
335 break;
337 status = ldns_str2rdf_b32_ext(&rdf, str);
338 break;
340 status = ldns_str2rdf_ilnp64(&rdf, str);
341 break;
343 status = ldns_str2rdf_eui48(&rdf, str);
344 break;
346 status = ldns_str2rdf_eui64(&rdf, str);
347 break;
349 status = ldns_str2rdf_str(&rdf, str);
350 break;
352 status = ldns_str2rdf_tag(&rdf, str);
353 break;
355 status = ldns_str2rdf_long_str(&rdf, str);
356 break;
358 status = ldns_str2rdf_certificate_usage(&rdf, str);
359 break;
361 status = ldns_str2rdf_selector(&rdf, str);
362 break;
364 status = ldns_str2rdf_matching_type(&rdf, str);
365 break;
367 status = ldns_str2rdf_amtrelay(&rdf, str);
368 break;
370 status = ldns_str2rdf_svcparams(&rdf, str);
371 break;
373 status = ldns_str2rdf_ipn(&rdf, str);
374 break;
376 default:
377 /* default default ??? */
378 status = LDNS_STATUS_ERR;
379 break;
380 }
381 if (LDNS_STATUS_OK == status) {
382 ldns_rdf_set_type(rdf, type);
383 return rdf;
384 }
385 if (rdf) {
386 LDNS_FREE(rdf);
387 }
388 return NULL;
389}
390
393{
394 return ldns_rdf_new_frm_fp_l(rdf, type, fp, NULL);
395}
396
398ldns_rdf_new_frm_fp_l(ldns_rdf **rdf, ldns_rdf_type type, FILE *fp, int *line_nr)
399{
400 char *line;
401 ldns_rdf *r;
402 ssize_t t;
403
404 line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
405 if (!line) {
406 return LDNS_STATUS_MEM_ERR;
407 }
408
409 /* read an entire line in from the file */
410 if ((t = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, 0, line_nr)) == -1 || t == 0) {
411 LDNS_FREE(line);
413 }
414 r = ldns_rdf_new_frm_str(type, (const char*) line);
415 LDNS_FREE(line);
416 if (rdf) {
417 *rdf = r;
418 return LDNS_STATUS_OK;
419 } else {
420 return LDNS_STATUS_NULL;
421 }
422}
423
424ldns_rdf *
426{
427 uint8_t buf_4[LDNS_IP4ADDRLEN];
428 uint8_t buf_6[LDNS_IP6ADDRLEN * 2];
429 ldns_rdf *rev;
430 ldns_rdf *in_addr;
431 ldns_rdf *ret_dname;
432 uint8_t octet;
433 uint8_t nnibble;
434 uint8_t nibble;
435 uint8_t i, j;
436
437 char *char_dname;
438 int nbit;
439
442 return NULL;
443 }
444
445 in_addr = NULL;
446 ret_dname = NULL;
447
448 switch(ldns_rdf_get_type(rd)) {
449 case LDNS_RDF_TYPE_A:
450 /* the length of the buffer is 4 */
451 buf_4[3] = ldns_rdf_data(rd)[0];
452 buf_4[2] = ldns_rdf_data(rd)[1];
453 buf_4[1] = ldns_rdf_data(rd)[2];
454 buf_4[0] = ldns_rdf_data(rd)[3];
455 in_addr = ldns_dname_new_frm_str("in-addr.arpa.");
456 if (!in_addr) {
457 return NULL;
458 }
459 /* make a new rdf and convert that back */
461 LDNS_IP4ADDRLEN, (void*)&buf_4);
462 if (!rev) {
463 LDNS_FREE(in_addr);
464 return NULL;
465 }
466
467 /* convert rev to a string */
468 char_dname = ldns_rdf2str(rev);
469 if (!char_dname) {
470 LDNS_FREE(in_addr);
472 return NULL;
473 }
474 /* transform back to rdf with type dname */
475 ret_dname = ldns_dname_new_frm_str(char_dname);
476 if (!ret_dname) {
477 LDNS_FREE(in_addr);
479 LDNS_FREE(char_dname);
480 return NULL;
481 }
482 /* not needed anymore */
484 LDNS_FREE(char_dname);
485 break;
487 /* some foo magic to reverse the nibbles ... */
488
489 for (nbit = 127; nbit >= 0; nbit = nbit - 4) {
490 /* calculate octet (8 bit) */
491 octet = ( ((unsigned int) nbit) & 0x78) >> 3;
492 /* calculate nibble */
493 nnibble = ( ((unsigned int) nbit) & 0x04) >> 2;
494 /* extract nibble */
495 nibble = (ldns_rdf_data(rd)[octet] & ( 0xf << (4 * (1 -
496 nnibble)) ) ) >> ( 4 * (1 -
497 nnibble));
498
499 buf_6[(LDNS_IP6ADDRLEN * 2 - 1) -
500 (octet * 2 + nnibble)] =
501 (uint8_t)ldns_int_to_hexdigit((int)nibble);
502 }
503
504 char_dname = LDNS_XMALLOC(char, (LDNS_IP6ADDRLEN * 4));
505 if (!char_dname) {
506 return NULL;
507 }
508 char_dname[LDNS_IP6ADDRLEN * 4 - 1] = '\0'; /* closure */
509
510 /* walk the string and add . 's */
511 for (i = 0, j = 0; i < LDNS_IP6ADDRLEN * 2; i++, j = j + 2) {
512 char_dname[j] = (char)buf_6[i];
513 if (i != LDNS_IP6ADDRLEN * 2 - 1) {
514 char_dname[j + 1] = '.';
515 }
516 }
517 in_addr = ldns_dname_new_frm_str("ip6.arpa.");
518 if (!in_addr) {
519 LDNS_FREE(char_dname);
520 return NULL;
521 }
522
523 /* convert rev to a string */
524 ret_dname = ldns_dname_new_frm_str(char_dname);
525 LDNS_FREE(char_dname);
526 if (!ret_dname) {
527 ldns_rdf_deep_free(in_addr);
528 return NULL;
529 }
530 break;
531 default:
532 break;
533 }
534 /* add the suffix */
535 rev = ldns_dname_cat_clone(ret_dname, in_addr);
536
537 ldns_rdf_deep_free(ret_dname);
538 ldns_rdf_deep_free(in_addr);
539 return rev;
540}
541
544 uint8_t *hit_size, uint8_t** hit,
545 uint16_t *pk_size, uint8_t** pk)
546{
547 uint8_t *data;
548 size_t rdf_size;
549
550 if (! rdf || ! alg || ! hit || ! hit_size || ! pk || ! pk_size) {
552 } else if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_HIP) {
554 } else if ((rdf_size = ldns_rdf_size(rdf)) < 6) {
556 }
557 data = ldns_rdf_data(rdf);
558 *hit_size = data[0];
559 *alg = data[1];
560 *pk_size = ldns_read_uint16(data + 2);
561 *hit = data + 4;
562 *pk = data + 4 + *hit_size;
563 if (*hit_size == 0 || *pk_size == 0 ||
564 rdf_size < (size_t) *hit_size + *pk_size + 4) {
566 }
567 return LDNS_STATUS_OK;
568}
569
572 uint8_t hit_size, uint8_t *hit,
573 uint16_t pk_size, uint8_t *pk)
574{
575 uint8_t *data;
576
577 if (! rdf) {
579 }
580 if (4 + hit_size + pk_size > LDNS_MAX_RDFLEN) {
582 }
583 data = LDNS_XMALLOC(uint8_t, 4 + hit_size + pk_size);
584 if (data == NULL) {
585 return LDNS_STATUS_MEM_ERR;
586 }
587 data[0] = hit_size;
588 data[1] = alg;
589 ldns_write_uint16(data + 2, pk_size);
590 memcpy(data + 4, hit, hit_size);
591 memcpy(data + 4 + hit_size, pk, pk_size);
592 *rdf = ldns_rdf_new(LDNS_RDF_TYPE_HIP, 4 + hit_size + pk_size, data);
593 if (! *rdf) {
594 LDNS_FREE(data);
595 return LDNS_STATUS_MEM_ERR;
596 }
597 return LDNS_STATUS_OK;
598}
599
601ldns_octet(char *word, size_t *length)
602{
603 char *s;
604 char *p;
605 *length = 0;
606
607 for (s = p = word; *s != '\0'; s++,p++) {
608 switch (*s) {
609 case '.':
610 if (s[1] == '.') {
612 }
613 *p = *s;
614 (*length)++;
615 break;
616 case '\\':
617 if ('0' <= s[1] && s[1] <= '9' &&
618 '0' <= s[2] && s[2] <= '9' &&
619 '0' <= s[3] && s[3] <= '9') {
620 /* \DDD seen */
621 int val = ((s[1] - '0') * 100 +
622 (s[2] - '0') * 10 + (s[3] - '0'));
623
624 if (0 <= val && val <= 255) {
625 /* this also handles \0 */
626 s += 3;
627 *p = val;
628 (*length)++;
629 } else {
631 }
632 } else {
633 /* an escaped character, like <space> ?
634 * remove the '\' keep the rest */
635 *p = *++s;
636 (*length)++;
637 }
638 break;
639 case '\"':
640 /* non quoted " Is either first or the last character in
641 * the string */
642
643 *p = *++s; /* skip it */
644 (*length)++;
645 /* I'm not sure if this is needed in libdns... MG */
646 if ( *s == '\0' ) {
647 /* ok, it was the last one */
648 *p = '\0';
649 return LDNS_STATUS_OK;
650 }
651 break;
652 default:
653 *p = *s;
654 (*length)++;
655 break;
656 }
657 }
658 *p = '\0';
659 return LDNS_STATUS_OK;
660}
661
662int
663ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2)
664{
665 uint16_t i1, i2, i;
666 uint8_t *d1, *d2;
667
668 /* only when both are not NULL we can say anything about them */
669 if (!rd1 && !rd2) {
670 return 0;
671 }
672 if (!rd1 || !rd2) {
673 return -1;
674 }
675 i1 = ldns_rdf_size(rd1);
676 i2 = ldns_rdf_size(rd2);
677
678 if (i1 < i2) {
679 return -1;
680 } else if (i1 > i2) {
681 return +1;
682 } else {
683 d1 = (uint8_t*)ldns_rdf_data(rd1);
684 d2 = (uint8_t*)ldns_rdf_data(rd2);
685 for(i = 0; i < i1; i++) {
686 if (d1[i] < d2[i]) {
687 return -1;
688 } else if (d1[i] > d2[i]) {
689 return +1;
690 }
691 }
692 }
693 return 0;
694}
695
696uint32_t
697ldns_str2period(const char *nptr, const char **endptr)
698{
699 int sign = 0;
700 uint32_t i = 0;
701 uint32_t seconds = 0;
702
703 for(*endptr = nptr; **endptr; (*endptr)++) {
704 switch (**endptr) {
705 case ' ':
706 case '\t':
707 break;
708 case '-':
709 if(sign == 0) {
710 sign = -1;
711 } else {
712 return seconds;
713 }
714 break;
715 case '+':
716 if(sign == 0) {
717 sign = 1;
718 } else {
719 return seconds;
720 }
721 break;
722 case 's':
723 case 'S':
724 seconds += i;
725 i = 0;
726 break;
727 case 'm':
728 case 'M':
729 seconds += i * 60;
730 i = 0;
731 break;
732 case 'h':
733 case 'H':
734 seconds += i * 60 * 60;
735 i = 0;
736 break;
737 case 'd':
738 case 'D':
739 seconds += i * 60 * 60 * 24;
740 i = 0;
741 break;
742 case 'w':
743 case 'W':
744 seconds += i * 60 * 60 * 24 * 7;
745 i = 0;
746 break;
747 case '0':
748 case '1':
749 case '2':
750 case '3':
751 case '4':
752 case '5':
753 case '6':
754 case '7':
755 case '8':
756 case '9':
757 i *= 10;
758 i += (**endptr - '0');
759 break;
760 default:
761 seconds += i;
762 /* disregard signedness */
763 return seconds;
764 }
765 }
766 seconds += i;
767 /* disregard signedness */
768 return seconds;
769}
ldns_rdf * ldns_dname_cat_clone(const ldns_rdf *rd1, const ldns_rdf *rd2)
concatenates two dnames together
Definition dname.c:52
ldns_rdf * ldns_dname_new_frm_str(const char *str)
creates a new dname rdf from a string.
Definition dname.c:268
@ LDNS_STATUS_WIRE_RDATA_ERR
Definition error.h:125
@ LDNS_STATUS_NULL
Definition error.h:51
@ LDNS_STATUS_ERR
Definition error.h:37
@ LDNS_STATUS_MEM_ERR
Definition error.h:34
@ LDNS_STATUS_SYNTAX_RDATA_ERR
Definition error.h:83
@ LDNS_STATUS_INVALID_POINTER
Definition error.h:33
@ LDNS_STATUS_DDD_OVERFLOW
Definition error.h:31
@ LDNS_STATUS_INVALID_RDF_TYPE
Definition error.h:128
@ LDNS_STATUS_OK
Definition error.h:26
@ LDNS_STATUS_EMPTY_LABEL
Definition error.h:27
@ LDNS_STATUS_RDATA_OVERFLOW
Definition error.h:129
enum ldns_enum_status ldns_status
Definition error.h:149
char * ldns_rdf2str(const ldns_rdf *rdf)
Converts the data in the rdata field to presentation format and returns that as a char *.
Definition host2str.c:3336
Including this file will include all ldns files, and define some lookup tables.
#define LDNS_IP4ADDRLEN
Definition ldns.h:132
#define LDNS_IP6ADDRLEN
Definition ldns.h:133
ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
returns a token/char from the stream F.
Definition parse.c:247
#define LDNS_PARSE_SKIP_SPACE
Definition parse.h:20
#define LDNS_MAX_LINELEN
Definition parse.h:23
uint32_t ldns_str2period(const char *nptr, const char **endptr)
converts a ttl value (like 5d2h) to a long.
Definition rdata.c:697
ldns_status ldns_rdf_hip_new_frm_alg_hit_pk(ldns_rdf **rdf, uint8_t alg, uint8_t hit_size, uint8_t *hit, uint16_t pk_size, uint8_t *pk)
Creates a new LDNS_RDF_TYPE_HIP rdf from given data.
Definition rdata.c:571
ldns_rdf * ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str)
creates a new rdf from a string.
Definition rdata.c:249
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition rdata.c:38
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition rdata.c:222
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
Definition rdata.c:31
void ldns_rdf_set_type(ldns_rdf *rd, ldns_rdf_type type)
sets the size of the rdf.
Definition rdata.c:53
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
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition rdata.c:230
uint32_t ldns_rdf2native_int32(const ldns_rdf *rd)
returns the native uint32_t representation from the rdf.
Definition rdata.c:98
uint16_t ldns_rdf2native_int16(const ldns_rdf *rd)
returns the native uint16_t representation from the rdf.
Definition rdata.c:84
ldns_rdf * ldns_native2rdf_int16(ldns_rdf_type type, uint16_t value)
returns the rdf containing the native uint16_t representation.
Definition rdata.c:132
ldns_status ldns_octet(char *word, size_t *length)
removes \DDD, \[space] and other escapes from the input.
Definition rdata.c:601
ldns_rdf * ldns_native2rdf_int16_data(size_t size, uint8_t *data)
returns an int16_data rdf that contains the data in the given array, preceded by an int16 specifying ...
Definition rdata.c:162
ldns_status ldns_rdf_new_frm_fp(ldns_rdf **rdf, ldns_rdf_type type, FILE *fp)
creates a new rdf from a file containing a string.
Definition rdata.c:392
ldns_rdf * ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value)
returns the rdf containing the native uint8_t repr.
Definition rdata.c:126
uint8_t ldns_rdf2native_int8(const ldns_rdf *rd)
returns the native uint8_t representation from the rdf.
Definition rdata.c:70
ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
returns an rdf that contains the given int32 value.
Definition rdata.c:147
ldns_status ldns_rdf_hip_get_alg_hit_pk(ldns_rdf *rdf, uint8_t *alg, uint8_t *hit_size, uint8_t **hit, uint16_t *pk_size, uint8_t **pk)
Gets the algorithm value, the HIT and Public Key data from the rdf with type LDNS_RDF_TYPE_HIP.
Definition rdata.c:543
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition rdata.c:24
time_t ldns_rdf2native_time_t(const ldns_rdf *rd)
returns the native time_t representation from the rdf.
Definition rdata.c:112
void ldns_rdf_set_data(ldns_rdf *rd, void *data)
sets the size of the rdf.
Definition rdata.c:60
void ldns_rdf_set_size(ldns_rdf *rd, size_t size)
sets the size of the rdf.
Definition rdata.c:46
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
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
Definition rdata.c:241
int ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2)
compares two rdf's on their wire formats.
Definition rdata.c:663
ldns_rdf * ldns_rdf_address_reverse(const ldns_rdf *rd)
reverses an rdf, only actually useful for AAAA and A records.
Definition rdata.c:425
ldns_status ldns_rdf_new_frm_fp_l(ldns_rdf **rdf, ldns_rdf_type type, FILE *fp, int *line_nr)
creates a new rdf from a file containing a string.
Definition rdata.c:398
#define LDNS_RDF_SIZE_WORD
Definition rdata.h:34
#define LDNS_MAX_RDFLEN
Definition rdata.h:31
#define LDNS_RDF_SIZE_BYTE
Definition rdata.h:33
@ LDNS_RDF_TYPE_INT32
32 bits
Definition rdata.h:56
@ LDNS_RDF_TYPE_TAG
A non-zero sequence of US-ASCII letters and numbers in lower case.
Definition rdata.h:132
@ LDNS_RDF_TYPE_NSAP
NSAP.
Definition rdata.h:106
@ LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition rdata.h:95
@ LDNS_RDF_TYPE_IPN
draft-johnson-dns-ipn-cla-07
Definition rdata.h:155
@ LDNS_RDF_TYPE_B32_EXT
b32 string
Definition rdata.h:68
@ LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
Definition rdata.h:114
@ LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
Definition rdata.h:81
@ LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
Definition rdata.h:122
@ LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
Definition rdata.h:100
@ LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
Definition rdata.h:124
@ LDNS_RDF_TYPE_PERIOD
period
Definition rdata.h:89
@ LDNS_RDF_TYPE_B64
b64 string
Definition rdata.h:70
@ LDNS_RDF_TYPE_AAAA
AAAA record.
Definition rdata.h:62
@ LDNS_RDF_TYPE_UNKNOWN
unknown types
Definition rdata.h:85
@ LDNS_RDF_TYPE_WKS
well known services
Definition rdata.h:104
@ LDNS_RDF_TYPE_DNAME
domain name
Definition rdata.h:50
@ LDNS_RDF_TYPE_TIME
time (32 bits)
Definition rdata.h:87
@ LDNS_RDF_TYPE_SVCPARAMS
draft-ietf-dnsop-svcb-https
Definition rdata.h:152
@ LDNS_RDF_TYPE_NSEC
nsec type codes
Definition rdata.h:74
@ LDNS_RDF_TYPE_SELECTOR
Definition rdata.h:145
@ LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
Definition rdata.h:112
@ LDNS_RDF_TYPE_APL
apl data
Definition rdata.h:66
@ LDNS_RDF_TYPE_A
A record.
Definition rdata.h:60
@ LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5....
Definition rdata.h:138
@ LDNS_RDF_TYPE_LOC
location data
Definition rdata.h:102
@ LDNS_RDF_TYPE_INT16_DATA
variable length any type rdata where the length is specified by the first 2 bytes
Definition rdata.h:98
@ LDNS_RDF_TYPE_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition rdata.h:119
@ LDNS_RDF_TYPE_ATMA
ATMA.
Definition rdata.h:108
@ LDNS_RDF_TYPE_HEX
hex string
Definition rdata.h:72
@ LDNS_RDF_TYPE_NONE
none
Definition rdata.h:48
@ LDNS_RDF_TYPE_CLASS
a class
Definition rdata.h:79
@ LDNS_RDF_TYPE_INT8
8 bits
Definition rdata.h:52
@ LDNS_RDF_TYPE_MATCHING_TYPE
Definition rdata.h:146
@ LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
Definition rdata.h:110
@ LDNS_RDF_TYPE_CERTIFICATE_USAGE
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
Definition rdata.h:144
@ LDNS_RDF_TYPE_STR
txt string
Definition rdata.h:64
@ LDNS_RDF_TYPE_INT16
16 bits
Definition rdata.h:54
@ LDNS_RDF_TYPE_ALG
a key algorithm
Definition rdata.h:83
@ LDNS_RDF_TYPE_AMTRELAY
draft-ietf-mboned-driad-amt-discovery
Definition rdata.h:149
@ LDNS_RDF_TYPE_UNQUOTED
Character string without quotes.
Definition rdata.h:127
@ LDNS_RDF_TYPE_TYPE
a RR type
Definition rdata.h:77
#define LDNS_RDF_SIZE_DOUBLEWORD
Definition rdata.h:35
enum ldns_enum_rdf_type ldns_rdf_type
Definition rdata.h:157
ldns_status ldns_str2rdf_hex(ldns_rdf **rd, const char *str)
convert a hex value into wireformat
Definition str2host.c:707
ldns_status ldns_str2rdf_amtrelay(ldns_rdf **rd, const char *str)
Convert a "<precedence> <D-bit> <type> <relay>" encoding of the value field as specified in Section 4...
Definition str2host.c:1735
ldns_status ldns_str2rdf_int8(ldns_rdf **rd, const char *bytestr)
convert a byte into wireformat
Definition str2host.c:291
ldns_status ldns_str2rdf_certificate_usage(ldns_rdf **rd, const char *str)
convert a tlsa certificate usage value into wireformat
Definition str2host.c:902
ldns_status ldns_str2rdf_hip(ldns_rdf **rd, const char *str)
Convert a "<algorithm> <hit> <pk>" encoding of the value field as specified in Section 6.
Definition str2host.c:1639
ldns_status ldns_str2rdf_service(ldns_rdf **rd, const char *str)
convert string with a protocol service into wireformat
ldns_status ldns_str2rdf_atma(ldns_rdf **rd, const char *str)
convert a str with a ATMA RR into wireformat
Definition str2host.c:1318
ldns_status ldns_str2rdf_type(ldns_rdf **rd, const char *str)
convert a rrtype into wireformat
Definition str2host.c:801
ldns_status ldns_str2rdf_ipn(ldns_rdf **rd, const char *str)
Convert either two unsigned 32 bit decimal numbers seperated by a '.
Definition str2host.c:241
ldns_status ldns_str2rdf_nsec3_salt(ldns_rdf **rd, const char *nsec3_salt)
Definition str2host.c:126
ldns_status ldns_str2rdf_svcparams(ldns_rdf **rd, const char *str)
Convert a series of "key[=<value>]" encodings to wireformat as described in [draft-ietf-dnsop-svcb-ht...
Definition str2host.c:2395
ldns_status ldns_str2rdf_period(ldns_rdf **rd, const char *str)
Definition str2host.c:178
ldns_status ldns_str2rdf_aaaa(ldns_rdf **rd, const char *str)
convert the str with an AAAA record into wireformat
Definition str2host.c:477
ldns_status ldns_str2rdf_b32_ext(ldns_rdf **rd, const char *str)
convert the string with the b32 ext hex data into wireformat
Definition str2host.c:676
ldns_status ldns_str2rdf_long_str(ldns_rdf **rd, const char *str)
Convert a <character-string> encoding of the value field as specified [RFC1035], Section 5....
Definition str2host.c:1592
ldns_status ldns_str2rdf_class(ldns_rdf **rd, const char *str)
convert string with a classname into wireformat
Definition str2host.c:812
ldns_status ldns_str2rdf_alg(ldns_rdf **rd, const char *str)
convert an algorithm value into wireformat
Definition str2host.c:896
ldns_status ldns_str2rdf_nsec(ldns_rdf **rd, const char *str)
convert string with nsec into wireformat
Definition str2host.c:753
ldns_status ldns_str2rdf_a(ldns_rdf **rd, const char *str)
convert str with an A record into wireformat
Definition str2host.c:464
ldns_status ldns_str2rdf_matching_type(ldns_rdf **rd, const char *str)
convert a tlsa matching type value into wireformat
Definition str2host.c:915
ldns_status ldns_str2rdf_wks(ldns_rdf **rd, const char *str)
convert string with a WKS RR into wireformat
Definition str2host.c:1154
ldns_status ldns_str2rdf_ilnp64(ldns_rdf **rd, const char *str)
convert 4 * 16bit hex separated by colons into wireformat
Definition str2host.c:1492
ldns_status ldns_str2rdf_time(ldns_rdf **rd, const char *time)
convert a time string to a time value in wireformat
Definition str2host.c:57
ldns_status ldns_str2rdf_nsap(ldns_rdf **rd, const char *str)
convert a str with a NSAP RR into wireformat
Definition str2host.c:1299
ldns_status ldns_str2rdf_eui64(ldns_rdf **rd, const char *str)
convert 8 hex bytes separated by dashes into wireformat
Definition str2host.c:1538
ldns_status ldns_str2rdf_loc(ldns_rdf **rd, const char *str)
convert a string with a LOC RR into wireformat
Definition str2host.c:979
ldns_status ldns_str2rdf_str(ldns_rdf **rd, const char *str)
convert a string into wireformat (think txt record)
Definition str2host.c:491
ldns_status ldns_str2rdf_ipseckey(ldns_rdf **rd, const char *str)
convert a str with a IPSECKEY RR into wireformat
Definition str2host.c:1338
ldns_status ldns_str2rdf_selector(ldns_rdf **rd, const char *str)
convert a tlsa selector value into wireformat
Definition str2host.c:909
ldns_status ldns_str2rdf_tag(ldns_rdf **rd, const char *str)
Convert a non-zero sequence of US-ASCII letters and numbers into wireformat.
Definition str2host.c:1563
ldns_status ldns_str2rdf_apl(ldns_rdf **rd, const char *str)
convert str with the apl record into wireformat
Definition str2host.c:535
ldns_status ldns_str2rdf_b64(ldns_rdf **rd, const char *str)
convert the string with the b64 data into wireformat
Definition str2host.c:646
ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str)
convert a dname string into wireformat
Definition str2host.c:374
ldns_status ldns_str2rdf_eui48(ldns_rdf **rd, const char *str)
convert 6 hex bytes separated by dashes into wireformat
Definition str2host.c:1515
ldns_status ldns_str2rdf_int32(ldns_rdf **rd, const char *longstr)
convert a strings into a 4 byte int in wireformat
Definition str2host.c:197
ldns_status ldns_str2rdf_int16(ldns_rdf **rd, const char *shortstr)
convert a string to a int16 in wireformat
Definition str2host.c:36
ldns_status ldns_str2rdf_cert_alg(ldns_rdf **rd, const char *str)
convert an certificate algorithm value into wireformat
Definition str2host.c:826
ldns_status ldns_str2rdf_unknown(ldns_rdf **rd, const char *str)
convert a string with a unknown RR into wireformat
Resource record data field.
Definition rdata.h:203
ldns_rdf_type _type
The type of the data.
Definition rdata.h:207
size_t _size
The size of the data (in octets)
Definition rdata.h:205
void * _data
Pointer to the data (raw octets)
Definition rdata.h:209
#define LDNS_FREE(ptr)
Definition util.h:60
#define LDNS_MALLOC(type)
Memory management macros.
Definition util.h:49
#define LDNS_XMALLOC(type, count)
Definition util.h:51
char ldns_int_to_hexdigit(int ch)
Returns the char (hex) representation of the given int.
Definition util.c:113