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