host2str.c
Go to the documentation of this file.
1 /*
2  * host2str.c
3  *
4  * conversion routines from the host format
5  * to the presentation format (strings)
6  *
7  * a Net::DNS like library for C
8  *
9  * (c) NLnet Labs, 2004-2006
10  *
11  * See the file LICENSE for the license
12  */
13 #include <ldns/config.h>
14 
15 #include <ldns/ldns.h>
16 
17 #include <limits.h>
18 
19 #ifdef HAVE_SYS_SOCKET_H
20 #include <sys/socket.h>
21 #endif
22 #ifdef HAVE_ARPA_INET_H
23 #include <arpa/inet.h>
24 #endif
25 #ifdef HAVE_NETDB_H
26 #include <netdb.h>
27 #endif
28 #include <time.h>
29 #include <sys/time.h>
30 
31 #ifdef HAVE_SSL
32 #include <openssl/bn.h>
33 #include <openssl/rsa.h>
34 #ifdef USE_DSA
35 #include <openssl/dsa.h>
36 #endif
37 #endif
38 
39 #ifndef INET_ADDRSTRLEN
40 #define INET_ADDRSTRLEN 16
41 #endif
42 #ifndef INET6_ADDRSTRLEN
43 #define INET6_ADDRSTRLEN 46
44 #endif
45 
46 /* Internal helper function */
49 
50 /* lookup tables for standard DNS stuff */
51 
52 /* Taken from RFC 2535, section 7. */
54  { LDNS_RSAMD5, "RSAMD5" },
55  { LDNS_DH, "DH" },
56  { LDNS_DSA, "DSA" },
57  { LDNS_ECC, "ECC" },
58  { LDNS_RSASHA1, "RSASHA1" },
59  { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
60  { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
61  { LDNS_RSASHA256, "RSASHA256"},
62  { LDNS_RSASHA512, "RSASHA512"},
63  { LDNS_ECC_GOST, "ECC-GOST"},
64  { LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
65  { LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
66  { LDNS_ED25519, "ED25519"},
67  { LDNS_ED448, "ED448"},
68  { LDNS_INDIRECT, "INDIRECT" },
69  { LDNS_PRIVATEDNS, "PRIVATEDNS" },
70  { LDNS_PRIVATEOID, "PRIVATEOID" },
71  { 0, NULL }
72 };
73 
74 /* Hashing algorithms used in the DS record */
76  {LDNS_SHA1 , "SHA1" }, /* RFC 4034 */
77  {LDNS_SHA256 , "SHA256" }, /* RFC 4509 */
78  {LDNS_HASH_GOST, "HASH-GOST" }, /* RFC 5933 */
79  {LDNS_SHA384 , "SHA384" }, /* RFC 6605 */
80  { 0, NULL }
81 };
82 
83 /* Taken from RFC 4398 */
85  { LDNS_CERT_PKIX, "PKIX" },
86  { LDNS_CERT_SPKI, "SPKI" },
87  { LDNS_CERT_PGP, "PGP" },
88  { LDNS_CERT_IPKIX, "IPKIX" },
89  { LDNS_CERT_ISPKI, "ISPKI" },
90  { LDNS_CERT_IPGP, "IPGP" },
91  { LDNS_CERT_ACPKIX, "ACPKIX" },
92  { LDNS_CERT_IACPKIX, "IACPKIX" },
93  { LDNS_CERT_URI, "URI" },
94  { LDNS_CERT_OID, "OID" },
95  { 0, NULL }
96 };
97 
98 /* classes */
100  { LDNS_RR_CLASS_IN, "IN" },
101  { LDNS_RR_CLASS_CH, "CH" },
102  { LDNS_RR_CLASS_HS, "HS" },
103  { LDNS_RR_CLASS_NONE, "NONE" },
104  { LDNS_RR_CLASS_ANY, "ANY" },
105  { 0, NULL }
106 };
107 
108 /* if these are used elsewhere */
110  { LDNS_RCODE_NOERROR, "NOERROR" },
111  { LDNS_RCODE_FORMERR, "FORMERR" },
112  { LDNS_RCODE_SERVFAIL, "SERVFAIL" },
113  { LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
114  { LDNS_RCODE_NOTIMPL, "NOTIMPL" },
115  { LDNS_RCODE_REFUSED, "REFUSED" },
116  { LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
117  { LDNS_RCODE_YXRRSET, "YXRRSET" },
118  { LDNS_RCODE_NXRRSET, "NXRRSET" },
119  { LDNS_RCODE_NOTAUTH, "NOTAUTH" },
120  { LDNS_RCODE_NOTZONE, "NOTZONE" },
121  { 0, NULL }
122 };
123 
125  { LDNS_PACKET_QUERY, "QUERY" },
126  { LDNS_PACKET_IQUERY, "IQUERY" },
127  { LDNS_PACKET_STATUS, "STATUS" },
128  { LDNS_PACKET_NOTIFY, "NOTIFY" },
129  { LDNS_PACKET_UPDATE, "UPDATE" },
130  { 0, NULL }
131 };
132 
137  LDNS_COMMENT_KEY, NULL
138 };
143 
146 };
149 
150 static bool
151 ldns_output_format_covers_type(const ldns_output_format* fmt, ldns_rr_type t)
152 {
153  return fmt && (fmt->flags & LDNS_FMT_RFC3597) &&
154  ((ldns_output_format_storage*)fmt)->bitmap &&
156  ((ldns_output_format_storage*)fmt)->bitmap, t);
157 }
158 
161 {
163  ldns_status s;
164 
165  assert(fmt != NULL);
166 
167  if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
168  ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
169  }
170  if (! fmt_st->bitmap) {
172  if (s != LDNS_STATUS_OK) {
173  return s;
174  }
175  }
176  return ldns_nsec_bitmap_set_type(fmt_st->bitmap, t);
177 }
178 
181 {
183  ldns_status s;
184 
185  assert(fmt != NULL);
186 
187  if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
188  ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
189  }
190  if (! fmt_st->bitmap) {
192  if (s != LDNS_STATUS_OK) {
193  return s;
194  }
195  }
196  return ldns_nsec_bitmap_clear_type(fmt_st->bitmap, t);
197 }
198 
201 {
203  if (lt && lt->name) {
204  ldns_buffer_printf(output, "%s", lt->name);
205  } else {
206  ldns_buffer_printf(output, "OPCODE%u", opcode);
207  }
208  return ldns_buffer_status(output);
209 }
210 
213 {
215  if (lt && lt->name) {
216  ldns_buffer_printf(output, "%s", lt->name);
217  } else {
218  ldns_buffer_printf(output, "RCODE%u", rcode);
219  }
220  return ldns_buffer_status(output);
221 }
222 
225  ldns_algorithm algorithm)
226 {
228  algorithm);
229  if (lt && lt->name) {
230  ldns_buffer_printf(output, "%s", lt->name);
231  } else {
232  ldns_buffer_printf(output, "ALG%u", algorithm);
233  }
234  return ldns_buffer_status(output);
235 }
236 
239  ldns_cert_algorithm cert_algorithm)
240 {
242  cert_algorithm);
243  if (lt && lt->name) {
244  ldns_buffer_printf(output, "%s", lt->name);
245  } else {
246  ldns_buffer_printf(output, "CERT_ALG%u",
247  cert_algorithm);
248  }
249  return ldns_buffer_status(output);
250 }
251 
252 char *
254 {
255  char *str;
256  ldns_buffer *buf;
257 
258  buf = ldns_buffer_new(12);
259  if (!buf) {
260  return NULL;
261  }
262 
263  str = NULL;
264  if (ldns_pkt_opcode2buffer_str(buf, opcode) == LDNS_STATUS_OK) {
265  str = ldns_buffer_export2str(buf);
266  }
267 
268  ldns_buffer_free(buf);
269  return str;
270 }
271 
272 char *
274 {
275  char *str;
276  ldns_buffer *buf;
277 
278  buf = ldns_buffer_new(10);
279  if (!buf) {
280  return NULL;
281  }
282 
283  str = NULL;
284  if (ldns_pkt_rcode2buffer_str(buf, rcode) == LDNS_STATUS_OK) {
285  str = ldns_buffer_export2str(buf);
286  }
287 
288  ldns_buffer_free(buf);
289  return str;
290 }
291 
292 char *
294 {
295  char *str;
296  ldns_buffer *buf;
297 
298  buf = ldns_buffer_new(10);
299  if (!buf) {
300  return NULL;
301  }
302 
303  str = NULL;
304  if (ldns_algorithm2buffer_str(buf, algorithm)
305  == LDNS_STATUS_OK) {
306  str = ldns_buffer_export2str(buf);
307  }
308 
309  ldns_buffer_free(buf);
310  return str;
311 }
312 
313 char *
315 {
316  char *str;
317  ldns_buffer *buf;
318 
319  buf = ldns_buffer_new(10);
320  if (!buf) {
321  return NULL;
322  }
323 
324  str = NULL;
325  if (ldns_cert_algorithm2buffer_str(buf, cert_algorithm)
326  == LDNS_STATUS_OK) {
327  str = ldns_buffer_export2str(buf);
328  }
329 
330  ldns_buffer_free(buf);
331  return str;
332 }
333 
334 
335 /* do NOT pass compressed data here :p */
338 {
339  /* can we do with 1 pos var? or without at all? */
340  uint8_t src_pos = 0;
341  uint8_t len;
342  uint8_t *data;
343  uint8_t i;
344  unsigned char c;
345 
346  data = (uint8_t*)ldns_rdf_data(dname);
347  len = data[src_pos];
348 
349  if (ldns_rdf_size(dname) > LDNS_MAX_DOMAINLEN) {
350  /* too large, return */
352  }
353 
354  /* special case: root label */
355  if (1 == ldns_rdf_size(dname)) {
356  ldns_buffer_printf(output, ".");
357  } else {
358  while ((len > 0) && src_pos < ldns_rdf_size(dname)) {
359  src_pos++;
360  for(i = 0; i < len; i++) {
361  /* paranoia check for various 'strange'
362  characters in dnames
363  */
364  c = (unsigned char) data[src_pos];
365  if(c == '.' || c == ';' ||
366  c == '(' || c == ')' ||
367  c == '\\') {
368  ldns_buffer_printf(output, "\\%c",
369  data[src_pos]);
370  } else if (!(isascii(c) && isgraph(c))) {
371  ldns_buffer_printf(output, "\\%03u",
372  data[src_pos]);
373  } else {
374  ldns_buffer_printf(output, "%c", data[src_pos]);
375  }
376  src_pos++;
377  }
378 
379  if (src_pos < ldns_rdf_size(dname)) {
380  ldns_buffer_printf(output, ".");
381  }
382  len = data[src_pos];
383  }
384  }
385  return ldns_buffer_status(output);
386 }
387 
390 {
391  uint8_t data = ldns_rdf_data(rdf)[0];
392  ldns_buffer_printf(output, "%lu", (unsigned long) data);
393  return ldns_buffer_status(output);
394 }
395 
398 {
399  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
400  ldns_buffer_printf(output, "%lu", (unsigned long) data);
401  return ldns_buffer_status(output);
402 }
403 
406 {
407  uint32_t data = ldns_read_uint32(ldns_rdf_data(rdf));
408  ldns_buffer_printf(output, "%lu", (unsigned long) data);
409  return ldns_buffer_status(output);
410 }
411 
414 {
415  /* create a YYYYMMDDHHMMSS string if possible */
416  struct tm tm;
417  char date_buf[16];
418 
419  memset(&tm, 0, sizeof(tm));
421  && strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) {
422  ldns_buffer_printf(output, "%s", date_buf);
423  }
424  return ldns_buffer_status(output);
425 }
426 
429 {
430  char str[INET_ADDRSTRLEN];
431 
432  if (inet_ntop(AF_INET, ldns_rdf_data(rdf), str, INET_ADDRSTRLEN)) {
433  ldns_buffer_printf(output, "%s", str);
434  }
435  return ldns_buffer_status(output);
436 }
437 
440 {
441  char str[INET6_ADDRSTRLEN];
442 
443  if (inet_ntop(AF_INET6, ldns_rdf_data(rdf), str, INET6_ADDRSTRLEN)) {
444  ldns_buffer_printf(output, "%s", str);
445  }
446 
447  return ldns_buffer_status(output);
448 }
449 
450 static void
451 ldns_characters2buffer_str(ldns_buffer* output,
452  size_t amount, const uint8_t* characters)
453 {
454  uint8_t ch;
455  while (amount > 0) {
456  ch = *characters++;
457  if (isprint((int)ch) || ch == '\t') {
458  if (ch == '\"' || ch == '\\')
459  ldns_buffer_printf(output, "\\%c", ch);
460  else
461  ldns_buffer_printf(output, "%c", ch);
462  } else {
463  ldns_buffer_printf(output, "\\%03u",
464  (unsigned)(uint8_t) ch);
465  }
466  amount--;
467  }
468 }
469 
472 {
473  if(ldns_rdf_size(rdf) < 1) {
475  }
476  if((int)ldns_rdf_size(rdf) < (int)ldns_rdf_data(rdf)[0] + 1) {
478  }
479  ldns_buffer_printf(output, "\"");
480  ldns_characters2buffer_str(output,
481  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf) + 1);
482  ldns_buffer_printf(output, "\"");
483  return ldns_buffer_status(output);
484 }
485 
488 {
489  size_t size;
490  char *b64;
491 
492  if (ldns_rdf_size(rdf) == 0) {
493  ldns_buffer_printf(output, "0");
494  return ldns_buffer_status(output);
495  } else
496  size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf));
497 
498  if (!(b64 = LDNS_XMALLOC(char, size)))
499  return LDNS_STATUS_MEM_ERR;
500 
501  if (ldns_b64_ntop(ldns_rdf_data(rdf), ldns_rdf_size(rdf), b64, size)) {
502  ldns_buffer_printf(output, "%s", b64);
503  }
504  LDNS_FREE(b64);
505  return ldns_buffer_status(output);
506 }
507 
510 {
511  size_t size;
512  char *b32;
513  if(ldns_rdf_size(rdf) == 0)
514  return LDNS_STATUS_OK;
515  /* remove -1 for the b32-hash-len octet */
516  size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
517  /* add one for the end nul for the string */
518  b32 = LDNS_XMALLOC(char, size + 1);
519  if(!b32) return LDNS_STATUS_MEM_ERR;
520  size = (size_t) ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1,
521  ldns_rdf_size(rdf) - 1, b32, size+1);
522  if (size > 0) {
523  ldns_buffer_printf(output, "%s", b32);
524  }
525  LDNS_FREE(b32);
526  return ldns_buffer_status(output);
527 }
528 
531 {
532  size_t i;
533  for (i = 0; i < ldns_rdf_size(rdf); i++) {
534  ldns_buffer_printf(output, "%02x", ldns_rdf_data(rdf)[i]);
535  }
536 
537  return ldns_buffer_status(output);
538 }
539 
540 static ldns_status
541 ldns_rdf2buffer_str_type_fmt(ldns_buffer *output,
542  const ldns_output_format* fmt, const ldns_rdf *rdf)
543 {
544  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
545 
546  if (! ldns_output_format_covers_type(fmt, data) &&
547  ldns_rr_descript(data) &&
548  ldns_rr_descript(data)->_name) {
549 
550  ldns_buffer_printf(output, "%s",ldns_rr_descript(data)->_name);
551  } else {
552  ldns_buffer_printf(output, "TYPE%u", data);
553  }
554  return ldns_buffer_status(output);
555 }
556 
559 {
560  return ldns_rdf2buffer_str_type_fmt(output,
562 }
563 
566 {
567  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
568  ldns_lookup_table *lt;
569 
570  lt = ldns_lookup_by_id(ldns_rr_classes, (int) data);
571  if (lt) {
572  ldns_buffer_printf(output, "\t%s", lt->name);
573  } else {
574  ldns_buffer_printf(output, "\tCLASS%d", data);
575  }
576  return ldns_buffer_status(output);
577 }
578 
581 {
582  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
583  ldns_lookup_table *lt;
584  lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data);
585  if (lt) {
586  ldns_buffer_printf(output, "%s", lt->name);
587  } else {
588  ldns_buffer_printf(output, "%d", data);
589  }
590  return ldns_buffer_status(output);
591 }
592 
595 {
596  return ldns_rdf2buffer_str_int8(output, rdf);
597 }
598 
599 static void
600 loc_cm_print(ldns_buffer *output, uint8_t mantissa, uint8_t exponent)
601 {
602  uint8_t i;
603  /* is it 0.<two digits> ? */
604  if(exponent < 2) {
605  if(exponent == 1)
606  mantissa *= 10;
607  ldns_buffer_printf(output, "0.%02ld", (long)mantissa);
608  return;
609  }
610  /* always <digit><string of zeros> */
611  ldns_buffer_printf(output, "%d", (int)mantissa);
612  for(i=0; i<exponent-2; i++)
613  ldns_buffer_printf(output, "0");
614 }
615 
618 {
619  const ldns_rr_descriptor *descriptor;
620 
621  descriptor = ldns_rr_descript(type);
622 
623  switch (type) {
624  case LDNS_RR_TYPE_IXFR:
625  ldns_buffer_printf(output, "IXFR");
626  break;
627  case LDNS_RR_TYPE_AXFR:
628  ldns_buffer_printf(output, "AXFR");
629  break;
630  case LDNS_RR_TYPE_MAILA:
631  ldns_buffer_printf(output, "MAILA");
632  break;
633  case LDNS_RR_TYPE_MAILB:
634  ldns_buffer_printf(output, "MAILB");
635  break;
636  case LDNS_RR_TYPE_ANY:
637  ldns_buffer_printf(output, "ANY");
638  break;
639  default:
640  if (descriptor && descriptor->_name) {
641  ldns_buffer_printf(output, "%s", descriptor->_name);
642  } else {
643  ldns_buffer_printf(output, "TYPE%u", type);
644  }
645  }
646  return ldns_buffer_status(output);
647 }
648 
649 char *
651 {
652  char *str;
653  ldns_buffer *buf;
654 
655  buf = ldns_buffer_new(10);
656  if (!buf) {
657  return NULL;
658  }
659 
660  str = NULL;
661  if (ldns_rr_type2buffer_str(buf, type) == LDNS_STATUS_OK) {
662  str = ldns_buffer_export2str(buf);
663  }
664 
665  ldns_buffer_free(buf);
666  return str;
667 }
668 
669 
672  const ldns_rr_class klass)
673 {
674  ldns_lookup_table *lt;
675 
676  lt = ldns_lookup_by_id(ldns_rr_classes, klass);
677  if (lt) {
678  ldns_buffer_printf(output, "%s", lt->name);
679  } else {
680  ldns_buffer_printf(output, "CLASS%d", klass);
681  }
682  return ldns_buffer_status(output);
683 }
684 
685 char *
687 {
688  ldns_buffer *buf;
689  char *str;
690 
691  buf = ldns_buffer_new(10);
692  if (!buf) {
693  return NULL;
694  }
695 
696  str = NULL;
697  if (ldns_rr_class2buffer_str(buf, klass) == LDNS_STATUS_OK) {
698  str = ldns_buffer_export2str(buf);
699  }
700  ldns_buffer_free(buf);
701  return str;
702 }
703 
706 {
707  /* we could do checking (ie degrees < 90 etc)? */
708  uint8_t version;
709  uint8_t size;
710  uint8_t horizontal_precision;
711  uint8_t vertical_precision;
712  uint32_t longitude;
713  uint32_t latitude;
714  uint32_t altitude;
715  char latitude_hemisphere;
716  char longitude_hemisphere;
717  uint32_t h;
718  uint32_t m;
719  double s;
720 
721  uint32_t equator = (uint32_t) ldns_power(2, 31);
722 
723  if(ldns_rdf_size(rdf) < 1) {
725  }
726  version = ldns_rdf_data(rdf)[0];
727  if (version == 0) {
728  if(ldns_rdf_size(rdf) < 16) {
730  }
731  size = ldns_rdf_data(rdf)[1];
732  horizontal_precision = ldns_rdf_data(rdf)[2];
733  vertical_precision = ldns_rdf_data(rdf)[3];
734 
735  latitude = ldns_read_uint32(&ldns_rdf_data(rdf)[4]);
736  longitude = ldns_read_uint32(&ldns_rdf_data(rdf)[8]);
737  altitude = ldns_read_uint32(&ldns_rdf_data(rdf)[12]);
738 
739  if (latitude > equator) {
740  latitude_hemisphere = 'N';
741  latitude = latitude - equator;
742  } else {
743  latitude_hemisphere = 'S';
744  latitude = equator - latitude;
745  }
746  h = latitude / (1000 * 60 * 60);
747  latitude = latitude % (1000 * 60 * 60);
748  m = latitude / (1000 * 60);
749  latitude = latitude % (1000 * 60);
750  s = (double) latitude / 1000.0;
751  ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
752  h, m, s, latitude_hemisphere);
753 
754  if (longitude > equator) {
755  longitude_hemisphere = 'E';
756  longitude = longitude - equator;
757  } else {
758  longitude_hemisphere = 'W';
759  longitude = equator - longitude;
760  }
761  h = longitude / (1000 * 60 * 60);
762  longitude = longitude % (1000 * 60 * 60);
763  m = longitude / (1000 * 60);
764  longitude = longitude % (1000 * 60);
765  s = (double) longitude / (1000.0);
766  ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
767  h, m, s, longitude_hemisphere);
768 
769  s = ((double) altitude) / 100;
770  s -= 100000;
771 
772  if(altitude%100 != 0)
773  ldns_buffer_printf(output, "%.2f", s);
774  else
775  ldns_buffer_printf(output, "%.0f", s);
776 
777  ldns_buffer_printf(output, "m ");
778 
779  loc_cm_print(output, (size & 0xf0) >> 4, size & 0x0f);
780  ldns_buffer_printf(output, "m ");
781 
782  loc_cm_print(output, (horizontal_precision & 0xf0) >> 4,
783  horizontal_precision & 0x0f);
784  ldns_buffer_printf(output, "m ");
785 
786  loc_cm_print(output, (vertical_precision & 0xf0) >> 4,
787  vertical_precision & 0x0f);
788  ldns_buffer_printf(output, "m");
789 
790  return ldns_buffer_status(output);
791  } else {
792  return ldns_rdf2buffer_str_hex(output, rdf);
793  }
794 }
795 
798 {
799  ldns_buffer_printf(output, "\\# %u ", ldns_rdf_size(rdf));
800  return ldns_rdf2buffer_str_hex(output, rdf);
801 }
802 
805 {
806  ldns_buffer_printf(output, "0x");
807  return ldns_rdf2buffer_str_hex(output, rdf);
808 }
809 
812 {
813  return ldns_rdf2buffer_str_hex(output, rdf);
814 }
815 
818 {
819  /* protocol, followed by bitmap of services */
820  struct protoent *protocol;
821  char *proto_name = NULL;
822  uint8_t protocol_nr;
823  struct servent *service;
824  uint16_t current_service;
825 
826  if(ldns_rdf_size(rdf) < 1) {
828  }
829  protocol_nr = ldns_rdf_data(rdf)[0];
830  protocol = getprotobynumber((int) protocol_nr);
831  if (protocol && (protocol->p_name != NULL)) {
832  proto_name = protocol->p_name;
833  ldns_buffer_printf(output, "%s ", protocol->p_name);
834  } else {
835  ldns_buffer_printf(output, "%u ", protocol_nr);
836  }
837 
838 #ifdef HAVE_ENDPROTOENT
839  endprotoent();
840 #endif
841 
842  for (current_service = 0;
843  current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) {
844  if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) {
845  service = getservbyport((int) htons(current_service),
846  proto_name);
847  if (service && service->s_name) {
848  ldns_buffer_printf(output, "%s ", service->s_name);
849  } else {
850  ldns_buffer_printf(output, "%u ", current_service);
851  }
852 #ifdef HAVE_ENDSERVENT
853  endservent();
854 #endif
855  }
856  /* exit from loop before integer overflow */
857  if(current_service == 65535) { break; }
858  }
859  return ldns_buffer_status(output);
860 }
861 
862 static ldns_status
863 ldns_rdf2buffer_str_nsec_fmt(ldns_buffer *output,
864  const ldns_output_format* fmt, const ldns_rdf *rdf)
865 {
866  /* Note: this code is duplicated in higher.c in
867  * ldns_nsec_type_check() function
868  */
869  uint8_t window_block_nr;
870  uint8_t bitmap_length;
871  uint16_t type;
872  uint16_t pos = 0;
873  uint16_t bit_pos;
874  uint8_t *data = ldns_rdf_data(rdf);
875 
876  while((size_t)(pos + 2) < ldns_rdf_size(rdf)) {
877  window_block_nr = data[pos];
878  bitmap_length = data[pos + 1];
879  pos += 2;
880  if (ldns_rdf_size(rdf) < pos + bitmap_length) {
882  }
883  for (bit_pos = 0; bit_pos < (bitmap_length) * 8; bit_pos++) {
884  if (! ldns_get_bit(&data[pos], bit_pos)) {
885  continue;
886  }
887  type = 256 * (uint16_t) window_block_nr + bit_pos;
888 
889  if (! ldns_output_format_covers_type(fmt, type) &&
890  ldns_rr_descript(type) &&
891  ldns_rr_descript(type)->_name){
892 
893  ldns_buffer_printf(output, "%s ",
894  ldns_rr_descript(type)->_name);
895  } else {
896  ldns_buffer_printf(output, "TYPE%u ", type);
897  }
898  }
899  pos += (uint16_t) bitmap_length;
900  }
901  return ldns_buffer_status(output);
902 }
903 
906 {
907  return ldns_rdf2buffer_str_nsec_fmt(output,
909 }
910 
913 {
914  uint8_t salt_length;
915  uint8_t salt_pos;
916 
917  uint8_t *data = ldns_rdf_data(rdf);
918 
919  if(ldns_rdf_size(rdf) < 1) {
921  }
922  salt_length = data[0];
923  /* from now there are variable length entries so remember pos */
924  if (salt_length == 0 || ((size_t)salt_length)+1 > ldns_rdf_size(rdf)) {
925  ldns_buffer_printf(output, "- ");
926  } else {
927  for (salt_pos = 0; salt_pos < salt_length; salt_pos++) {
928  ldns_buffer_printf(output, "%02x", data[1 + salt_pos]);
929  }
930  ldns_buffer_printf(output, " ");
931  }
932 
933  return ldns_buffer_status(output);
934 }
935 
938 {
939  /* period is the number of seconds */
940  if (ldns_rdf_size(rdf) != 4) {
942  }
943  ldns_buffer_printf(output, "%u", ldns_read_uint32(ldns_rdf_data(rdf)));
944  return ldns_buffer_status(output);
945 }
946 
949 {
950  /* tsigtime is 48 bits network order unsigned integer */
951  uint64_t tsigtime = 0;
952  uint8_t *data = ldns_rdf_data(rdf);
953  uint64_t d0, d1, d2, d3, d4, d5;
954 
955  if (ldns_rdf_size(rdf) < 6) {
957  }
958  d0 = data[0]; /* cast to uint64 for shift operations */
959  d1 = data[1];
960  d2 = data[2];
961  d3 = data[3];
962  d4 = data[4];
963  d5 = data[5];
964  tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5;
965 
966  ldns_buffer_printf(output, "%llu ", (long long)tsigtime);
967 
968  return ldns_buffer_status(output);
969 }
970 
973 {
974  uint8_t *data = ldns_rdf_data(rdf);
975  uint16_t address_family;
976  uint8_t prefix;
977  bool negation;
978  uint8_t adf_length;
979  size_t i;
980  size_t pos = 0;
981 
982  while (pos < (unsigned int) ldns_rdf_size(rdf)) {
983  if(pos + 3 >= (unsigned)ldns_rdf_size(rdf))
985  address_family = ldns_read_uint16(&data[pos]);
986  prefix = data[pos + 2];
987  negation = data[pos + 3] & LDNS_APL_NEGATION;
988  adf_length = data[pos + 3] & LDNS_APL_MASK;
989  if (address_family == LDNS_APL_IP4) {
990  /* check if prefix < 32? */
991  if (negation) {
992  ldns_buffer_printf(output, "!");
993  }
994  ldns_buffer_printf(output, "%u:", address_family);
995  /* address is variable length 0 - 4 */
996  for (i = 0; i < 4; i++) {
997  if (i > 0) {
998  ldns_buffer_printf(output, ".");
999  }
1000  if (i < (unsigned short) adf_length) {
1001  if(pos+i+4 >= ldns_rdf_size(rdf))
1003  ldns_buffer_printf(output, "%d",
1004  data[pos + i + 4]);
1005  } else {
1006  ldns_buffer_printf(output, "0");
1007  }
1008  }
1009  ldns_buffer_printf(output, "/%u ", prefix);
1010  } else if (address_family == LDNS_APL_IP6) {
1011  /* check if prefix < 128? */
1012  if (negation) {
1013  ldns_buffer_printf(output, "!");
1014  }
1015  ldns_buffer_printf(output, "%u:", address_family);
1016  /* address is variable length 0 - 16 */
1017  for (i = 0; i < 16; i++) {
1018  if (i % 2 == 0 && i > 0) {
1019  ldns_buffer_printf(output, ":");
1020  }
1021  if (i < (unsigned short) adf_length) {
1022  if(pos+i+4 >= ldns_rdf_size(rdf))
1024  ldns_buffer_printf(output, "%02x",
1025  data[pos + i + 4]);
1026  } else {
1027  ldns_buffer_printf(output, "00");
1028  }
1029  }
1030  ldns_buffer_printf(output, "/%u ", prefix);
1031 
1032  } else {
1033  /* unknown address family */
1034  ldns_buffer_printf(output,
1035  "Unknown address family: %u data: ",
1036  address_family);
1037  for (i = 1; i < (unsigned short) (4 + adf_length); i++) {
1038  if(pos+i >= ldns_rdf_size(rdf))
1040  ldns_buffer_printf(output, "%02x", data[i]);
1041  }
1042  }
1043  pos += 4 + adf_length;
1044  }
1045  return ldns_buffer_status(output);
1046 }
1047 
1050 {
1051  size_t size;
1052  char *b64;
1053  if (ldns_rdf_size(rdf) < 2) {
1055  }
1056  /* Subtract the size (2) of the number that specifies the length */
1057  size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf) - 2);
1058  ldns_buffer_printf(output, "%u ", ldns_rdf_size(rdf) - 2);
1059  if (ldns_rdf_size(rdf) > 2) {
1060  b64 = LDNS_XMALLOC(char, size);
1061  if(!b64)
1062  return LDNS_STATUS_MEM_ERR;
1063 
1064  if (ldns_rdf_size(rdf) > 2 &&
1065  ldns_b64_ntop(ldns_rdf_data(rdf) + 2,
1066  ldns_rdf_size(rdf) - 2,
1067  b64, size)) {
1068  ldns_buffer_printf(output, "%s", b64);
1069  }
1070  LDNS_FREE(b64);
1071  }
1072  return ldns_buffer_status(output);
1073 }
1074 
1077 {
1078  /* wire format from
1079  http://www.ietf.org/internet-drafts/draft-ietf-ipseckey-rr-12.txt
1080  */
1081  uint8_t *data = ldns_rdf_data(rdf);
1082  uint8_t precedence;
1083  uint8_t gateway_type;
1084  uint8_t algorithm;
1085 
1086  ldns_rdf *gateway = NULL;
1087  uint8_t *gateway_data;
1088 
1089  size_t public_key_size;
1090  uint8_t *public_key_data;
1091  ldns_rdf *public_key;
1092 
1093  size_t offset = 0;
1094  ldns_status status;
1095 
1096  if (ldns_rdf_size(rdf) < 3) {
1098  }
1099  precedence = data[0];
1100  gateway_type = data[1];
1101  algorithm = data[2];
1102  offset = 3;
1103 
1104  switch (gateway_type) {
1105  case 0:
1106  /* no gateway */
1107  break;
1108  case 1:
1109  if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) {
1110  return LDNS_STATUS_ERR;
1111  }
1112  gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN);
1113  if(!gateway_data)
1114  return LDNS_STATUS_MEM_ERR;
1115  memcpy(gateway_data, &data[offset], LDNS_IP4ADDRLEN);
1116  gateway = ldns_rdf_new(LDNS_RDF_TYPE_A,
1117  LDNS_IP4ADDRLEN , gateway_data);
1118  offset += LDNS_IP4ADDRLEN;
1119  if(!gateway) {
1120  LDNS_FREE(gateway_data);
1121  return LDNS_STATUS_MEM_ERR;
1122  }
1123  break;
1124  case 2:
1125  if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) {
1126  return LDNS_STATUS_ERR;
1127  }
1128  gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN);
1129  if(!gateway_data)
1130  return LDNS_STATUS_MEM_ERR;
1131  memcpy(gateway_data, &data[offset], LDNS_IP6ADDRLEN);
1132  offset += LDNS_IP6ADDRLEN;
1133  gateway =
1135  LDNS_IP6ADDRLEN, gateway_data);
1136  if(!gateway) {
1137  LDNS_FREE(gateway_data);
1138  return LDNS_STATUS_MEM_ERR;
1139  }
1140  break;
1141  case 3:
1142  status = ldns_wire2dname(&gateway, data,
1143  ldns_rdf_size(rdf), &offset);
1144  if(status != LDNS_STATUS_OK)
1145  return status;
1146  break;
1147  default:
1148  /* error? */
1149  break;
1150  }
1151 
1152  if (ldns_rdf_size(rdf) <= offset) {
1153  ldns_rdf_deep_free(gateway);
1154  return LDNS_STATUS_ERR;
1155  }
1156  public_key_size = ldns_rdf_size(rdf) - offset;
1157  public_key_data = LDNS_XMALLOC(uint8_t, public_key_size);
1158  if(!public_key_data) {
1159  ldns_rdf_deep_free(gateway);
1160  return LDNS_STATUS_MEM_ERR;
1161  }
1162  memcpy(public_key_data, &data[offset], public_key_size);
1163  public_key = ldns_rdf_new(LDNS_RDF_TYPE_B64,
1164  public_key_size, public_key_data);
1165  if(!public_key) {
1166  LDNS_FREE(public_key_data);
1167  ldns_rdf_deep_free(gateway);
1168  return LDNS_STATUS_MEM_ERR;
1169  }
1170 
1171  ldns_buffer_printf(output, "%u %u %u ", precedence, gateway_type, algorithm);
1172  if (gateway)
1173  (void) ldns_rdf2buffer_str(output, gateway);
1174  else
1175  ldns_buffer_printf(output, ".");
1176  ldns_buffer_printf(output, " ");
1177  (void) ldns_rdf2buffer_str(output, public_key);
1178 
1179  ldns_rdf_deep_free(gateway);
1180  ldns_rdf_deep_free(public_key);
1181 
1182  return ldns_buffer_status(output);
1183 }
1184 
1187 {
1188  if (ldns_rdf_size(rdf) != 8) {
1190  }
1191  ldns_buffer_printf(output,"%.4x:%.4x:%.4x:%.4x",
1192  ldns_read_uint16(ldns_rdf_data(rdf)),
1193  ldns_read_uint16(ldns_rdf_data(rdf)+2),
1194  ldns_read_uint16(ldns_rdf_data(rdf)+4),
1195  ldns_read_uint16(ldns_rdf_data(rdf)+6));
1196  return ldns_buffer_status(output);
1197 }
1198 
1201 {
1202  if (ldns_rdf_size(rdf) != 6) {
1204  }
1205  ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1206  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1207  ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1208  ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5]);
1209  return ldns_buffer_status(output);
1210 }
1211 
1214 {
1215  if (ldns_rdf_size(rdf) != 8) {
1217  }
1218  ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1219  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1220  ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1221  ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5],
1222  ldns_rdf_data(rdf)[6], ldns_rdf_data(rdf)[7]);
1223  return ldns_buffer_status(output);
1224 }
1225 
1228 {
1229  size_t nchars;
1230  const uint8_t* chars;
1231  char ch;
1232  if (ldns_rdf_size(rdf) < 2) {
1234  }
1235  nchars = ldns_rdf_data(rdf)[0];
1236  if (nchars >= ldns_rdf_size(rdf) || /* should be rdf_size - 1 */
1237  nchars < 1) {
1239  }
1240  chars = ldns_rdf_data(rdf) + 1;
1241  while (nchars > 0) {
1242  ch = (char)*chars++;
1243  if (! isalnum((unsigned char)ch)) {
1245  }
1246  ldns_buffer_printf(output, "%c", ch);
1247  nchars--;
1248  }
1249  return ldns_buffer_status(output);
1250 }
1251 
1254 {
1255 
1256  ldns_buffer_printf(output, "\"");
1257  ldns_characters2buffer_str(output,
1258  ldns_rdf_size(rdf), ldns_rdf_data(rdf));
1259  ldns_buffer_printf(output, "\"");
1260  return ldns_buffer_status(output);
1261 }
1262 
1265 {
1266  uint8_t *data = ldns_rdf_data(rdf);
1267  size_t rdf_size = ldns_rdf_size(rdf);
1268  uint8_t hit_size;
1269  uint16_t pk_size;
1270  int written;
1271 
1272  if (rdf_size < 6) {
1274  }
1275  if ((hit_size = data[0]) == 0 ||
1276  (pk_size = ldns_read_uint16(data + 2)) == 0 ||
1277  rdf_size < (size_t) hit_size + pk_size + 4) {
1278 
1280  }
1281 
1282  ldns_buffer_printf(output, "%d ", (int) data[1]);
1283 
1284  for (data += 4; hit_size > 0; hit_size--, data++) {
1285 
1286  ldns_buffer_printf(output, "%02x", (int) *data);
1287  }
1288  ldns_buffer_write_char(output, (uint8_t) ' ');
1289 
1290  if (ldns_buffer_reserve(output,
1291  ldns_b64_ntop_calculate_size(pk_size))) {
1292 
1293  written = ldns_b64_ntop(data, pk_size,
1294  (char *) ldns_buffer_current(output),
1295  ldns_buffer_remaining(output));
1296 
1297  if (written > 0 &&
1298  written < (int) ldns_buffer_remaining(output)) {
1299 
1300  output->_position += written;
1301  }
1302  }
1303  return ldns_buffer_status(output);
1304 }
1305 
1306 /* implementation mimicked from ldns_rdf2buffer_str_ipseckey */
1309 {
1310  /* wire format from
1311  * draft-ietf-mboned-driad-amt-discovery Section 4.2
1312  */
1313  uint8_t *data = ldns_rdf_data(rdf);
1314  uint8_t precedence;
1315  uint8_t discovery_optional;
1316  uint8_t relay_type;
1317 
1318  ldns_rdf *relay = NULL;
1319  uint8_t *relay_data;
1320 
1321  size_t offset = 0;
1322  ldns_status status;
1323 
1324  if (ldns_rdf_size(rdf) < 2) {
1326  }
1327  precedence = data[0];
1328  discovery_optional = ((data[1] & 0x80) >> 7);
1329  relay_type = data[1] & 0x7F;
1330  offset = 2;
1331 
1332  switch (relay_type) {
1333  case 0:
1334  /* no relay */
1335  break;
1336  case 1:
1337  if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) {
1338  return LDNS_STATUS_ERR;
1339  }
1340  relay_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN);
1341  if(!relay_data)
1342  return LDNS_STATUS_MEM_ERR;
1343  memcpy(relay_data, &data[offset], LDNS_IP4ADDRLEN);
1344  relay = ldns_rdf_new(LDNS_RDF_TYPE_A,
1345  LDNS_IP4ADDRLEN , relay_data);
1346  offset += LDNS_IP4ADDRLEN;
1347  if(!relay) {
1348  LDNS_FREE(relay_data);
1349  return LDNS_STATUS_MEM_ERR;
1350  }
1351  break;
1352  case 2:
1353  if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) {
1354  return LDNS_STATUS_ERR;
1355  }
1356  relay_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN);
1357  if(!relay_data)
1358  return LDNS_STATUS_MEM_ERR;
1359  memcpy(relay_data, &data[offset], LDNS_IP6ADDRLEN);
1360  offset += LDNS_IP6ADDRLEN;
1361  relay =
1363  LDNS_IP6ADDRLEN, relay_data);
1364  if(!relay) {
1365  LDNS_FREE(relay_data);
1366  return LDNS_STATUS_MEM_ERR;
1367  }
1368  break;
1369  case 3:
1370  status = ldns_wire2dname(&relay, data,
1371  ldns_rdf_size(rdf), &offset);
1372  if(status != LDNS_STATUS_OK)
1373  return status;
1374  break;
1375  default:
1376  /* error? */
1377  break;
1378  }
1379 
1380  if (ldns_rdf_size(rdf) != offset) {
1381  ldns_rdf_deep_free(relay);
1382  return LDNS_STATUS_ERR;
1383  }
1384  ldns_buffer_printf(output, "%u %u %u ",
1385  precedence, discovery_optional, relay_type);
1386  if (relay)
1387  (void) ldns_rdf2buffer_str(output, relay);
1388 
1389  ldns_rdf_deep_free(relay);
1390  return ldns_buffer_status(output);
1391 }
1392 
1393 #ifdef RRTYPE_SVCB_HTTPS
1394 ldns_status svcparam_key2buffer_str(ldns_buffer *output, uint16_t key);
1395 
1396 static ldns_status
1397 svcparam_mandatory2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1398 {
1399  if (sz % 2)
1401 
1402  svcparam_key2buffer_str(output, ldns_read_uint16(data));
1403  for (data += 2, sz -= 2; sz; data += 2, sz -= 2) {
1404  ldns_buffer_write_char(output, ',');
1405  svcparam_key2buffer_str(output, ldns_read_uint16(data));
1406  }
1407  return ldns_buffer_status(output);
1408 }
1409 
1410 static ldns_status
1411 svcparam_alpn2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1412 {
1413  uint8_t *eod = data + sz, *dp;
1414  bool quote = false;
1415  size_t i;
1416 
1417  for (dp = data; dp < eod && !quote; dp += 1 + *dp) {
1418  if (dp + 1 + *dp > eod)
1420 
1421  for (i = 0; i < *dp; i++)
1422  if (isspace(dp[i + 1]))
1423  break;
1424  quote = i < *dp;
1425  }
1426  if (quote)
1427  ldns_buffer_write_char(output, '"');
1428  while (data < eod) {
1429  uint8_t *eot = data + 1 + *data;
1430 
1431  if (eot > eod)
1433 
1434  if (eod - data < (int)sz)
1435  ldns_buffer_write_char(output, ',');
1436 
1437  for (data += 1; data < eot; data += 1) {
1438  uint8_t ch = *data;
1439 
1440  if (isprint(ch) || ch == '\t') {
1441  if (ch == '"' || ch == ',' || ch == '\\')
1442  ldns_buffer_write_char(output, '\\');
1443  ldns_buffer_write_char(output, ch);
1444  } else
1445  ldns_buffer_printf(output, "\\%03u"
1446  , (unsigned)ch);
1447  }
1448  }
1449  if (quote)
1450  ldns_buffer_write_char(output, '"');
1451  return ldns_buffer_status(output);
1452 }
1453 
1454 static ldns_status
1455 svcparam_port2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1456 {
1457  if (sz != 2)
1459  ldns_buffer_printf(output, "%d", (int)ldns_read_uint16(data));
1460  return ldns_buffer_status(output);
1461 }
1462 
1463 static ldns_status
1464 svcparam_ipv4hint2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1465 {
1466  char str[INET_ADDRSTRLEN];
1467 
1468  if (sz % 4 || !inet_ntop(AF_INET, data, str, INET_ADDRSTRLEN))
1470 
1471  ldns_buffer_write_chars(output, str);
1472 
1473  for (data += 4, sz -= 4; sz ; data += 4, sz -= 4 ) {
1474  ldns_buffer_write_char(output, ',');
1475  if (!inet_ntop(AF_INET, data, str, INET_ADDRSTRLEN))
1477 
1478  ldns_buffer_write_chars(output, str);
1479  }
1480  return ldns_buffer_status(output);
1481 }
1482 
1483 static ldns_status
1484 svcparam_ech2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1485 {
1486  size_t str_sz = ldns_b64_ntop_calculate_size(sz);
1487  int written;
1488 
1489  if (!ldns_buffer_reserve(output, str_sz))
1490  return LDNS_STATUS_MEM_ERR;
1491 
1492  written = ldns_b64_ntop( data, sz
1493  , (char *)ldns_buffer_current(output), str_sz);
1494  if (written > 0)
1495  ldns_buffer_skip(output, written);
1496  else
1498 
1499  return ldns_buffer_status(output);
1500 }
1501 
1502 static ldns_status
1503 svcparam_ipv6hint2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1504 {
1505  char str[INET6_ADDRSTRLEN];
1506 
1507  if (sz % 16 || !inet_ntop(AF_INET6, data, str, INET6_ADDRSTRLEN))
1509 
1510  ldns_buffer_write_chars(output, str);
1511 
1512  for (data += 16, sz -= 16; sz ; data += 16, sz -= 16) {
1513  ldns_buffer_write_char(output, ',');
1514  if (!inet_ntop(AF_INET6, data, str, INET6_ADDRSTRLEN))
1516 
1517  ldns_buffer_write_chars(output, str);
1518  }
1519  return ldns_buffer_status(output);
1520 }
1521 
1522 static ldns_status
1523 svcparam_value2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1524 {
1525  uint8_t *eod = data + sz, *dp;
1526  bool quote = false;
1527 
1528  for (dp = data; dp < eod && !isspace(*dp); dp++)
1529  ; /* pass */
1530 
1531  if ((quote = dp < eod))
1532  ldns_buffer_write_char(output, '"');
1533 
1534  for (dp = data; dp < eod; dp++) {
1535  uint8_t ch = *dp;
1536 
1537  if (isprint(ch) || ch == '\t') {
1538  if (ch == '"' || ch == '\\')
1539  ldns_buffer_write_char(output, '\\');
1540  ldns_buffer_write_char(output, ch);
1541  } else
1542  ldns_buffer_printf(output, "\\%03u", (unsigned)ch);
1543  }
1544  if (quote)
1545  ldns_buffer_write_char(output, '"');
1546  return ldns_buffer_status(output);
1547 }
1548 
1551 {
1552  uint8_t *data, *dp, *next_dp = NULL;
1553  size_t sz;
1554  ldns_status st;
1555 
1556  if (!output)
1557  return LDNS_STATUS_NULL;
1558 
1559  if (!rdf || !(data = ldns_rdf_data(rdf)) || !(sz = ldns_rdf_size(rdf)))
1560  /* No svcparams is just fine. Just nothing to print. */
1561  return LDNS_STATUS_OK;
1562 
1563  for (dp = data; dp + 4 <= data + sz; dp = next_dp) {
1564  ldns_svcparam_key key = ldns_read_uint16(dp);
1565  uint16_t val_sz = ldns_read_uint16(dp + 2);
1566 
1567  if ((next_dp = dp + 4 + val_sz) > data + sz)
1569 
1570  if (dp > data)
1571  ldns_buffer_write_char(output, ' ');
1572 
1573  if ((st = svcparam_key2buffer_str(output, key)))
1574  return st;
1575 
1576  if (val_sz == 0)
1577  continue;
1578  dp += 4;
1579  ldns_buffer_write_char(output, '=');
1580  switch (key) {
1582  st = svcparam_mandatory2buffer_str(output, val_sz, dp);
1583  break;
1585  st = svcparam_alpn2buffer_str(output, val_sz, dp);
1586  break;
1590  st = svcparam_port2buffer_str(output, val_sz, dp);
1591  break;
1593  st = svcparam_ipv4hint2buffer_str(output, val_sz, dp);
1594  break;
1595  case LDNS_SVCPARAM_KEY_ECH:
1596  st = svcparam_ech2buffer_str(output, val_sz, dp);
1597  break;
1599  st = svcparam_ipv6hint2buffer_str(output, val_sz, dp);
1600  break;
1601  default:
1602  st = svcparam_value2buffer_str(output, val_sz, dp);
1603  break;
1604  }
1605  if (st)
1606  return st;
1607  }
1608  return ldns_buffer_status(output);
1609 }
1610 #else /* #ifdef RRTYPE_SVCB_HTTPS */
1613 {
1614  (void)output; (void)rdf;
1615  return LDNS_STATUS_NOT_IMPL;
1616 }
1617 #endif /* #ifdef RRTYPE_SVCB_HTTPS */
1618 
1619 static ldns_status
1620 ldns_rdf2buffer_str_fmt(ldns_buffer *buffer,
1621  const ldns_output_format* fmt, const ldns_rdf *rdf)
1622 {
1624 
1625  /*ldns_buffer_printf(buffer, "%u:", ldns_rdf_get_type(rdf));*/
1626  if (rdf) {
1627  switch(ldns_rdf_get_type(rdf)) {
1628  case LDNS_RDF_TYPE_NONE:
1629  break;
1630  case LDNS_RDF_TYPE_DNAME:
1631  res = ldns_rdf2buffer_str_dname(buffer, rdf);
1632  break;
1633  case LDNS_RDF_TYPE_INT8: /* Don't output mnemonics for these */
1634  case LDNS_RDF_TYPE_ALG:
1638  res = ldns_rdf2buffer_str_int8(buffer, rdf);
1639  break;
1640  case LDNS_RDF_TYPE_INT16:
1641  res = ldns_rdf2buffer_str_int16(buffer, rdf);
1642  break;
1643  case LDNS_RDF_TYPE_INT32:
1644  res = ldns_rdf2buffer_str_int32(buffer, rdf);
1645  break;
1646  case LDNS_RDF_TYPE_PERIOD:
1647  res = ldns_rdf2buffer_str_period(buffer, rdf);
1648  break;
1650  res = ldns_rdf2buffer_str_tsigtime(buffer, rdf);
1651  break;
1652  case LDNS_RDF_TYPE_A:
1653  res = ldns_rdf2buffer_str_a(buffer, rdf);
1654  break;
1655  case LDNS_RDF_TYPE_AAAA:
1656  res = ldns_rdf2buffer_str_aaaa(buffer, rdf);
1657  break;
1658  case LDNS_RDF_TYPE_STR:
1659  res = ldns_rdf2buffer_str_str(buffer, rdf);
1660  break;
1661  case LDNS_RDF_TYPE_APL:
1662  res = ldns_rdf2buffer_str_apl(buffer, rdf);
1663  break;
1664  case LDNS_RDF_TYPE_B32_EXT:
1665  res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1666  break;
1667  case LDNS_RDF_TYPE_B64:
1668  res = ldns_rdf2buffer_str_b64(buffer, rdf);
1669  break;
1670  case LDNS_RDF_TYPE_HEX:
1671  res = ldns_rdf2buffer_str_hex(buffer, rdf);
1672  break;
1673  case LDNS_RDF_TYPE_NSEC:
1674  res = ldns_rdf2buffer_str_nsec_fmt(buffer, fmt, rdf);
1675  break;
1677  res = ldns_rdf2buffer_str_nsec3_salt(buffer, rdf);
1678  break;
1679  case LDNS_RDF_TYPE_TYPE:
1680  res = ldns_rdf2buffer_str_type_fmt(buffer, fmt, rdf);
1681  break;
1682  case LDNS_RDF_TYPE_CLASS:
1683  res = ldns_rdf2buffer_str_class(buffer, rdf);
1684  break;
1686  res = ldns_rdf2buffer_str_cert_alg(buffer, rdf);
1687  break;
1688  case LDNS_RDF_TYPE_UNKNOWN:
1689  res = ldns_rdf2buffer_str_unknown(buffer, rdf);
1690  break;
1691  case LDNS_RDF_TYPE_TIME:
1692  res = ldns_rdf2buffer_str_time(buffer, rdf);
1693  break;
1694  case LDNS_RDF_TYPE_HIP:
1695  res = ldns_rdf2buffer_str_hip(buffer, rdf);
1696  break;
1697  case LDNS_RDF_TYPE_LOC:
1698  res = ldns_rdf2buffer_str_loc(buffer, rdf);
1699  break;
1700  case LDNS_RDF_TYPE_WKS:
1701  case LDNS_RDF_TYPE_SERVICE:
1702  res = ldns_rdf2buffer_str_wks(buffer, rdf);
1703  break;
1704  case LDNS_RDF_TYPE_NSAP:
1705  res = ldns_rdf2buffer_str_nsap(buffer, rdf);
1706  break;
1707  case LDNS_RDF_TYPE_ATMA:
1708  res = ldns_rdf2buffer_str_atma(buffer, rdf);
1709  break;
1711  res = ldns_rdf2buffer_str_ipseckey(buffer, rdf);
1712  break;
1714  res = ldns_rdf2buffer_str_int16_data(buffer, rdf);
1715  break;
1717  res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1718  break;
1719  case LDNS_RDF_TYPE_ILNP64:
1720  res = ldns_rdf2buffer_str_ilnp64(buffer, rdf);
1721  break;
1722  case LDNS_RDF_TYPE_EUI48:
1723  res = ldns_rdf2buffer_str_eui48(buffer, rdf);
1724  break;
1725  case LDNS_RDF_TYPE_EUI64:
1726  res = ldns_rdf2buffer_str_eui64(buffer, rdf);
1727  break;
1728  case LDNS_RDF_TYPE_TAG:
1729  res = ldns_rdf2buffer_str_tag(buffer, rdf);
1730  break;
1732  res = ldns_rdf2buffer_str_long_str(buffer, rdf);
1733  break;
1735  res = ldns_rdf2buffer_str_amtrelay(buffer, rdf);
1736  break;
1738  res = ldns_rdf2buffer_str_svcparams(buffer, rdf);
1739  break;
1740  }
1741  } else {
1743  ldns_buffer_printf(buffer, "(null) ");
1744  res = LDNS_STATUS_ERR;
1745  }
1746  return res;
1747 }
1748 
1751 {
1752  return ldns_rdf2buffer_str_fmt(buffer,ldns_output_format_default,rdf);
1753 }
1754 
1755 static ldns_rdf *
1756 ldns_b32_ext2dname(const ldns_rdf *rdf)
1757 {
1758  size_t size;
1759  char *b32;
1760  ldns_rdf *out;
1761  if(ldns_rdf_size(rdf) == 0)
1762  return NULL;
1763  /* remove -1 for the b32-hash-len octet */
1764  size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
1765  /* add one for the end nul for the string */
1766  b32 = LDNS_XMALLOC(char, size + 2);
1767  if (b32) {
1769  ldns_rdf_size(rdf) - 1, b32, size+1) > 0) {
1770  b32[size] = '.';
1771  b32[size+1] = '\0';
1772  if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) {
1773  LDNS_FREE(b32);
1774  return out;
1775  }
1776  }
1777  LDNS_FREE(b32);
1778  }
1779  return NULL;
1780 }
1781 
1782 static ldns_status
1783 ldns_rr2buffer_str_rfc3597(ldns_buffer *output, const ldns_rr *rr)
1784 {
1785  size_t total_rdfsize = 0;
1786  size_t i, j;
1787 
1788  ldns_buffer_printf(output, "TYPE%u\t", ldns_rr_get_type(rr));
1789  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1790  total_rdfsize += ldns_rdf_size(ldns_rr_rdf(rr, i));
1791  }
1792  if (total_rdfsize == 0) {
1793  ldns_buffer_printf(output, "\\# 0\n");
1794  return ldns_buffer_status(output);
1795  }
1796  ldns_buffer_printf(output, "\\# %d ", total_rdfsize);
1797  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1798  for (j = 0; j < ldns_rdf_size(ldns_rr_rdf(rr, i)); j++) {
1799  ldns_buffer_printf(output, "%.2x",
1800  ldns_rdf_data(ldns_rr_rdf(rr, i))[j]);
1801  }
1802  }
1803  ldns_buffer_printf(output, "\n");
1804  return ldns_buffer_status(output);
1805 }
1806 
1809  const ldns_output_format *fmt, const ldns_rr *rr)
1810 {
1811  uint16_t i, flags;
1812  ldns_status status = LDNS_STATUS_OK;
1814 
1815  if (fmt_st == NULL) {
1816  fmt_st = (ldns_output_format_storage*)
1818  }
1819  if (!(fmt_st->flags & LDNS_FMT_SHORT)) {
1820  if (!rr) {
1821  if (LDNS_COMMENT_NULLS & fmt_st->flags) {
1822  ldns_buffer_printf(output, "; (null)\n");
1823  }
1824  return ldns_buffer_status(output);
1825  }
1826  if (ldns_rr_owner(rr)) {
1827  status = ldns_rdf2buffer_str_dname(output, ldns_rr_owner(rr));
1828  }
1829  if (status != LDNS_STATUS_OK) {
1830  return status;
1831  }
1832 
1833  /* TTL should NOT be printed if it is a question */
1834  if (!ldns_rr_is_question(rr)) {
1835  ldns_buffer_printf(output, "\t%u", (unsigned)ldns_rr_ttl(rr));
1836  }
1837 
1838  ldns_buffer_printf(output, "\t");
1839  status = ldns_rr_class2buffer_str(output, ldns_rr_get_class(rr));
1840  if (status != LDNS_STATUS_OK) {
1841  return status;
1842  }
1843  ldns_buffer_printf(output, "\t");
1844 
1845  if (ldns_output_format_covers_type(fmt, ldns_rr_get_type(rr))) {
1846  return ldns_rr2buffer_str_rfc3597(output, rr);
1847  }
1848  status = ldns_rr_type2buffer_str(output, ldns_rr_get_type(rr));
1849  if (status != LDNS_STATUS_OK) {
1850  return status;
1851  }
1852 
1853  if (ldns_rr_rd_count(rr) > 0) {
1854  ldns_buffer_printf(output, "\t");
1855  } else if (!ldns_rr_is_question(rr)) {
1856  ldns_buffer_printf(output, "\t\\# 0");
1857  }
1858  } else if (ldns_rr_rd_count(rr) == 0) {
1859  /* assert(fmt_st->flags & LDNS_FMT_SHORT); */
1860 
1861  ldns_buffer_printf(output, "# 0");
1862  }
1863  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1864  /* ldns_rdf2buffer_str handles NULL input fine! */
1865  if ((fmt_st->flags & LDNS_FMT_ZEROIZE_RRSIGS) &&
1867  ((/* inception */ i == 4 &&
1868  ldns_rdf_get_type(ldns_rr_rdf(rr, 4)) ==
1869  LDNS_RDF_TYPE_TIME) ||
1870  (/* expiration */ i == 5 &&
1871  ldns_rdf_get_type(ldns_rr_rdf(rr, 5)) ==
1872  LDNS_RDF_TYPE_TIME) ||
1873  (/* signature */ i == 8 &&
1874  ldns_rdf_get_type(ldns_rr_rdf(rr, 8)) ==
1875  LDNS_RDF_TYPE_B64))) {
1876 
1877  ldns_buffer_printf(output, "(null)");
1878  status = ldns_buffer_status(output);
1879  } else if ((fmt_st->flags & LDNS_FMT_PAD_SOA_SERIAL) &&
1881  /* serial */ i == 2 &&
1882  ldns_rdf_get_type(ldns_rr_rdf(rr, 2)) ==
1884  ldns_buffer_printf(output, "%10lu",
1885  (unsigned long) ldns_read_uint32(
1886  ldns_rdf_data(ldns_rr_rdf(rr, 2))));
1887  status = ldns_buffer_status(output);
1888  } else {
1889  status = ldns_rdf2buffer_str_fmt(output,
1890  fmt, ldns_rr_rdf(rr, i));
1891  }
1892  if(status != LDNS_STATUS_OK)
1893  return status;
1894  if (i < ldns_rr_rd_count(rr) - 1) {
1895  ldns_buffer_printf(output, " ");
1896  }
1897  }
1898  /* per RR special comments - handy for DNSSEC types */
1899  /* check to prevent question sec. rr from
1900  * getting here */
1901  if (ldns_rr_rd_count(rr) > 0) {
1902  switch (ldns_rr_get_type(rr)) {
1903  case LDNS_RR_TYPE_DNSKEY:
1904  /* if ldns_rr_rd_count(rr) > 0
1905  then ldns_rr_rdf(rr, 0) exists! */
1906  if (! (fmt_st->flags & LDNS_COMMENT_KEY)) {
1907  break;
1908  }
1909  flags = ldns_rdf2native_int16(ldns_rr_rdf(rr, 0));
1910  ldns_buffer_printf(output, " ;{");
1911  if (fmt_st->flags & LDNS_COMMENT_KEY_ID) {
1912  ldns_buffer_printf(output, "id = %u",
1913  (unsigned int) ldns_calc_keytag(rr));
1914  }
1915  if ((fmt_st->flags & LDNS_COMMENT_KEY_TYPE) &&
1916  (flags & LDNS_KEY_ZONE_KEY)){
1917 
1918  if (flags & LDNS_KEY_SEP_KEY) {
1919  ldns_buffer_printf(output, " (ksk)");
1920  } else {
1921  ldns_buffer_printf(output, " (zsk)");
1922  }
1923  if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE){
1924  ldns_buffer_printf(output, ", ");
1925  }
1926  } else if (fmt_st->flags
1929  ldns_buffer_printf( output, ", ");
1930  }
1931  if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE) {
1932  ldns_buffer_printf(output, "size = %db",
1934  }
1935  ldns_buffer_printf(output, "}");
1936  break;
1937  case LDNS_RR_TYPE_RRSIG:
1938  if ((fmt_st->flags & LDNS_COMMENT_KEY)
1939  && (fmt_st->flags& LDNS_COMMENT_RRSIGS)
1940  && ldns_rr_rdf(rr, 6) != NULL) {
1941  ldns_buffer_printf(output, " ;{id = %d}",
1943  ldns_rr_rdf(rr, 6)));
1944  }
1945  break;
1946  case LDNS_RR_TYPE_DS:
1947  if ((fmt_st->flags & LDNS_COMMENT_BUBBLEBABBLE) &&
1948  ldns_rr_rdf(rr, 3) != NULL) {
1949 
1950  uint8_t *data = ldns_rdf_data(
1951  ldns_rr_rdf(rr, 3));
1952  size_t len = ldns_rdf_size(ldns_rr_rdf(rr, 3));
1953  char *babble = ldns_bubblebabble(data, len);
1954  if(babble) {
1955  ldns_buffer_printf(output,
1956  " ;{%s}", babble);
1957  }
1958  LDNS_FREE(babble);
1959  }
1960  break;
1961  case LDNS_RR_TYPE_NSEC3:
1962  if (! (fmt_st->flags & LDNS_COMMENT_FLAGS) &&
1963  ! (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN)) {
1964  break;
1965  }
1966  ldns_buffer_printf(output, " ;{");
1967  if ((fmt_st->flags & LDNS_COMMENT_FLAGS)) {
1968  if (ldns_nsec3_optout(rr)) {
1969  ldns_buffer_printf(output,
1970  " flags: optout");
1971  } else {
1972  ldns_buffer_printf(output," flags: -");
1973  }
1974  if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1975  fmt_st->hashmap != NULL) {
1976  ldns_buffer_printf(output, ", ");
1977  }
1978  }
1979  if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1980  fmt_st->hashmap != NULL) {
1981  ldns_rbnode_t *node;
1982  ldns_rdf *key = ldns_dname_label(
1983  ldns_rr_owner(rr), 0);
1984  if (key) {
1985  node = ldns_rbtree_search(
1986  fmt_st->hashmap,
1987  (void *) key);
1988  if (node->data) {
1989  ldns_buffer_printf(output,
1990  "from: ");
1991  (void) ldns_rdf2buffer_str(
1992  output,
1994  (ldns_dnssec_name*)
1995  node->data
1996  ));
1997  }
1998  ldns_rdf_deep_free(key);
1999  }
2000  key = ldns_b32_ext2dname(
2001  ldns_nsec3_next_owner(rr));
2002  if (key) {
2003  node = ldns_rbtree_search(
2004  fmt_st->hashmap,
2005  (void *) key);
2006  if (node->data) {
2007  ldns_buffer_printf(output,
2008  " to: ");
2009  (void) ldns_rdf2buffer_str(
2010  output,
2012  (ldns_dnssec_name*)
2013  node->data
2014  ));
2015  }
2016  ldns_rdf_deep_free(key);
2017  }
2018  }
2019  ldns_buffer_printf(output, "}");
2020  break;
2021  default:
2022  break;
2023 
2024  }
2025  }
2026  /* last */
2027  ldns_buffer_printf(output, "\n");
2028  return ldns_buffer_status(output);
2029 }
2030 
2033 {
2035 }
2036 
2039  const ldns_output_format *fmt, const ldns_rr_list *list)
2040 {
2041  uint16_t i;
2042 
2043  for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
2044  (void) ldns_rr2buffer_str_fmt(output, fmt,
2045  ldns_rr_list_rr(list, i));
2046  }
2047  return ldns_buffer_status(output);
2048 }
2049 
2052 {
2054  output, ldns_output_format_default, list);
2055 }
2056 
2059 {
2061  (int) ldns_pkt_get_opcode(pkt));
2063  (int) ldns_pkt_get_rcode(pkt));
2064 
2065  ldns_buffer_printf(output, ";; ->>HEADER<<- ");
2066  if (opcode) {
2067  ldns_buffer_printf(output, "opcode: %s, ", opcode->name);
2068  } else {
2069  ldns_buffer_printf(output, "opcode: ?? (%u), ",
2070  ldns_pkt_get_opcode(pkt));
2071  }
2072  if (rcode) {
2073  ldns_buffer_printf(output, "rcode: %s, ", rcode->name);
2074  } else {
2075  ldns_buffer_printf(output, "rcode: ?? (%u), ", ldns_pkt_get_rcode(pkt));
2076  }
2077  ldns_buffer_printf(output, "id: %d\n", ldns_pkt_id(pkt));
2078  ldns_buffer_printf(output, ";; flags: ");
2079 
2080  if (ldns_pkt_qr(pkt)) {
2081  ldns_buffer_printf(output, "qr ");
2082  }
2083  if (ldns_pkt_aa(pkt)) {
2084  ldns_buffer_printf(output, "aa ");
2085  }
2086  if (ldns_pkt_tc(pkt)) {
2087  ldns_buffer_printf(output, "tc ");
2088  }
2089  if (ldns_pkt_rd(pkt)) {
2090  ldns_buffer_printf(output, "rd ");
2091  }
2092  if (ldns_pkt_cd(pkt)) {
2093  ldns_buffer_printf(output, "cd ");
2094  }
2095  if (ldns_pkt_ra(pkt)) {
2096  ldns_buffer_printf(output, "ra ");
2097  }
2098  if (ldns_pkt_ad(pkt)) {
2099  ldns_buffer_printf(output, "ad ");
2100  }
2101  ldns_buffer_printf(output, "; ");
2102  ldns_buffer_printf(output, "QUERY: %u, ", ldns_pkt_qdcount(pkt));
2103  ldns_buffer_printf(output, "ANSWER: %u, ", ldns_pkt_ancount(pkt));
2104  ldns_buffer_printf(output, "AUTHORITY: %u, ", ldns_pkt_nscount(pkt));
2105  ldns_buffer_printf(output, "ADDITIONAL: %u ", ldns_pkt_arcount(pkt));
2106  return ldns_buffer_status(output);
2107 }
2108 
2109 
2110 /* print EDNS option data in the Dig format: 76 61 6c 69 ... */
2111 static void
2112 ldns_edns_hex_data2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2113 {
2114  size_t j;
2115  for (j = 0; j < len; j++) {
2116  ldns_buffer_printf(output, " %02x", data[j]);
2117  }
2118 }
2119 
2120 static ldns_status
2121 ldns_edns_llq2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2122 {
2123  /* LLQ constants */
2124  const char* llq_errors[] = {"NO-ERROR", "SERV-FULL", "STATIC",
2125  "FORMAT-ERR", "NO-SUCH-LLQ", "BAD-VERS", "UNKNOWN_ERR"};
2126  const unsigned int llq_errors_num = 7;
2127  const char* llq_opcodes[] = {"LLQ-SETUP", "LLQ-REFRESH", "LLQ-EVENT"};
2128  const unsigned int llq_opcodes_num = 3;
2129 
2130  uint16_t version, llq_opcode, error_code;
2131  uint64_t llq_id;
2132  uint32_t lease_life; /* Requested or granted life of LLQ, in seconds */
2133 
2134  ldns_buffer_printf(output, "; Long-Lived Query:");
2135 
2136  /* read the record */
2137  if(len != 18) {
2138  ldns_buffer_printf(output, " malformed LLQ ");
2139  ldns_edns_hex_data2buffer_str(output, data, len);
2140 
2141  return ldns_buffer_status(output);
2142  }
2143  version = ldns_read_uint16(data);
2144  llq_opcode = ldns_read_uint16(data+2);
2145  error_code = ldns_read_uint16(data+4);
2146  memmove(&llq_id, data+6, sizeof(uint64_t));
2147  lease_life = ldns_read_uint32(data+14);
2148 
2149  /* print option field entires */
2150  ldns_buffer_printf(output, "v%d ", (int)version);
2151 
2152  if(llq_opcode < llq_opcodes_num) {
2153  ldns_buffer_printf(output, "%s", llq_opcodes[llq_opcode]);
2154  } else {
2155  ldns_buffer_printf(output, "opcode %d", (int)llq_opcode);
2156  }
2157 
2158  if(error_code < llq_errors_num)
2159  ldns_buffer_printf(output, " %s", llq_errors[error_code]);
2160  else {
2161  ldns_buffer_printf(output, " error %d", (int)error_code);
2162  }
2163 
2164 #ifndef USE_WINSOCK
2165  ldns_buffer_printf(output, " id %llx lease-life %lu",
2166  (unsigned long long)llq_id, (unsigned long)lease_life);
2167 #else
2168  ldns_buffer_printf(output, " id %I64x lease-life %lu",
2169  (unsigned long long)llq_id, (unsigned long)lease_life);
2170 #endif
2171  return ldns_buffer_status(output);
2172 }
2173 
2174 
2175 static ldns_status
2176 ldns_edns_ul2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2177 {
2178  uint32_t lease;
2179 
2180  ldns_buffer_printf(output, "; Update Lease:");
2181 
2182  if(len != 4) {
2183  ldns_buffer_printf(output, " malformed UL ");
2184  ldns_edns_hex_data2buffer_str(output, data, len);
2185  return ldns_buffer_status(output);
2186  }
2187  lease = ldns_read_uint32(data);
2188  ldns_buffer_printf(output, "lease %lu", (unsigned long)lease);
2189 
2190  return ldns_buffer_status(output);
2191 }
2192 
2193 static ldns_status
2194 ldns_edns_nsid2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2195 {
2196  size_t i, printed=0;
2197 
2198  ldns_buffer_printf(output, "; NSID:");
2199  ldns_edns_hex_data2buffer_str(output, data, len);
2200 
2201  /* print the human-readable text string */
2202  for(i = 0; i < len; i++) {
2203  if(isprint((unsigned char)data[i]) || data[i] == '\t') {
2204  if(!printed) {
2205  ldns_buffer_printf(output, " (");
2206  printed = 1;
2207  }
2208  ldns_buffer_printf(output, "%c", (char)data[i]);
2209  }
2210  }
2211  if(printed)
2212  ldns_buffer_printf(output, ")");
2213  return ldns_buffer_status(output);
2214 }
2215 
2216 
2217 static ldns_status
2218 ldns_edns_dau2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2219 {
2220  size_t i;
2221  ldns_lookup_table *lt;
2222 
2223  ldns_buffer_printf(output, "; DNSSEC Algorithm Understood (DAU):");
2224 
2225  for(i = 0; i <len; i++) {
2226  lt = ldns_lookup_by_id(ldns_algorithms, data[i]);
2227  if (lt && lt->name) {
2228  ldns_buffer_printf(output, " %s", lt->name);
2229  } else {
2230  ldns_buffer_printf(output, " ALG%u", data[i]);
2231  }
2232  }
2233  return ldns_buffer_status(output);
2234 }
2235 
2236 static ldns_status
2237 ldns_edns_dhu2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2238 {
2239  size_t i;
2240  ldns_lookup_table *lt;
2241 
2242  ldns_buffer_printf(output, "; DS Hash Understood (DHU):");
2243 
2244  for(i = 0; i < len; i++) {
2245  lt = ldns_lookup_by_id(ldns_hashes, data[i]);
2246  if (lt && lt->name) {
2247  ldns_buffer_printf(output, " %s", lt->name);
2248  } else {
2249  ldns_buffer_printf(output, " ALG%u", data[i]);
2250  }
2251  }
2252  return ldns_buffer_status(output);
2253 }
2254 
2255 static ldns_status
2256 ldns_edns_d3u2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2257 {
2258  size_t i;
2259 
2260  ldns_buffer_printf(output, "; NSEC3 Hash Understood (N3U):");
2261 
2262  for(i=0; i<len; i++) {
2263  if(data[i] == 1) {
2264  ldns_buffer_printf(output, " SHA1");
2265  } else {
2266  ldns_buffer_printf(output, " %d", (int)data[i]);
2267  }
2268  }
2269  return ldns_buffer_status(output);
2270 }
2271 
2272 static ldns_status
2273 ldns_edns_subnet2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2274 {
2275  uint16_t family;
2276  uint8_t source, scope;
2277  if(len < 4) {
2278  ldns_buffer_printf(output, "malformed subnet ");
2279  ldns_edns_hex_data2buffer_str(output, data, len);
2280  return ldns_buffer_status(output);
2281  }
2282  family = ldns_read_uint16(data);
2283  source = data[2];
2284  scope = data[3];
2285  if(family == 1) {
2286  /* IPv4 */
2287  char buf[64];
2288  uint8_t ip4[4];
2289  memset(ip4, 0, sizeof(ip4));
2290  if(len-4 > 4) {
2291  ldns_buffer_printf(output, "trailingdata:");
2292  ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2293  ldns_buffer_printf(output, " ");
2294  len = 4+4;
2295  }
2296  memmove(ip4, data+4, len-4);
2297  if(!inet_ntop(AF_INET, ip4, buf, (socklen_t) sizeof(buf))) {
2298  ldns_buffer_printf(output, "ip4ntoperror ");
2299  ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2300  } else {
2301  ldns_buffer_printf(output, "%s", buf);
2302  }
2303  } else if(family == 2) {
2304  /* IPv6 */
2305  char buf[64];
2306  uint8_t ip6[16];
2307  memset(ip6, 0, sizeof(ip6));
2308  if(len-4 > 16) {
2309  ldns_buffer_printf(output, "trailingdata:");
2310  ldns_edns_hex_data2buffer_str(output, data+4+16, len-4-16);
2311  ldns_buffer_printf(output, " ");
2312  len = 4+16;
2313  }
2314  memmove(ip6, data+4, len-4);
2315 #ifdef AF_INET6
2316  if(!inet_ntop(AF_INET6, ip6, buf, (socklen_t) sizeof(buf))) {
2317  ldns_buffer_printf(output, "ip6ntoperror ");
2318  ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2319  } else {
2320  ldns_buffer_printf(output, "%s", buf);
2321  }
2322 #else
2323  ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2324 #endif
2325  } else {
2326  /* unknown */
2327  ldns_buffer_printf(output, "family %d ", (int)family);
2328  ldns_edns_hex_data2buffer_str(output, data, len);
2329  }
2330  ldns_buffer_printf(output, "/%d scope /%d", (int)source, (int)scope);
2331 
2332  return ldns_buffer_status(output);
2333 }
2334 
2335 static ldns_status
2336 ldns_edns_expire2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2337 {
2338 
2339  ldns_buffer_printf(output, "; EXPIRE:");
2340 
2341  if (!(len == 0) || len == 4) {
2342  ldns_buffer_printf(output, "malformed expire ");
2343  ldns_edns_hex_data2buffer_str(output, data, len);
2344 
2345  return ldns_buffer_status(output);
2346  }
2347 
2348  // TODO can this output be more accurate?
2349  ldns_edns_hex_data2buffer_str(output, data, len);
2350 
2351  return ldns_buffer_status(output);
2352 }
2353 
2354 
2355 static ldns_status
2356 ldns_edns_cookie2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2357 {
2358  ldns_buffer_printf(output, "; COOKIE:");
2359 
2360  /* the size of an EDNS cookie is restricted by RFC 7873 */
2361  if (!(len == 8 || (len >= 16 && len < 40))) {
2362  ldns_buffer_printf(output, "malformed cookie ");
2363  ldns_edns_hex_data2buffer_str(output, data, len);
2364  }
2365  ldns_edns_hex_data2buffer_str(output, data, len);
2366 
2367  return ldns_buffer_status(output);
2368 }
2369 
2370 static ldns_status
2371 ldns_edns_keepalive2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2372 {
2373  uint16_t timeout;
2374 
2375  ldns_buffer_printf(output, "; KEEPALIVE:");
2376 
2377  if(!(len == 0 || len == 2)) {
2378  ldns_buffer_printf(output, "malformed keepalive ");
2379  ldns_edns_hex_data2buffer_str(output, data, len);
2380 
2381  return ldns_buffer_status(output);
2382  }
2383 
2384  if(len == 0) {
2385  ldns_buffer_printf(output, "no timeout value (only valid for client option)");
2386  } else {
2387  timeout = ldns_read_uint16(data);
2388  ldns_buffer_printf(output, "timeout value in units of 100ms %u", (int)timeout);
2389  }
2390  return ldns_buffer_status(output);
2391 }
2392 
2393 static ldns_status
2394 ldns_edns_padding2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2395 {
2396  ldns_buffer_printf(output, "; PADDING: ");
2397  ldns_edns_hex_data2buffer_str(output, data, len);
2398 
2399  return ldns_buffer_status(output);
2400 }
2401 
2402 static ldns_status
2403 ldns_edns_chain2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2404 {
2405  ldns_rdf** temp = NULL;
2406 
2407  ldns_buffer_printf(output, "; CHAIN: ");
2408 
2409  if (ldns_str2rdf_dname(temp, (char*) data) != LDNS_STATUS_OK) {
2410  ldns_buffer_printf(output, "malformed chain ");
2411  ldns_edns_hex_data2buffer_str(output, data, len);
2412 
2413  return ldns_buffer_status(output);
2414  }
2415 
2416  ldns_characters2buffer_str(output, len, data);
2417 
2418  return ldns_buffer_status(output);
2419 }
2420 
2421 static ldns_status
2422 ldns_edns_key_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2423 {
2424  size_t i;
2425 
2426  ldns_buffer_printf(output, "; KEY TAG: ");
2427 
2428  if(len < 2 || len % 2 != 0) {
2429  ldns_buffer_printf(output, "malformed key tag ");
2430  ldns_edns_hex_data2buffer_str(output, data, len);
2431 
2432  return ldns_buffer_status(output);
2433  }
2434 
2435  for (i = 0; i < len; i += 2) {
2436  uint16_t tag = ldns_read_uint16(data);
2437 
2438  ldns_buffer_printf(output, " %hu", tag);
2439  }
2440 
2441  return ldns_buffer_status(output);
2442 }
2443 
2444 static ldns_status
2445 ldns_edns_ede2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2446 {
2447  size_t i;
2448  uint16_t ede;
2449  ldns_buffer_printf(output, "; EDE:");
2450 
2451  if(len < 2) {
2452  ldns_buffer_printf(output, "malformed ede ");
2453  ldns_edns_hex_data2buffer_str(output, data, len);
2454 
2455  return ldns_buffer_status(output);
2456  }
2457 
2458  ede = ldns_read_uint16(data);
2459 
2460  switch (ede) {
2461  case LDNS_EDE_OTHER:
2462  ldns_buffer_printf(output, " 0 (Other): ");
2463  break;
2465  ldns_buffer_printf(output, " 1 (Unsupported DNSKEY Algorithm)");
2466  break;
2468  ldns_buffer_printf(output, " 2 (Unsupported DS Digest type)");
2469  break;
2470  case LDNS_EDE_STALE_ANSWER:
2471  ldns_buffer_printf(output, " 3 (Stale Answer)");
2472  break;
2474  ldns_buffer_printf(output, " 4 (Forged Answer)");
2475  break;
2477  ldns_buffer_printf(output, " 5 (DNSSEC Indeterminate)");
2478  break;
2479  case LDNS_EDE_DNSSEC_BOGUS:
2480  ldns_buffer_printf(output, " 6 (DNSSEC Bogus)");
2481  break;
2483  ldns_buffer_printf(output, " 7 (Signature Expired)");
2484  break;
2486  ldns_buffer_printf(output, " 8 (Signature Not Yet Valid)");
2487  break;
2489  ldns_buffer_printf(output, " 9 (DNSKEY Missing)");
2490  break;
2492  ldns_buffer_printf(output, " 10 (RRSIGs Missing)");
2493  break;
2495  ldns_buffer_printf(output, " 11 (No Zone Key Bit Set)");
2496  break;
2497  case LDNS_EDE_NSEC_MISSING:
2498  ldns_buffer_printf(output, " 12 (NSEC Missing)");
2499  break;
2500  case LDNS_EDE_CACHED_ERROR:
2501  ldns_buffer_printf(output, " 13 (Cached Error)");
2502  break;
2503  case LDNS_EDE_NOT_READY:
2504  ldns_buffer_printf(output, " 14 (Not Ready)");
2505  break;
2506  case LDNS_EDE_BLOCKED:
2507  ldns_buffer_printf(output, " 15 (Blocked)");
2508  break;
2509  case LDNS_EDE_CENSORED:
2510  ldns_buffer_printf(output, " 16 (Censored)");
2511  break;
2512  case LDNS_EDE_FILTERED:
2513  ldns_buffer_printf(output, " 17 (Filtered)");
2514  break;
2515  case LDNS_EDE_PROHIBITED:
2516  ldns_buffer_printf(output, " 18 (Prohibited)");
2517  break;
2519  ldns_buffer_printf(output, " 19 (NXDOMAIN Answer)");
2520  break;
2522  ldns_buffer_printf(output, " 20 (Not Authoritative)");
2523  break;
2525  ldns_buffer_printf(output, " 21 (Not Supported)");
2526  break;
2528  ldns_buffer_printf(output, " 22 (No Reachable Authority)");
2529  break;
2531  ldns_buffer_printf(output, " 23 (Network Error)");
2532  break;
2533  case LDNS_EDE_INVALID_DATA:
2534  ldns_buffer_printf(output, " 24 (Invalid Data)");
2535  break;
2537  ldns_buffer_printf(output, " 25 (Signature Expired Before Valid)");
2538  break;
2539  case LDNS_EDE_TOO_EARLY:
2540  ldns_buffer_printf(output, " 26 (Too Early)");
2541  break;
2542  default:
2543  ldns_buffer_printf(output, " %02x", data[0]);
2544  ldns_buffer_printf(output, " %02x", data[1]);
2545  break;
2546  }
2547 
2548  /* skip the EDE code in the output */
2549  data += 2;
2550  len -= 2;
2551 
2552  if (len > 2) {
2553  /* format the hex bytes */
2554  ldns_buffer_printf(output, ":");
2555  for (i = 0; i < len; i++) {
2556  ldns_buffer_printf(output, " %02x", data[i]);
2557  }
2558 
2559  /* format the human-readable string */
2560  ldns_buffer_printf(output, " (");
2561  ldns_characters2buffer_str(output, len, data);
2562  ldns_buffer_printf(output, ")");
2563  }
2564 
2565  return ldns_buffer_status(output);
2566 }
2567 
2568 static ldns_status
2569 ldns_edns_client_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2570 {
2571  ldns_buffer_printf(output, "; CLIENT-TAG:");
2572 
2573  if (len > 2) {
2574  ldns_buffer_printf(output, "malformed client-tag ");
2575  ldns_edns_hex_data2buffer_str(output, data, len);
2576 
2577  return ldns_buffer_status(output);
2578  }
2579 
2580  ldns_edns_hex_data2buffer_str(output, data, len);
2581 
2582  return ldns_buffer_status(output);
2583 }
2584 
2585 static ldns_status
2586 ldns_edns_server_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2587 {
2588  ldns_buffer_printf(output, "; SERVER-TAG:");
2589 
2590  if (len > 2) {
2591  ldns_buffer_printf(output, "malformed server-tag ");
2592  ldns_edns_hex_data2buffer_str(output, data, len);
2593 
2594  return ldns_buffer_status(output);
2595  }
2596 
2597  ldns_edns_hex_data2buffer_str(output, data, len);
2598 
2599  return ldns_buffer_status(output);
2600 }
2601 
2604 {
2605  size_t count = ldns_edns_option_list_get_count(edns_list);
2606  size_t i, size;
2607  uint8_t* data;
2608 
2609  for (i = 0; i < count; i++) {
2610  ldns_edns_option_code code;
2611  ldns_edns_option* edns = ldns_edns_option_list_get_option(edns_list, i);
2612 
2613  if (!edns) {
2614  break;
2615  }
2616 
2617  code = ldns_edns_get_code(edns);
2618  size = ldns_edns_get_size(edns);
2619  data = ldns_edns_get_data(edns);
2620 
2621  switch(code) {
2622  case LDNS_EDNS_LLQ:
2623  ldns_edns_llq2buffer_str(output, data, size);
2624  break;
2625  case LDNS_EDNS_UL:
2626  ldns_edns_ul2buffer_str(output, data, size);
2627  break;
2628  case LDNS_EDNS_NSID:
2629  ldns_edns_nsid2buffer_str(output, data, size);
2630  break;
2631  case LDNS_EDNS_DAU:
2632  ldns_edns_dau2buffer_str(output, data, size);
2633  break;
2634  case LDNS_EDNS_DHU:
2635  ldns_edns_dhu2buffer_str(output, data, size);
2636  break;
2637  case LDNS_EDNS_N3U:
2638  ldns_edns_d3u2buffer_str(output, data, size);
2639  break;
2641  ldns_edns_subnet2buffer_str(output, data, size);
2642  break;
2643  case LDNS_EDNS_EXPIRE:
2644  ldns_edns_expire2buffer_str(output, data, size);
2645  break;
2646  case LDNS_EDNS_COOKIE:
2647  ldns_edns_cookie2buffer_str(output, data, size);
2648  break;
2649  case LDNS_EDNS_KEEPALIVE:
2650  ldns_edns_keepalive2buffer_str(output, data, size);
2651  break;
2652  case LDNS_EDNS_PADDING:
2653  ldns_edns_padding2buffer_str(output, data, size);
2654  break;
2655  case LDNS_EDNS_CHAIN:
2656  ldns_edns_chain2buffer_str(output, data, size);
2657  break;
2658  case LDNS_EDNS_KEY_TAG:
2659  ldns_edns_key_tag2buffer_str(output, data, size);
2660  break;
2661  case LDNS_EDNS_EDE:
2662  ldns_edns_ede2buffer_str(output, data, size);
2663  break;
2664  case LDNS_EDNS_CLIENT_TAG:
2665  ldns_edns_client_tag2buffer_str(output, data, size);
2666  break;
2667  case LDNS_EDNS_SERVER_TAG:
2668  ldns_edns_server_tag2buffer_str(output, data, size);
2669  break;
2670  default:
2671  ldns_buffer_printf(output, "; OPT=%d:", code);
2672  ldns_edns_hex_data2buffer_str(output, data, size);
2673  break;
2674  }
2675  ldns_buffer_printf(output, "\n");
2676  }
2677 
2678  return ldns_buffer_status(output);
2679 }
2680 
2681 
2684  const ldns_output_format *fmt, const ldns_pkt *pkt)
2685 {
2686  uint16_t i;
2687  ldns_status status = LDNS_STATUS_OK;
2688  char *tmp;
2689  struct timeval time;
2690  time_t time_tt;
2691  int short_fmt = fmt && (fmt->flags & LDNS_FMT_SHORT);
2692 
2693  if (!pkt) {
2694  ldns_buffer_printf(output, "null");
2695  return LDNS_STATUS_OK;
2696  }
2697 
2698  if (!ldns_buffer_status_ok(output)) {
2699  return ldns_buffer_status(output);
2700  }
2701 
2702  if (!short_fmt) {
2703  status = ldns_pktheader2buffer_str(output, pkt);
2704  if (status != LDNS_STATUS_OK) {
2705  return status;
2706  }
2707 
2708  ldns_buffer_printf(output, "\n");
2709 
2710  ldns_buffer_printf(output, ";; QUESTION SECTION:\n;; ");
2711 
2712 
2713  for (i = 0; i < ldns_pkt_qdcount(pkt); i++) {
2714  status = ldns_rr2buffer_str_fmt(output, fmt,
2716  ldns_pkt_question(pkt), i));
2717  if (status != LDNS_STATUS_OK) {
2718  return status;
2719  }
2720  }
2721  ldns_buffer_printf(output, "\n");
2722 
2723  ldns_buffer_printf(output, ";; ANSWER SECTION:\n");
2724  }
2725  for (i = 0; i < ldns_pkt_ancount(pkt); i++) {
2726  status = ldns_rr2buffer_str_fmt(output, fmt,
2728  ldns_pkt_answer(pkt), i));
2729  if (status != LDNS_STATUS_OK) {
2730  return status;
2731  }
2732  }
2733  if (!short_fmt) {
2734  ldns_buffer_printf(output, "\n");
2735 
2736  ldns_buffer_printf(output, ";; AUTHORITY SECTION:\n");
2737 
2738  for (i = 0; i < ldns_pkt_nscount(pkt); i++) {
2739  status = ldns_rr2buffer_str_fmt(output, fmt,
2741  ldns_pkt_authority(pkt), i));
2742  if (status != LDNS_STATUS_OK) {
2743  return status;
2744  }
2745  }
2746  ldns_buffer_printf(output, "\n");
2747 
2748  ldns_buffer_printf(output, ";; ADDITIONAL SECTION:\n");
2749  for (i = 0; i < ldns_pkt_arcount(pkt); i++) {
2750  status = ldns_rr2buffer_str_fmt(output, fmt,
2752  ldns_pkt_additional(pkt), i));
2753  if (status != LDNS_STATUS_OK) {
2754  return status;
2755  }
2756 
2757  }
2758  ldns_buffer_printf(output, "\n");
2759  /* add some further fields */
2760  ldns_buffer_printf(output, ";; Query time: %d msec\n",
2761  ldns_pkt_querytime(pkt));
2762  if (ldns_pkt_edns(pkt)) {
2763  ldns_buffer_printf(output,
2764  ";; EDNS: version %u; flags:",
2765  ldns_pkt_edns_version(pkt));
2766  if (ldns_pkt_edns_do(pkt)) {
2767  ldns_buffer_printf(output, " do");
2768  }
2769  /* the extended rcode is the value set, shifted four bits,
2770  * and or'd with the original rcode */
2771  if (ldns_pkt_edns_extended_rcode(pkt)) {
2772  ldns_buffer_printf(output, " ; ext-rcode: %d",
2774  }
2775  ldns_buffer_printf(output, " ; udp: %u\n",
2776  ldns_pkt_edns_udp_size(pkt));
2777 
2778  if (pkt->_edns_list)
2780 
2781  else if (ldns_pkt_edns_data(pkt)) {
2782  ldns_edns_option_list* edns_list;
2783  /* parse the EDNS data into separate EDNS options
2784  * and add them to the list */
2785  if ((edns_list = pkt_edns_data2edns_option_list(ldns_pkt_edns_data(pkt)))) {
2786  ldns_edns_option_list2buffer_str(output, edns_list);
2788  } else {
2789  ldns_buffer_printf(output, ";; Data: ");
2790  (void)ldns_rdf2buffer_str(output, ldns_pkt_edns_data(pkt));
2791  }
2792  }
2793  }
2794  if (ldns_pkt_tsig(pkt)) {
2795  ldns_buffer_printf(output, ";; TSIG:\n;; ");
2796  (void) ldns_rr2buffer_str_fmt(
2797  output, fmt, ldns_pkt_tsig(pkt));
2798  ldns_buffer_printf(output, "\n");
2799  }
2800  if (ldns_pkt_answerfrom(pkt)) {
2801  tmp = ldns_rdf2str(ldns_pkt_answerfrom(pkt));
2802  ldns_buffer_printf(output, ";; SERVER: %s\n", tmp);
2803  LDNS_FREE(tmp);
2804  }
2805  time = ldns_pkt_timestamp(pkt);
2806  time_tt = (time_t)time.tv_sec;
2807  ldns_buffer_printf(output, ";; WHEN: %s",
2808  (char*)ctime(&time_tt));
2809 
2810  ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n",
2811  (int)ldns_pkt_size(pkt));
2812  }
2813  return status;
2814 }
2815 
2818 {
2820 }
2821 
2822 
2823 #ifdef HAVE_SSL
2824 static ldns_status
2825 ldns_hmac_key2buffer_str(ldns_buffer *output, const ldns_key *k)
2826 {
2827  ldns_status status;
2828  size_t i;
2829  ldns_rdf *b64_bignum;
2830 
2831  ldns_buffer_printf(output, "Key: ");
2832 
2833  i = ldns_key_hmac_size(k);
2835  status = ldns_rdf2buffer_str(output, b64_bignum);
2836  ldns_rdf_deep_free(b64_bignum);
2837  ldns_buffer_printf(output, "\n");
2838  return status;
2839 }
2840 #endif
2841 
2842 #if defined(HAVE_SSL) && defined(USE_GOST)
2843 static ldns_status
2844 ldns_gost_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2845 {
2846  unsigned char* pp = NULL;
2847  int ret;
2848  ldns_rdf *b64_bignum;
2849  ldns_status status;
2850 
2851  ldns_buffer_printf(output, "GostAsn1: ");
2852 
2853  ret = i2d_PrivateKey(p, &pp);
2854  b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)ret, pp);
2855  status = ldns_rdf2buffer_str(output, b64_bignum);
2856 
2857  ldns_rdf_deep_free(b64_bignum);
2858  OPENSSL_free(pp);
2859  ldns_buffer_printf(output, "\n");
2860  return status;
2861 }
2862 #endif
2863 
2864 #if defined(HAVE_SSL) && defined(USE_ED25519)
2865 static ldns_status
2866 ldns_ed25519_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2867 {
2868  unsigned char* pp = NULL;
2869  int ret;
2870  ldns_rdf *b64_bignum;
2871  ldns_status status;
2872 
2873  ldns_buffer_printf(output, "PrivateKey: ");
2874 
2875  ret = i2d_PrivateKey(p, &pp);
2876  /* 16 byte asn (302e020100300506032b657004220420) + 32byte key */
2877  if(ret != 16 + 32) {
2878  OPENSSL_free(pp);
2879  return LDNS_STATUS_ERR;
2880  }
2882  (size_t)ret-16, pp+16);
2883  status = ldns_rdf2buffer_str(output, b64_bignum);
2884 
2885  ldns_rdf_deep_free(b64_bignum);
2886  OPENSSL_free(pp);
2887  ldns_buffer_printf(output, "\n");
2888  return status;
2889 }
2890 #endif
2891 
2892 #if defined(HAVE_SSL) && defined(USE_ED448)
2893 static ldns_status
2894 ldns_ed448_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2895 {
2896  unsigned char* pp = NULL;
2897  int ret;
2898  ldns_rdf *b64_bignum;
2899  ldns_status status;
2900 
2901  ldns_buffer_printf(output, "PrivateKey: ");
2902 
2903  ret = i2d_PrivateKey(p, &pp);
2904  /* some-ASN + 57byte key */
2905  if(ret != 16 + 57) {
2906  OPENSSL_free(pp);
2907  return LDNS_STATUS_ERR;
2908  }
2910  (size_t)ret-16, pp+16);
2911  status = ldns_rdf2buffer_str(output, b64_bignum);
2912 
2913  ldns_rdf_deep_free(b64_bignum);
2914  OPENSSL_free(pp);
2915  ldns_buffer_printf(output, "\n");
2916  return status;
2917 }
2918 #endif
2919 
2920 #if defined(HAVE_SSL)
2922 static int
2923 ldns_print_bignum_b64_line(ldns_buffer* output, const char* label, const BIGNUM* num)
2924 {
2925  unsigned char *bignumbuf = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2926  if(!bignumbuf) return 0;
2927 
2928  ldns_buffer_printf(output, "%s: ", label);
2929  if(num) {
2930  ldns_rdf *b64_bignum = NULL;
2931  int i = BN_bn2bin(num, bignumbuf);
2932  if (i > LDNS_MAX_KEYLEN) {
2933  LDNS_FREE(bignumbuf);
2934  return 0;
2935  }
2936  b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)i, bignumbuf);
2937  if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) {
2938  ldns_rdf_deep_free(b64_bignum);
2939  LDNS_FREE(bignumbuf);
2940  return 0;
2941  }
2942  ldns_rdf_deep_free(b64_bignum);
2943  ldns_buffer_printf(output, "\n");
2944  } else {
2945  ldns_buffer_printf(output, "(Not available)\n");
2946  }
2947  LDNS_FREE(bignumbuf);
2948  return 1;
2949 }
2950 #endif
2951 
2954 {
2955  ldns_status status = LDNS_STATUS_OK;
2956  unsigned char *bignum;
2957 #ifdef HAVE_SSL
2958  RSA *rsa;
2959 #ifdef USE_DSA
2960  DSA *dsa;
2961 #endif /* USE_DSA */
2962 #endif /* HAVE_SSL */
2963 
2964  if (!k) {
2965  return LDNS_STATUS_ERR;
2966  }
2967 
2968  bignum = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2969  if (!bignum) {
2970  return LDNS_STATUS_ERR;
2971  }
2972 
2973  if (ldns_buffer_status_ok(output)) {
2974 #ifdef HAVE_SSL
2975  switch(ldns_key_algorithm(k)) {
2976  case LDNS_SIGN_RSASHA1:
2978  case LDNS_SIGN_RSASHA256:
2979  case LDNS_SIGN_RSASHA512:
2980  case LDNS_SIGN_RSAMD5:
2981  /* copied by looking at dnssec-keygen output */
2982  /* header */
2983  rsa = ldns_key_rsa_key(k);
2984 
2985  ldns_buffer_printf(output,"Private-key-format: v1.2\n");
2986  switch(ldns_key_algorithm(k)) {
2987  case LDNS_SIGN_RSAMD5:
2988  ldns_buffer_printf(output,
2989  "Algorithm: %u (RSA)\n",
2990  LDNS_RSAMD5);
2991  break;
2992  case LDNS_SIGN_RSASHA1:
2993  ldns_buffer_printf(output,
2994  "Algorithm: %u (RSASHA1)\n",
2995  LDNS_RSASHA1);
2996  break;
2998  ldns_buffer_printf(output,
2999  "Algorithm: %u (RSASHA1_NSEC3)\n",
3001  break;
3002 #ifdef USE_SHA2
3003  case LDNS_SIGN_RSASHA256:
3004  ldns_buffer_printf(output,
3005  "Algorithm: %u (RSASHA256)\n",
3006  LDNS_RSASHA256);
3007  break;
3008  case LDNS_SIGN_RSASHA512:
3009  ldns_buffer_printf(output,
3010  "Algorithm: %u (RSASHA512)\n",
3011  LDNS_RSASHA512);
3012  break;
3013 #endif
3014  default:
3015 #ifdef STDERR_MSGS
3016  fprintf(stderr, "Warning: unknown signature ");
3017  fprintf(stderr,
3018  "algorithm type %u\n",
3019  ldns_key_algorithm(k));
3020 #endif
3021  ldns_buffer_printf(output,
3022  "Algorithm: %u (Unknown)\n",
3023  ldns_key_algorithm(k));
3024  break;
3025  }
3026 
3027  /* print to buf, convert to bin, convert to b64,
3028  * print to buf */
3029 
3030 #ifndef S_SPLINT_S
3031  if(1) {
3032  const BIGNUM *n=NULL, *e=NULL, *d=NULL,
3033  *p=NULL, *q=NULL, *dmp1=NULL,
3034  *dmq1=NULL, *iqmp=NULL;
3035 #if OPENSSL_VERSION_NUMBER < 0x10100000 || (defined(HAVE_LIBRESSL) && LIBRESSL_VERSION_NUMBER < 0x20700000)
3036  n = rsa->n;
3037  e = rsa->e;
3038  d = rsa->d;
3039  p = rsa->p;
3040  q = rsa->q;
3041  dmp1 = rsa->dmp1;
3042  dmq1 = rsa->dmq1;
3043  iqmp = rsa->iqmp;
3044 #else
3045  RSA_get0_key(rsa, &n, &e, &d);
3046  RSA_get0_factors(rsa, &p, &q);
3047  RSA_get0_crt_params(rsa, &dmp1,
3048  &dmq1, &iqmp);
3049 #endif
3050  if(!ldns_print_bignum_b64_line(output, "Modulus", n))
3051  goto error;
3052  if(!ldns_print_bignum_b64_line(output, "PublicExponent", e))
3053  goto error;
3054  if(!ldns_print_bignum_b64_line(output, "PrivateExponent", d))
3055  goto error;
3056  if(!ldns_print_bignum_b64_line(output, "Prime1", p))
3057  goto error;
3058  if(!ldns_print_bignum_b64_line(output, "Prime2", q))
3059  goto error;
3060  if(!ldns_print_bignum_b64_line(output, "Exponent1", dmp1))
3061  goto error;
3062  if(!ldns_print_bignum_b64_line(output, "Exponent2", dmq1))
3063  goto error;
3064  if(!ldns_print_bignum_b64_line(output, "Coefficient", iqmp))
3065  goto error;
3066  }
3067 #endif /* splint */
3068 
3069  RSA_free(rsa);
3070  break;
3071 #ifdef USE_DSA
3072  case LDNS_SIGN_DSA:
3073  case LDNS_SIGN_DSA_NSEC3:
3074  dsa = ldns_key_dsa_key(k);
3075 
3076  ldns_buffer_printf(output,"Private-key-format: v1.2\n");
3077  if (ldns_key_algorithm(k) == LDNS_SIGN_DSA) {
3078  ldns_buffer_printf(output,"Algorithm: 3 (DSA)\n");
3079  } else if (ldns_key_algorithm(k) == LDNS_SIGN_DSA_NSEC3) {
3080  ldns_buffer_printf(output,"Algorithm: 6 (DSA_NSEC3)\n");
3081  }
3082 
3083  /* print to buf, convert to bin, convert to b64,
3084  * print to buf */
3085  if(1) {
3086  const BIGNUM *p=NULL, *q=NULL, *g=NULL,
3087  *priv_key=NULL, *pub_key=NULL;
3088 #if OPENSSL_VERSION_NUMBER < 0x10100000 || (defined(HAVE_LIBRESSL) && LIBRESSL_VERSION_NUMBER < 0x20700000)
3089 #ifndef S_SPLINT_S
3090  p = dsa->p;
3091  q = dsa->q;
3092  g = dsa->g;
3093  priv_key = dsa->priv_key;
3094  pub_key = dsa->pub_key;
3095 #endif /* splint */
3096 #else
3097  DSA_get0_pqg(dsa, &p, &q, &g);
3098  DSA_get0_key(dsa, &pub_key, &priv_key);
3099 #endif
3100  if(!ldns_print_bignum_b64_line(output, "Prime(p)", p))
3101  goto error;
3102  if(!ldns_print_bignum_b64_line(output, "Subprime(q)", q))
3103  goto error;
3104  if(!ldns_print_bignum_b64_line(output, "Base(g)", g))
3105  goto error;
3106  if(!ldns_print_bignum_b64_line(output, "Private_value(x)", priv_key))
3107  goto error;
3108  if(!ldns_print_bignum_b64_line(output, "Public_value(y)", pub_key))
3109  goto error;
3110  }
3111  break;
3112 #endif /* USE_DSA */
3113  case LDNS_SIGN_ECC_GOST:
3114  /* no format defined, use blob */
3115 #if defined(HAVE_SSL) && defined(USE_GOST)
3116  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3117  ldns_buffer_printf(output, "Algorithm: %d (ECC-GOST)\n", LDNS_SIGN_ECC_GOST);
3118  status = ldns_gost_key2buffer_str(output,
3119 #ifndef S_SPLINT_S
3120  k->_key.key
3121 #else
3122  NULL
3123 #endif
3124  );
3125 #else
3126  goto error;
3127 #endif /* GOST */
3128  break;
3131 #ifdef USE_ECDSA
3132  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3133  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3135 #ifndef S_SPLINT_S
3136  ldns_buffer_printf(output, ")\n");
3137  if(k->_key.key) {
3138  EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
3139  const BIGNUM* b = EC_KEY_get0_private_key(ec);
3140  if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
3141  goto error;
3142  /* down reference count in EC_KEY
3143  * its still assigned to the PKEY */
3144  EC_KEY_free(ec);
3145  }
3146 #endif /* splint */
3147 #else
3148  goto error;
3149 #endif /* ECDSA */
3150  break;
3151 #ifdef USE_ED25519
3152  case LDNS_SIGN_ED25519:
3153  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3154  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3156  ldns_buffer_printf(output, ")\n");
3157  if (status) break;
3158  status = ldns_ed25519_key2buffer_str(output,
3159  k->_key.key);
3160  break;
3161 #endif /* USE_ED25519 */
3162 #ifdef USE_ED448
3163  case LDNS_SIGN_ED448:
3164  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3165  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3167  ldns_buffer_printf(output, ")\n");
3168  if (status) break;
3169  status = ldns_ed448_key2buffer_str(output,
3170  k->_key.key);
3171  break;
3172 #endif /* USE_ED448 */
3173  case LDNS_SIGN_HMACMD5:
3174  /* there's not much of a format defined for TSIG */
3175  /* It's just a binary blob, Same for all algorithms */
3176  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3177  ldns_buffer_printf(output, "Algorithm: 157 (HMAC_MD5)\n");
3178  status = ldns_hmac_key2buffer_str(output, k);
3179  break;
3180  case LDNS_SIGN_HMACSHA1:
3181  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3182  ldns_buffer_printf(output, "Algorithm: 158 (HMAC_SHA1)\n");
3183  status = ldns_hmac_key2buffer_str(output, k);
3184  break;
3185  case LDNS_SIGN_HMACSHA224:
3186  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3187  ldns_buffer_printf(output, "Algorithm: 162 (HMAC_SHA224)\n");
3188  status = ldns_hmac_key2buffer_str(output, k);
3189  break;
3190  case LDNS_SIGN_HMACSHA256:
3191  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3192  ldns_buffer_printf(output, "Algorithm: 159 (HMAC_SHA256)\n");
3193  status = ldns_hmac_key2buffer_str(output, k);
3194  break;
3195  case LDNS_SIGN_HMACSHA384:
3196  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3197  ldns_buffer_printf(output, "Algorithm: 164 (HMAC_SHA384)\n");
3198  status = ldns_hmac_key2buffer_str(output, k);
3199  break;
3200  case LDNS_SIGN_HMACSHA512:
3201  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3202  ldns_buffer_printf(output, "Algorithm: 165 (HMAC_SHA512)\n");
3203  status = ldns_hmac_key2buffer_str(output, k);
3204  break;
3205  }
3206 #endif /* HAVE_SSL */
3207  } else {
3208  LDNS_FREE(bignum);
3209  return ldns_buffer_status(output);
3210  }
3211  LDNS_FREE(bignum);
3212  return status;
3213 
3214 #ifdef HAVE_SSL
3215  /* compiles warn the label isn't used */
3216 error:
3217  LDNS_FREE(bignum);
3218  return LDNS_STATUS_ERR;
3219 #endif /* HAVE_SSL */
3220 
3221 }
3222 
3223 /*
3224  * Zero terminate the buffer and copy data.
3225  */
3226 char *
3228 {
3229  char *str;
3230 
3231  /* check if buffer ends with \0, if not, and
3232  if there is space, add it */
3233  if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
3234  if (!ldns_buffer_reserve(buffer, 1)) {
3235  return NULL;
3236  }
3237  ldns_buffer_write_char(buffer, (uint8_t) '\0');
3238  if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
3239  return NULL;
3240  }
3241  }
3242 
3243  str = strdup((const char *)ldns_buffer_begin(buffer));
3244  if(!str) {
3245  return NULL;
3246  }
3247  return str;
3248 }
3249 
3250 /*
3251  * Zero terminate the buffer and export data.
3252  */
3253 char *
3255 {
3256  /* Append '\0' as string terminator */
3257  if (! ldns_buffer_reserve(buffer, 1)) {
3258  return NULL;
3259  }
3260  ldns_buffer_write_char(buffer, 0);
3261 
3262  /* reallocate memory to the size of the string and export */
3263  ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer));
3264  return ldns_buffer_export(buffer);
3265 }
3266 
3267 char *
3269 {
3270  char *result = NULL;
3272 
3273  if (!tmp_buffer) {
3274  return NULL;
3275  }
3276  if (ldns_rdf2buffer_str(tmp_buffer, rdf) == LDNS_STATUS_OK) {
3277  /* export and return string, destroy rest */
3278  result = ldns_buffer_export2str(tmp_buffer);
3279  }
3280  ldns_buffer_free(tmp_buffer);
3281  return result;
3282 }
3283 
3284 char *
3286 {
3287  char *result = NULL;
3289 
3290  if (!tmp_buffer) {
3291  return NULL;
3292  }
3293  if (ldns_rr2buffer_str_fmt(tmp_buffer, fmt, rr)
3294  == LDNS_STATUS_OK) {
3295  /* export and return string, destroy rest */
3296  result = ldns_buffer_export2str(tmp_buffer);
3297  }
3298  ldns_buffer_free(tmp_buffer);
3299  return result;
3300 }
3301 
3302 char *
3304 {
3306 }
3307 
3308 char *
3310 {
3311  char *result = NULL;
3313 
3314  if (!tmp_buffer) {
3315  return NULL;
3316  }
3317  if (ldns_pkt2buffer_str_fmt(tmp_buffer, fmt, pkt)
3318  == LDNS_STATUS_OK) {
3319  /* export and return string, destroy rest */
3320  result = ldns_buffer_export2str(tmp_buffer);
3321  }
3322 
3323  ldns_buffer_free(tmp_buffer);
3324  return result;
3325 }
3326 
3327 char *
3329 {
3331 }
3332 
3333 char *
3335 {
3336  char *result = NULL;
3338 
3339  if (!tmp_buffer) {
3340  return NULL;
3341  }
3342  if (ldns_key2buffer_str(tmp_buffer, k) == LDNS_STATUS_OK) {
3343  /* export and return string, destroy rest */
3344  result = ldns_buffer_export2str(tmp_buffer);
3345  }
3346  ldns_buffer_free(tmp_buffer);
3347  return result;
3348 }
3349 
3350 char *
3352 {
3353  char *result = NULL;
3355 
3356  if (!tmp_buffer) {
3357  return NULL;
3358  }
3359  if (list) {
3361  tmp_buffer, fmt, list)
3362  == LDNS_STATUS_OK) {
3363  }
3364  } else {
3365  if (fmt == NULL) {
3367  }
3368  if (fmt->flags & LDNS_COMMENT_NULLS) {
3369  ldns_buffer_printf(tmp_buffer, "; (null)\n");
3370  }
3371  }
3372 
3373  /* export and return string, destroy rest */
3374  result = ldns_buffer_export2str(tmp_buffer);
3375  ldns_buffer_free(tmp_buffer);
3376  return result;
3377 }
3378 
3379 char *
3381 {
3383 }
3384 
3385 void
3386 ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
3387 {
3388  char *str = ldns_rdf2str(rdf);
3389  if (str) {
3390  fprintf(output, "%s", str);
3391  } else {
3392  fprintf(output, ";Unable to convert rdf to string\n");
3393  }
3394  LDNS_FREE(str);
3395 }
3396 
3397 void
3398 ldns_rr_print_fmt(FILE *output,
3399  const ldns_output_format *fmt, const ldns_rr *rr)
3400 {
3401  char *str = ldns_rr2str_fmt(fmt, rr);
3402  if (str) {
3403  fprintf(output, "%s", str);
3404  } else {
3405  fprintf(output, ";Unable to convert rr to string\n");
3406  }
3407  LDNS_FREE(str);
3408 }
3409 
3410 void
3411 ldns_rr_print(FILE *output, const ldns_rr *rr)
3412 {
3414 }
3415 
3416 void
3417 ldns_pkt_print_fmt(FILE *output,
3418  const ldns_output_format *fmt, const ldns_pkt *pkt)
3419 {
3420  char *str = ldns_pkt2str_fmt(fmt, pkt);
3421  if (str) {
3422  fprintf(output, "%s", str);
3423  } else {
3424  fprintf(output, ";Unable to convert packet to string\n");
3425  }
3426  LDNS_FREE(str);
3427 }
3428 
3429 void
3430 ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
3431 {
3433 }
3434 
3435 void
3437  const ldns_output_format *fmt, const ldns_rr_list *lst)
3438 {
3439  size_t i;
3440  for (i = 0; i < ldns_rr_list_rr_count(lst); i++) {
3441  ldns_rr_print_fmt(output, fmt, ldns_rr_list_rr(lst, i));
3442  }
3443 }
3444 
3445 void
3446 ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
3447 {
3449 }
3450 
3451 void
3453  const ldns_output_format *fmt, const ldns_resolver *r)
3454 {
3455  uint16_t i;
3456  ldns_rdf **n;
3457  ldns_rdf **s;
3458  size_t *rtt;
3459  if (!r) {
3460  return;
3461  }
3463  s = ldns_resolver_searchlist(r);
3464  rtt = ldns_resolver_rtt(r);
3465 
3466  fprintf(output, "port: %d\n", (int)ldns_resolver_port(r));
3467  fprintf(output, "edns0 size: %d\n", (int)ldns_resolver_edns_udp_size(r));
3468  fprintf(output, "use ip6: %d\n", (int)ldns_resolver_ip6(r));
3469 
3470  fprintf(output, "recursive: %d\n", ldns_resolver_recursive(r));
3471  fprintf(output, "usevc: %d\n", ldns_resolver_usevc(r));
3472  fprintf(output, "igntc: %d\n", ldns_resolver_igntc(r));
3473  fprintf(output, "fail: %d\n", ldns_resolver_fail(r));
3474  fprintf(output, "retry: %d\n", (int)ldns_resolver_retry(r));
3475  fprintf(output, "retrans: %d\n", (int)ldns_resolver_retrans(r));
3476  fprintf(output, "fallback: %d\n", ldns_resolver_fallback(r));
3477  fprintf(output, "random: %d\n", ldns_resolver_random(r));
3478  fprintf(output, "timeout: %d\n", (int)ldns_resolver_timeout(r).tv_sec);
3479  fprintf(output, "dnssec: %d\n", ldns_resolver_dnssec(r));
3480  fprintf(output, "dnssec cd: %d\n", ldns_resolver_dnssec_cd(r));
3481  fprintf(output, "trust anchors (%d listed):\n",
3484  fprintf(output, "tsig: %s %s\n",
3487  fprintf(output, "debug: %d\n", ldns_resolver_debug(r));
3488 
3489  fprintf(output, "default domain: ");
3491  fprintf(output, "\n");
3492  fprintf(output, "apply default domain: %d\n", ldns_resolver_defnames(r));
3493 
3494  fprintf(output, "searchlist (%d listed):\n", (int)ldns_resolver_searchlist_count(r));
3495  for (i = 0; i < ldns_resolver_searchlist_count(r); i++) {
3496  fprintf(output, "\t");
3497  ldns_rdf_print(output, s[i]);
3498  fprintf(output, "\n");
3499  }
3500  fprintf(output, "apply search list: %d\n", ldns_resolver_dnsrch(r));
3501 
3502  fprintf(output, "nameservers (%d listed):\n", (int)ldns_resolver_nameserver_count(r));
3503  for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
3504  fprintf(output, "\t");
3505  ldns_rdf_print(output, n[i]);
3506 
3507  switch ((int)rtt[i]) {
3508  case LDNS_RESOLV_RTT_MIN:
3509  fprintf(output, " - reachable\n");
3510  break;
3511  case LDNS_RESOLV_RTT_INF:
3512  fprintf(output, " - unreachable\n");
3513  break;
3514  }
3515  }
3516 }
3517 
3518 void
3519 ldns_resolver_print(FILE *output, const ldns_resolver *r)
3520 {
3522 }
3523 
3524 void
3525 ldns_zone_print_fmt(FILE *output,
3526  const ldns_output_format *fmt, const ldns_zone *z)
3527 {
3528  if(ldns_zone_soa(z))
3529  ldns_rr_print_fmt(output, fmt, ldns_zone_soa(z));
3530  ldns_rr_list_print_fmt(output, fmt, ldns_zone_rrs(z));
3531 }
3532 void
3533 ldns_zone_print(FILE *output, const ldns_zone *z)
3534 {
3536 }
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
Definition: buffer.c:137
bool ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
changes the buffer's capacity.
Definition: buffer.c:60
bool ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
ensures BUFFER can contain at least AMOUNT more bytes.
Definition: buffer.c:80
ldns_buffer * ldns_buffer_new(size_t capacity)
creates a new buffer with the specified capacity.
Definition: buffer.c:16
int ldns_buffer_printf(ldns_buffer *buffer, const char *format,...)
prints to the buffer, increasing the capacity if required using buffer_reserve().
Definition: buffer.c:99
void * ldns_buffer_export(ldns_buffer *buffer)
Makes the buffer fixed and returns a pointer to the data.
Definition: buffer.c:150
int ldns_b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize)
ldns_rdf * ldns_dname_label(const ldns_rdf *rdf, uint8_t labelpos)
look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label.
Definition: dname.c:560
uint16_t ldns_calc_keytag(const ldns_rr *key)
calculates a keytag of a key for use in DNSSEC.
Definition: dnssec.c:277
bool ldns_nsec_bitmap_covers_type(const ldns_rdf *bitmap, ldns_rr_type type)
Check if RR type t is enumerated and set in the RR type bitmap rdf.
Definition: dnssec.c:1393
bool ldns_nsec3_optout(const ldns_rr *nsec3_rr)
Returns true if the opt-out flag has been set in the given NSEC3 RR.
Definition: dnssec.c:1286
ldns_status ldns_nsec_bitmap_set_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and sets the bit.
Definition: dnssec.c:1430
ldns_status ldns_nsec_bitmap_clear_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and clears the bit.
Definition: dnssec.c:1468
ldns_rdf * ldns_nsec3_next_owner(const ldns_rr *nsec3_rr)
Returns the first label of the next ownername in the NSEC3 chain (ie.
Definition: dnssec.c:1348
#define LDNS_MAX_KEYLEN
Definition: dnssec.h:41
ldns_rdf * ldns_dnssec_name_name(const ldns_dnssec_name *name)
Returns the domain name of the given dnssec_name structure.
Definition: dnssec_zone.c:395
uint8_t * ldns_edns_get_data(const ldns_edns_option *edns)
returns the EDNS option data.
Definition: edns.c:38
ldns_edns_option_code ldns_edns_get_code(const ldns_edns_option *edns)
returns the option code of the EDNS data.
Definition: edns.c:31
size_t ldns_edns_option_list_get_count(const ldns_edns_option_list *option_list)
returns the number of options in the EDNS options list.
Definition: edns.c:238
size_t ldns_edns_get_size(const ldns_edns_option *edns)
returns the size of the EDNS data.
Definition: edns.c:24
void ldns_edns_option_list_deep_free(ldns_edns_option_list *option_list)
Definition: edns.c:225
ldns_edns_option * ldns_edns_option_list_get_option(const ldns_edns_option_list *option_list, size_t index)
returns the EDNS option as the specified index in the list of EDNS options.
Definition: edns.c:248
@ LDNS_EDE_DNSSEC_INDETERMINATE
Definition: edns.h:58
@ LDNS_EDE_NOT_SUPPORTED
Definition: edns.h:74
@ LDNS_EDE_PROHIBITED
Definition: edns.h:71
@ LDNS_EDE_NOT_READY
Definition: edns.h:67
@ LDNS_EDE_UNSUPPORTED_DNSKEY_ALG
Definition: edns.h:54
@ LDNS_EDE_RRSIGS_MISSING
Definition: edns.h:63
@ LDNS_EDE_NO_REACHABLE_AUTHORITY
Definition: edns.h:75
@ LDNS_EDE_SIGNATURE_EXPIRED
Definition: edns.h:60
@ LDNS_EDE_DNSSEC_BOGUS
Definition: edns.h:59
@ LDNS_EDE_CENSORED
Definition: edns.h:69
@ LDNS_EDE_STALE_NXDOMAIN_ANSWER
Definition: edns.h:72
@ LDNS_EDE_NO_ZONE_KEY_BIT_SET
Definition: edns.h:64
@ LDNS_EDE_DNSKEY_MISSING
Definition: edns.h:62
@ LDNS_EDE_NETWORK_ERROR
Definition: edns.h:76
@ LDNS_EDE_FILTERED
Definition: edns.h:70
@ LDNS_EDE_BLOCKED
Definition: edns.h:68
@ LDNS_EDE_FORGED_ANSWER
Definition: edns.h:57
@ LDNS_EDE_SIGNATURE_EXPIRED_BEFORE_VALID
Definition: edns.h:78
@ LDNS_EDE_STALE_ANSWER
Definition: edns.h:56
@ LDNS_EDE_NOT_AUTHORITATIVE
Definition: edns.h:73
@ LDNS_EDE_CACHED_ERROR
Definition: edns.h:66
@ LDNS_EDE_NSEC_MISSING
Definition: edns.h:65
@ LDNS_EDE_OTHER
Definition: edns.h:53
@ LDNS_EDE_INVALID_DATA
Definition: edns.h:77
@ LDNS_EDE_SIGNATURE_NOT_YET_VALID
Definition: edns.h:61
@ LDNS_EDE_UNSUPPORTED_DS_DIGEST
Definition: edns.h:55
@ LDNS_EDE_TOO_EARLY
Definition: edns.h:79
enum ldns_enum_edns_option ldns_edns_option_code
Definition: edns.h:46
@ LDNS_EDNS_NSID
Definition: edns.h:30
@ LDNS_EDNS_KEEPALIVE
Definition: edns.h:38
@ LDNS_EDNS_DHU
Definition: edns.h:33
@ LDNS_EDNS_PADDING
Definition: edns.h:39
@ LDNS_EDNS_COOKIE
Definition: edns.h:37
@ LDNS_EDNS_DAU
Definition: edns.h:32
@ LDNS_EDNS_N3U
Definition: edns.h:34
@ LDNS_EDNS_UL
Definition: edns.h:29
@ LDNS_EDNS_CLIENT_SUBNET
Definition: edns.h:35
@ LDNS_EDNS_KEY_TAG
Definition: edns.h:41
@ LDNS_EDNS_CHAIN
Definition: edns.h:40
@ LDNS_EDNS_CLIENT_TAG
Definition: edns.h:43
@ LDNS_EDNS_EDE
Definition: edns.h:42
@ LDNS_EDNS_LLQ
Definition: edns.h:28
@ LDNS_EDNS_SERVER_TAG
Definition: edns.h:44
@ LDNS_EDNS_EXPIRE
Definition: edns.h:36
@ LDNS_STATUS_WIRE_RDATA_ERR
Definition: error.h:125
@ LDNS_STATUS_NO_SVCPARAM_VALUE_EXPECTED
Definition: error.h:142
@ LDNS_STATUS_NULL
Definition: error.h:51
@ LDNS_STATUS_ERR
Definition: error.h:37
@ LDNS_STATUS_MEM_ERR
Definition: error.h:34
@ LDNS_STATUS_INVALID_SVCPARAM_VALUE
Definition: error.h:144
@ LDNS_STATUS_OK
Definition: error.h:26
@ LDNS_STATUS_DOMAINNAME_OVERFLOW
Definition: error.h:29
@ LDNS_STATUS_RDATA_OVERFLOW
Definition: error.h:129
@ LDNS_STATUS_NOT_IMPL
Definition: error.h:50
enum ldns_enum_status ldns_status
Definition: error.h:146
ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr)
Converts the data in the resource record to presentation format (as char *) and appends it to the giv...
Definition: host2str.c:2032
ldns_status ldns_rdf2buffer_str_hip(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_HIP rdata element to presentation format for the algorithm,...
Definition: host2str.c:1264
ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_WKS rdata element to string format and adds it to the output buffer.
Definition: host2str.c:817
const ldns_output_format * ldns_output_format_nocomments
Standard output format record that disables commenting in the textual representation of Resource Reco...
Definition: host2str.c:135
char * ldns_rr_class2str(const ldns_rr_class klass)
Converts an ldns_rr_class value to its string representation, and returns that string.
Definition: host2str.c:686
char * ldns_rr2str_fmt(const ldns_output_format *fmt, const ldns_rr *rr)
Converts the data in the resource record to presentation format and returns that as a char *.
Definition: host2str.c:3285
char * ldns_key2str(const ldns_key *k)
Converts a private key to the test presentation fmt and returns that as a char *.
Definition: host2str.c:3334
ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition: host2str.c:2953
ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer.
Definition: host2str.c:405
ldns_status ldns_edns_option_list2buffer_str(ldns_buffer *output, ldns_edns_option_list *edns_list)
Converts the list of EDNS options to presentation format (as char *) and appends it to the given buff...
Definition: host2str.c:2603
char * ldns_pkt2str_fmt(const ldns_output_format *fmt, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format and returns that as a char *.
Definition: host2str.c:3309
ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer.
Definition: host2str.c:530
char * ldns_pkt_rcode2str(ldns_pkt_rcode rcode)
Converts a packet rcode to its mnemonic and returns that as an allocated null-terminated string.
Definition: host2str.c:273
ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer.
Definition: host2str.c:471
ldns_status ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode)
Converts an ldns packet rcode value to its mnemonic, and adds that to the output buffer.
Definition: host2str.c:212
ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer.
Definition: host2str.c:705
ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_APL rdata element to string format and adds it to the output buffer.
Definition: host2str.c:972
char * ldns_rr_type2str(const ldns_rr_type type)
Converts an ldns_rr_type value to its string representation, and returns that string.
Definition: host2str.c:650
ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSAP rdata element to string format and adds it to the output buffer.
Definition: host2str.c:804
void ldns_rr_list_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr_list *lst)
print a rr_list to output
Definition: host2str.c:3436
ldns_lookup_table ldns_rcodes[]
Response codes.
Definition: host2str.c:109
ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer.
Definition: host2str.c:487
ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer.
Definition: host2str.c:558
ldns_status ldns_rdf2buffer_str(ldns_buffer *buffer, const ldns_rdf *rdf)
Converts the data in the rdata field to presentation format (as char *) and appends it to the given b...
Definition: host2str.c:1750
void ldns_pkt_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format)
Definition: host2str.c:3417
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
Definition: packet.c:762
char * ldns_pkt_algorithm2str(ldns_algorithm algorithm)
Converts a signing algorithms to its mnemonic and returns that as an allocated null-terminated string...
Definition: host2str.c:293
ldns_status ldns_pkt2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition: host2str.c:2683
char * ldns_rr_list2str(const ldns_rr_list *list)
Converts a list of resource records to presentation format and returns that as a char *.
Definition: host2str.c:3380
ldns_status ldns_rr2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_rr *rr)
Converts the data in the resource record to presentation format (as char *) and appends it to the giv...
Definition: host2str.c:1808
const ldns_output_format ldns_output_format_nocomments_record
Definition: host2str.c:133
void ldns_zone_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_zone *z)
Print a zone structure * to output.
Definition: host2str.c:3525
ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt)
Converts the header of a packet to presentation format and appends it to the output buffer.
Definition: host2str.c:2058
const ldns_output_format * ldns_output_format_onlykeyids
Standard output format record that annotated only DNSKEY RR's with comment text.
Definition: host2str.c:140
ldns_status ldns_rdf2buffer_str_tag(ldns_buffer *output, const ldns_rdf *rdf)
Adds the LDNS_RDF_TYPE_TAG rdata to the output buffer, provided it contains only alphanumeric charact...
Definition: host2str.c:1227
const ldns_output_format ldns_output_format_onlykeyids_record
Definition: host2str.c:136
ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list)
Converts a rr_list to presentation format and appends it to the output buffer.
Definition: host2str.c:2051
ldns_status ldns_rr_class2buffer_str(ldns_buffer *output, const ldns_rr_class klass)
Converts an ldns_rr_class value to its string representation, and places it in the given buffer.
Definition: host2str.c:671
char * ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm)
Converts a cert algorithm to its mnemonic and returns that as an allocated null-terminated string.
Definition: host2str.c:314
void ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
Prints the data in the rdata field to the given file stream (in presentation format)
Definition: host2str.c:3386
ldns_lookup_table ldns_algorithms[]
Taken from RFC 2535, section 7.
Definition: host2str.c:53
ldns_status ldns_algorithm2buffer_str(ldns_buffer *output, ldns_algorithm algorithm)
Converts an ldns algorithm type to its mnemonic, and adds that to the output buffer.
Definition: host2str.c:224
ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer.
Definition: host2str.c:413
void ldns_rr_print(FILE *output, const ldns_rr *rr)
Prints the data in the resource record to the given file stream (in presentation format)
Definition: host2str.c:3411
char * ldns_buffer_export2str(ldns_buffer *buffer)
Exports and returns the data in the buffer as a null terminated char * string.
Definition: host2str.c:3254
ldns_status svcparam_key2buffer_str(ldns_buffer *output, uint16_t key)
Definition: str2host.c:2201
ldns_status ldns_cert_algorithm2buffer_str(ldns_buffer *output, ldns_cert_algorithm cert_algorithm)
Converts an ldns certificate algorithm type to its mnemonic, and adds that to the output buffer.
Definition: host2str.c:238
char * ldns_buffer2str(ldns_buffer *buffer)
Returns a copy of the data in the buffer as a null terminated char * string.
Definition: host2str.c:3227
#define INET_ADDRSTRLEN
Definition: host2str.c:40
char * ldns_pkt2str(const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format and returns that as a char *.
Definition: host2str.c:3328
void ldns_resolver_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_resolver *r)
Print a resolver (in sofar that is possible) state to output.
Definition: host2str.c:3452
char * ldns_pkt_opcode2str(ldns_pkt_opcode opcode)
Converts a packet opcode to its mnemonic and returns that as an allocated null-terminated string.
Definition: host2str.c:253
ldns_lookup_table ldns_opcodes[]
Operation codes.
Definition: host2str.c:124
ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TSIGTIME rdata element to string format and adds it to the output buffer.
Definition: host2str.c:948
ldns_status ldns_rdf2buffer_str_eui48(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_EUI48 rdata element to 6 hexadecimal numbers separated by dashes and adds i...
Definition: host2str.c:1200
ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer.
Definition: host2str.c:389
ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer.
Definition: host2str.c:594
ldns_status ldns_rdf2buffer_str_svcparams(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_SVCPARAMS rdata element to presentation format.
Definition: host2str.c:1550
char * ldns_rr2str(const ldns_rr *rr)
Converts the data in the resource record to presentation format and returns that as a char *.
Definition: host2str.c:3303
ldns_status ldns_rdf2buffer_str_eui64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_EUI64 rdata element to 8 hexadecimal numbers separated by dashes and adds i...
Definition: host2str.c:1213
ldns_status ldns_rdf2buffer_str_amtrelay(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_AMTRELAY rdata element to presentation format for the precedence,...
Definition: host2str.c:1308
ldns_status ldns_rdf2buffer_str_ilnp64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ILNP64 rdata element to 4 hexadecimal numbers separated by colons and adds ...
Definition: host2str.c:1186
ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSEC rdata element to string format and adds it to the output buffer.
Definition: host2str.c:905
void ldns_resolver_print(FILE *output, const ldns_resolver *r)
Print a resolver (in sofar that is possible) state to output.
Definition: host2str.c:3519
ldns_status ldns_rdf2buffer_str_long_str(ldns_buffer *output, const ldns_rdf *rdf)
Adds the LDNS_RDF_TYPE_LONG_STR rdata to the output buffer, in-between double quotes and all non prin...
Definition: host2str.c:1253
ldns_status ldns_output_format_clear_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
Definition: host2str.c:180
ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer.
Definition: host2str.c:509
ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer.
Definition: host2str.c:797
void ldns_zone_print(FILE *output, const ldns_zone *z)
Print a zone structure * to output.
Definition: host2str.c:3533
ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_CERT rdata element to string format and adds it to the output buffer.
Definition: host2str.c:580
void ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
print a rr_list to output
Definition: host2str.c:3446
ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer.
Definition: host2str.c:565
ldns_lookup_table ldns_rr_classes[]
rr types
Definition: host2str.c:99
ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer.
Definition: host2str.c:397
ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_IPSECKEY rdata element to string format and adds it to the output buffer.
Definition: host2str.c:1076
ldns_status ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode)
Converts an ldns packet opcode value to its mnemonic, and adds that to the output buffer.
Definition: host2str.c:200
const ldns_output_format * ldns_output_format_default
The default output format record.
Definition: host2str.c:142
ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_PERIOD rdata element to string format and adds it to the output buffer.
Definition: host2str.c:937
void ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format)
Definition: host2str.c:3430
ldns_status ldns_rr_list2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_rr_list *list)
Converts a rr_list to presentation format and appends it to the output buffer.
Definition: host2str.c:2038
ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname)
Print the ldns_rdf containing a dname to the buffer.
Definition: host2str.c:337
ldns_lookup_table ldns_hashes[]
Definition: host2str.c:75
ldns_lookup_table ldns_cert_algorithms[]
Taken from RFC 2538.
Definition: host2str.c:84
ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer.
Definition: host2str.c:428
ldns_status ldns_output_format_set_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
Definition: host2str.c:160
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:3268
ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer.
Definition: host2str.c:912
const ldns_output_format ldns_output_format_bubblebabble_record
Definition: host2str.c:144
const ldns_output_format * ldns_output_format_bubblebabble
Standard output format record that shows all DNSKEY related information in the comment text,...
Definition: host2str.c:148
ldns_status ldns_rr_type2buffer_str(ldns_buffer *output, const ldns_rr_type type)
Converts an ldns_rr_type value to its string representation, and places it in the given buffer.
Definition: host2str.c:617
ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition: host2str.c:2817
#define INET6_ADDRSTRLEN
Definition: host2str.c:43
char * ldns_rr_list2str_fmt(const ldns_output_format *fmt, const ldns_rr_list *list)
Converts a list of resource records to presentation format and returns that as a char *.
Definition: host2str.c:3351
ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT16_DATA rdata element to string format and adds it to the output buffer.
Definition: host2str.c:1049
ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer.
Definition: host2str.c:439
ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ATMA rdata element to string format and adds it to the output buffer.
Definition: host2str.c:811
void ldns_rr_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr *rr)
Prints the data in the resource record to the given file stream (in presentation format)
Definition: host2str.c:3398
#define LDNS_COMMENT_KEY_SIZE
Show DNSKEY key size as comment.
Definition: host2str.h:54
#define LDNS_APL_IP4
Definition: host2str.h:37
#define LDNS_COMMENT_RRSIGS
Also comment KEY_ID with RRSIGS.
Definition: host2str.h:64
#define LDNS_APL_MASK
Definition: host2str.h:39
#define LDNS_FMT_PAD_SOA_SERIAL
Definition: host2str.h:66
#define LDNS_COMMENT_BUBBLEBABBLE
Provide bubblebabble representation for DS RR's as comment.
Definition: host2str.h:56
#define LDNS_FMT_ZEROIZE_RRSIGS
Definition: host2str.h:65
#define LDNS_FMT_RFC3597
Definition: host2str.h:67
#define LDNS_COMMENT_FLAGS
Show when a NSEC3 RR has the optout flag set as comment.
Definition: host2str.h:58
#define LDNS_APL_IP6
Definition: host2str.h:38
#define LDNS_COMMENT_NULLS
Represent a NULL pointer (instead of a pointer to a ldns_rr as "; (null)" as opposed to outputting no...
Definition: host2str.h:48
#define LDNS_COMMENT_KEY_ID
Show key id with DNSKEY RR's as comment.
Definition: host2str.h:50
#define LDNS_APL_NEGATION
Definition: host2str.h:40
#define LDNS_FMT_SHORT
Prints only answer section of packets and only rdata of RRs.
Definition: host2str.h:69
#define LDNS_COMMENT_KEY_TYPE
Show if a DNSKEY is a ZSK or KSK as comment.
Definition: host2str.h:52
#define LDNS_COMMENT_KEY
Show key id, type and size as comment for DNSKEY RR's.
Definition: host2str.h:74
#define LDNS_COMMENT_NSEC3_CHAIN
Show the unhashed owner and next owner names for NSEC3 RR's as comment.
Definition: host2str.h:60
unsigned char * ldns_key_hmac_key(const ldns_key *k)
return the hmac key data
Definition: keys.c:1521
size_t ldns_key_hmac_size(const ldns_key *k)
return the hmac key size
Definition: keys.c:1531
ldns_signing_algorithm ldns_key_algorithm(const ldns_key *k)
return the signing alg of the key
Definition: keys.c:1463
RSA * ldns_key_rsa_key(const ldns_key *k)
returns the (openssl) RSA struct contained in the key
Definition: keys.c:1494
DSA * ldns_key_dsa_key(const ldns_key *k)
returns the (openssl) DSA struct contained in the key
Definition: keys.c:1504
#define LDNS_KEY_SEP_KEY
Definition: keys.h:38
@ LDNS_ED448
Definition: keys.h:59
@ LDNS_RSAMD5
Definition: keys.h:46
@ LDNS_ECDSAP384SHA384
Definition: keys.h:57
@ LDNS_RSASHA1_NSEC3
Definition: keys.h:52
@ LDNS_DSA_NSEC3
Definition: keys.h:51
@ LDNS_DSA
Definition: keys.h:48
@ LDNS_ECDSAP256SHA256
Definition: keys.h:56
@ LDNS_ECC_GOST
Definition: keys.h:55
@ LDNS_PRIVATEOID
Definition: keys.h:62
@ LDNS_PRIVATEDNS
Definition: keys.h:61
@ LDNS_DH
Definition: keys.h:47
@ LDNS_INDIRECT
Definition: keys.h:60
@ LDNS_ECC
Definition: keys.h:49
@ LDNS_RSASHA1
Definition: keys.h:50
@ LDNS_RSASHA512
Definition: keys.h:54
@ LDNS_RSASHA256
Definition: keys.h:53
@ LDNS_ED25519
Definition: keys.h:58
@ LDNS_SIGN_RSASHA1
Definition: keys.h:84
@ LDNS_SIGN_ECDSAP256SHA256
Definition: keys.h:95
@ LDNS_SIGN_DSA_NSEC3
Definition: keys.h:92
@ LDNS_SIGN_ECC_GOST
Definition: keys.h:94
@ LDNS_SIGN_ED448
Definition: keys.h:101
@ LDNS_SIGN_ED25519
Definition: keys.h:98
@ LDNS_SIGN_RSASHA1_NSEC3
Definition: keys.h:88
@ LDNS_SIGN_HMACSHA224
Definition: keys.h:106
@ LDNS_SIGN_ECDSAP384SHA384
Definition: keys.h:96
@ LDNS_SIGN_HMACMD5
Definition: keys.h:103
@ LDNS_SIGN_RSAMD5
Definition: keys.h:83
@ LDNS_SIGN_RSASHA512
Definition: keys.h:90
@ LDNS_SIGN_DSA
Definition: keys.h:86
@ LDNS_SIGN_RSASHA256
Definition: keys.h:89
@ LDNS_SIGN_HMACSHA384
Definition: keys.h:107
@ LDNS_SIGN_HMACSHA1
Definition: keys.h:104
@ LDNS_SIGN_HMACSHA512
Definition: keys.h:108
@ LDNS_SIGN_HMACSHA256
Definition: keys.h:105
@ LDNS_HASH_GOST
Definition: keys.h:73
@ LDNS_SHA256
Definition: keys.h:72
@ LDNS_SHA1
Definition: keys.h:71
@ LDNS_SHA384
Definition: keys.h:74
#define LDNS_KEY_ZONE_KEY
Definition: keys.h:37
enum ldns_enum_algorithm ldns_algorithm
Definition: keys.h:64
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
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
Definition: packet.c:219
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet's answerfrom.
Definition: packet.c:195
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet's code.
Definition: packet.c:88
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
Definition: packet.c:124
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition: packet.c:40
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
Definition: packet.c:118
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet's timestamp.
Definition: packet.c:201
bool ldns_pkt_qr(const ldns_pkt *packet)
Read the packet's qr bit.
Definition: packet.c:46
bool ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
Definition: packet.c:750
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
Definition: packet.c:136
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
Definition: packet.c:106
bool ldns_pkt_cd(const ldns_pkt *packet)
Read the packet's cd bit.
Definition: packet.c:70
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
Definition: packet.c:142
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet's size in bytes.
Definition: packet.c:183
bool ldns_pkt_ad(const ldns_pkt *packet)
Read the packet's ad bit.
Definition: packet.c:82
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet's querytime.
Definition: packet.c:189
bool ldns_pkt_rd(const ldns_pkt *packet)
Read the packet's rd bit.
Definition: packet.c:64
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
Definition: packet.c:213
bool ldns_pkt_ra(const ldns_pkt *packet)
Read the packet's ra bit.
Definition: packet.c:76
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
Definition: packet.c:130
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
Definition: packet.c:112
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
Definition: packet.c:100
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
Definition: packet.c:260
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet's tsig pseudo rr's.
Definition: packet.c:465
bool ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
Definition: packet.c:231
bool ldns_pkt_aa(const ldns_pkt *packet)
Read the packet's aa bit.
Definition: packet.c:52
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
Definition: packet.c:94
bool ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
Definition: packet.c:58
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
Definition: packet.c:207
#define LDNS_MAX_PACKETLEN
Definition: packet.h:24
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition: packet.h:69
@ LDNS_PACKET_IQUERY
Definition: packet.h:48
@ LDNS_PACKET_NOTIFY
Definition: packet.h:50
@ LDNS_PACKET_QUERY
Definition: packet.h:47
@ LDNS_PACKET_STATUS
Definition: packet.h:49
@ LDNS_PACKET_UPDATE
Definition: packet.h:51
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition: packet.h:53
@ LDNS_RCODE_REFUSED
Definition: packet.h:62
@ LDNS_RCODE_YXDOMAIN
Definition: packet.h:63
@ LDNS_RCODE_FORMERR
Definition: packet.h:58
@ LDNS_RCODE_YXRRSET
Definition: packet.h:64
@ LDNS_RCODE_SERVFAIL
Definition: packet.h:59
@ LDNS_RCODE_NOTIMPL
Definition: packet.h:61
@ LDNS_RCODE_NXRRSET
Definition: packet.h:65
@ LDNS_RCODE_NOTZONE
Definition: packet.h:67
@ LDNS_RCODE_NXDOMAIN
Definition: packet.h:60
@ LDNS_RCODE_NOTAUTH
Definition: packet.h:66
@ LDNS_RCODE_NOERROR
Definition: packet.h:57
ldns_rbnode_t * ldns_rbtree_search(ldns_rbtree_t *rbtree, const void *key)
Find key in tree.
Definition: rbtree.c:294
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
Definition: rdata.c:31
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition: rdata.c:230
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
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
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition: rdata.c:24
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition: rdata.c:38
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
enum ldns_enum_cert_algorithm ldns_cert_algorithm
Definition: rdata.h:169
enum ldns_enum_svcparam_key ldns_svcparam_key
Definition: rdata.h:187
@ 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:126
@ LDNS_RDF_TYPE_NSAP
NSAP.
Definition: rdata.h:103
@ LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition: rdata.h:92
@ LDNS_RDF_TYPE_B32_EXT
b32 string
Definition: rdata.h:66
@ LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
Definition: rdata.h:111
@ LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
Definition: rdata.h:78
@ LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:119
@ LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
Definition: rdata.h:97
@ LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:121
@ LDNS_RDF_TYPE_PERIOD
period
Definition: rdata.h:86
@ LDNS_RDF_TYPE_B64
b64 string
Definition: rdata.h:68
@ LDNS_RDF_TYPE_AAAA
AAAA record.
Definition: rdata.h:60
@ LDNS_RDF_TYPE_UNKNOWN
unknown types
Definition: rdata.h:82
@ LDNS_RDF_TYPE_WKS
well known services
Definition: rdata.h:101
@ LDNS_RDF_TYPE_DNAME
domain name
Definition: rdata.h:50
@ LDNS_RDF_TYPE_TIME
time (32 bits)
Definition: rdata.h:84
@ LDNS_RDF_TYPE_SVCPARAMS
draft-ietf-dnsop-svcb-https
Definition: rdata.h:146
@ LDNS_RDF_TYPE_NSEC
nsec type codes
Definition: rdata.h:72
@ LDNS_RDF_TYPE_SELECTOR
Definition: rdata.h:139
@ LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
Definition: rdata.h:109
@ LDNS_RDF_TYPE_APL
apl data
Definition: rdata.h:64
@ LDNS_RDF_TYPE_A
A record.
Definition: rdata.h:58
@ LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5....
Definition: rdata.h:132
@ LDNS_RDF_TYPE_LOC
location data
Definition: rdata.h:99
@ 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_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition: rdata.h:116
@ LDNS_RDF_TYPE_ATMA
ATMA.
Definition: rdata.h:105
@ LDNS_RDF_TYPE_HEX
hex string
Definition: rdata.h:70
@ LDNS_RDF_TYPE_NONE
none
Definition: rdata.h:48
@ LDNS_RDF_TYPE_CLASS
a class
Definition: rdata.h:76
@ LDNS_RDF_TYPE_INT8
8 bits
Definition: rdata.h:52
@ LDNS_RDF_TYPE_MATCHING_TYPE
Definition: rdata.h:140
@ LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
Definition: rdata.h:107
@ LDNS_RDF_TYPE_CERTIFICATE_USAGE
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
Definition: rdata.h:138
@ LDNS_RDF_TYPE_STR
txt string
Definition: rdata.h:62
@ LDNS_RDF_TYPE_INT16
16 bits
Definition: rdata.h:54
@ LDNS_RDF_TYPE_ALG
a key algorithm
Definition: rdata.h:80
@ LDNS_RDF_TYPE_AMTRELAY
draft-ietf-mboned-driad-amt-discovery
Definition: rdata.h:143
@ LDNS_RDF_TYPE_TSIGTIME
tsig time 48 bits
Definition: rdata.h:88
@ LDNS_RDF_TYPE_TYPE
a RR type
Definition: rdata.h:74
@ LDNS_SVCPARAM_KEY_PORT
Definition: rdata.h:179
@ LDNS_SVCPARAM_KEY_ALPN
Definition: rdata.h:177
@ LDNS_SVCPARAM_KEY_ECH
Definition: rdata.h:181
@ LDNS_SVCPARAM_KEY_MANDATORY
Definition: rdata.h:176
@ LDNS_SVCPARAM_KEY_IPV4HINT
Definition: rdata.h:180
@ LDNS_SVCPARAM_KEY_IPV6HINT
Definition: rdata.h:182
@ LDNS_SVCPARAM_KEY_NO_DEFAULT_ALPN
Definition: rdata.h:178
@ LDNS_CERT_SPKI
Definition: rdata.h:159
@ LDNS_CERT_URI
Definition: rdata.h:166
@ LDNS_CERT_ISPKI
Definition: rdata.h:162
@ LDNS_CERT_IPGP
Definition: rdata.h:163
@ LDNS_CERT_ACPKIX
Definition: rdata.h:164
@ LDNS_CERT_IACPKIX
Definition: rdata.h:165
@ LDNS_CERT_IPKIX
Definition: rdata.h:161
@ LDNS_CERT_OID
Definition: rdata.h:167
@ LDNS_CERT_PGP
Definition: rdata.h:160
@ LDNS_CERT_PKIX
Definition: rdata.h:158
const char * ldns_resolver_tsig_algorithm(const ldns_resolver *r)
Return the tsig algorithm as used by the nameserver.
Definition: resolver.c:213
bool ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
Definition: resolver.c:120
bool ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
Definition: resolver.c:171
bool ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
Definition: resolver.c:72
size_t ldns_resolver_searchlist_count(const ldns_resolver *r)
Return the resolver's searchlist count.
Definition: resolver.c:231
ldns_rr_list * ldns_resolver_dnssec_anchors(const ldns_resolver *r)
Get the resolver's DNSSEC anchors.
Definition: resolver.c:132
size_t ldns_resolver_nameserver_count(const ldns_resolver *r)
How many nameserver are configured in the resolver.
Definition: resolver.c:114
uint8_t ldns_resolver_retrans(const ldns_resolver *r)
Get the retransmit interval.
Definition: resolver.c:48
bool ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
Definition: resolver.c:126
bool ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
Definition: resolver.c:66
bool ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
Definition: resolver.c:78
bool ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
Definition: resolver.c:165
bool ldns_resolver_defnames(const ldns_resolver *r)
Does the resolver apply default domain name.
Definition: resolver.c:90
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
Definition: resolver.c:96
uint16_t ldns_resolver_edns_udp_size(const ldns_resolver *r)
Get the resolver's udp size.
Definition: resolver.c:36
bool ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
Definition: resolver.c:225
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
Definition: resolver.c:201
size_t * ldns_resolver_rtt(const ldns_resolver *r)
Return the used round trip times for the nameservers.
Definition: resolver.c:177
bool ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
Definition: resolver.c:54
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
Definition: resolver.c:60
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
Definition: resolver.c:42
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
Definition: resolver.c:102
bool ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
Definition: resolver.c:84
const char * ldns_resolver_tsig_keyname(const ldns_resolver *r)
Return the tsig keyname as used by the nameserver.
Definition: resolver.c:207
ldns_rdf ** ldns_resolver_nameservers(const ldns_resolver *r)
Return the configured nameserver ip address.
Definition: resolver.c:108
uint16_t ldns_resolver_port(const ldns_resolver *r)
Get the port the resolver should use.
Definition: resolver.c:24
#define LDNS_RESOLV_RTT_MIN
Definition: resolver.h:54
#define LDNS_RESOLV_RTT_INF
Definition: resolver.h:53
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
Definition: rr.c:990
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition: rr.c:931
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition: rr.c:919
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition: rr.c:2632
size_t ldns_rr_rd_count(const ldns_rr *rr)
returns the rd_count of an rr structure.
Definition: rr.c:937
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
Definition: rr.c:957
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition: rr.c:943
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition: rr.c:949
bool ldns_rr_is_question(const ldns_rr *rr)
returns the question flag of an rr structure.
Definition: rr.c:925
ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf **rdf)
Create a rr type bitmap rdf providing enough space to set all known (to ldns) rr types.
Definition: rr.c:2617
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition: rr.c:909
ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf **rdf)
Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
Definition: rr.c:2623
enum ldns_enum_rr_type ldns_rr_type
Definition: rr.h:243
@ LDNS_RR_TYPE_RRSIG
DNSSEC.
Definition: rr.h:170
@ LDNS_RR_TYPE_IXFR
Definition: rr.h:215
@ LDNS_RR_TYPE_DNSKEY
Definition: rr.h:172
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
Definition: rr.h:90
@ LDNS_RR_TYPE_DS
RFC4034, RFC3658.
Definition: rr.h:164
@ LDNS_RR_TYPE_NSEC3
Definition: rr.h:176
@ LDNS_RR_TYPE_MAILA
A request for mail agent RRs (Obsolete - see MX)
Definition: rr.h:220
@ LDNS_RR_TYPE_AXFR
Definition: rr.h:216
@ LDNS_RR_TYPE_ANY
any type (wildcard)
Definition: rr.h:222
@ LDNS_RR_TYPE_MAILB
A request for mailbox-related records (MB, MG or MR)
Definition: rr.h:218
enum ldns_enum_rr_class ldns_rr_class
Definition: rr.h:61
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
Definition: rr.h:33
@ LDNS_RR_CLASS_NONE
None class, dynamic update.
Definition: rr.h:53
@ LDNS_RR_CLASS_IN
the Internet
Definition: rr.h:47
@ LDNS_RR_CLASS_CH
Chaos class.
Definition: rr.h:49
@ LDNS_RR_CLASS_HS
Hesiod (Dyer 87)
Definition: rr.h:51
@ LDNS_RR_CLASS_ANY
Any class.
Definition: rr.h:55
size_t ldns_rr_dnskey_key_size(const ldns_rr *key)
get the length of the keydata in bits
Definition: rr_functions.c:344
ldns_status ldns_str2rdf_dname(ldns_rdf **d, const char *str)
convert a dname string into wireformat
Definition: str2host.c:311
The rbnode_t struct definition.
Definition: rbtree.h:60
const void * data
pointer to data
Definition: rbtree.h:70
implementation of buffers to ease operations
Definition: buffer.h:51
size_t _position
The current position used for reading/writing.
Definition: buffer.h:53
The struct that stores an ordered EDNS option.
Definition: edns.h:97
General key structure, can contain all types of keys that are used in DNSSEC.
Definition: keys.h:122
EVP_PKEY * key
Definition: keys.h:133
struct ldns_struct_key::@0 _key
Storage pointers for the types of keys supported.
A general purpose lookup table.
Definition: util.h:156
const char * name
Definition: util.h:158
Output format struct with additional data for flags that use them.
Definition: host2str.h:103
Output format specifier.
Definition: host2str.h:89
int flags
Specification of how RR's should be formatted in text.
Definition: host2str.h:91
DNS packet.
Definition: packet.h:235
ldns_edns_option_list * _edns_list
Structed EDNS data.
Definition: packet.h:262
Resource record data field.
Definition: rdata.h:197
DNS stub resolver structure.
Definition: resolver.h:60
Contains all information about resource record types.
Definition: rr.h:351
const char * _name
Textual name of the RR type.
Definition: rr.h:355
List or Set of Resource Records.
Definition: rr.h:338
Resource Record.
Definition: rr.h:310
DNS Zone.
Definition: zone.h:43
int ldns_b32_ntop_extended_hex(const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
Definition: util.c:604
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
Definition: util.c:41
int ldns_get_bit(uint8_t bits[], size_t index)
Returns the value of the specified bit The bits are counted from left to right, so bit #0 is the left...
Definition: util.c:52
char * ldns_bubblebabble(uint8_t *data, size_t len)
Encode data as BubbleBabble.
Definition: util.c:428
struct tm * ldns_serial_arithmetics_gmtime_r(int32_t time, time_t now, struct tm *result)
The function interprets time as the number of seconds since epoch with respect to now using serial ar...
Definition: util.c:304
#define LDNS_FREE(ptr)
Definition: util.h:60
#define LDNS_XMALLOC(type, count)
Definition: util.h:51
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_list * ldns_zone_rrs(const ldns_zone *z)
Get a list of a zone's content.
Definition: zone.c:35
ldns_rr * ldns_zone_soa(const ldns_zone *z)
Return the soa record of a zone.
Definition: zone.c:17