ldns  1.7.0
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 #ifndef INET_ADDRSTRLEN
32 #define INET_ADDRSTRLEN 16
33 #endif
34 #ifndef INET6_ADDRSTRLEN
35 #define INET6_ADDRSTRLEN 46
36 #endif
37 
38 /* lookup tables for standard DNS stuff */
39 
40 /* Taken from RFC 2535, section 7. */
42  { LDNS_RSAMD5, "RSAMD5" },
43  { LDNS_DH, "DH" },
44  { LDNS_DSA, "DSA" },
45  { LDNS_ECC, "ECC" },
46  { LDNS_RSASHA1, "RSASHA1" },
47  { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
48  { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
49 #ifdef USE_SHA2
50  { LDNS_RSASHA256, "RSASHA256"},
51  { LDNS_RSASHA512, "RSASHA512"},
52 #endif
53 #ifdef USE_GOST
54  { LDNS_ECC_GOST, "ECC-GOST"},
55 #endif
56 #ifdef USE_ECDSA
57  { LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
58  { LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
59 #endif
60 #ifdef USE_ED25519
61  { LDNS_ED25519, "ED25519"},
62 #endif
63 #ifdef USE_ED448
64  { LDNS_ED448, "ED448"},
65 #endif
66  { LDNS_INDIRECT, "INDIRECT" },
67  { LDNS_PRIVATEDNS, "PRIVATEDNS" },
68  { LDNS_PRIVATEOID, "PRIVATEOID" },
69  { 0, NULL }
70 };
71 
72 /* Taken from RFC 4398 */
74  { LDNS_CERT_PKIX, "PKIX" },
75  { LDNS_CERT_SPKI, "SPKI" },
76  { LDNS_CERT_PGP, "PGP" },
77  { LDNS_CERT_IPKIX, "IPKIX" },
78  { LDNS_CERT_ISPKI, "ISPKI" },
79  { LDNS_CERT_IPGP, "IPGP" },
80  { LDNS_CERT_ACPKIX, "ACPKIX" },
81  { LDNS_CERT_IACPKIX, "IACPKIX" },
82  { LDNS_CERT_URI, "URI" },
83  { LDNS_CERT_OID, "OID" },
84  { 0, NULL }
85 };
86 
87 /* classes */
89  { LDNS_RR_CLASS_IN, "IN" },
90  { LDNS_RR_CLASS_CH, "CH" },
91  { LDNS_RR_CLASS_HS, "HS" },
92  { LDNS_RR_CLASS_NONE, "NONE" },
93  { LDNS_RR_CLASS_ANY, "ANY" },
94  { 0, NULL }
95 };
96 
97 /* if these are used elsewhere */
99  { LDNS_RCODE_NOERROR, "NOERROR" },
100  { LDNS_RCODE_FORMERR, "FORMERR" },
101  { LDNS_RCODE_SERVFAIL, "SERVFAIL" },
102  { LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
103  { LDNS_RCODE_NOTIMPL, "NOTIMPL" },
104  { LDNS_RCODE_REFUSED, "REFUSED" },
105  { LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
106  { LDNS_RCODE_YXRRSET, "YXRRSET" },
107  { LDNS_RCODE_NXRRSET, "NXRRSET" },
108  { LDNS_RCODE_NOTAUTH, "NOTAUTH" },
109  { LDNS_RCODE_NOTZONE, "NOTZONE" },
110  { 0, NULL }
111 };
112 
114  { LDNS_PACKET_QUERY, "QUERY" },
115  { LDNS_PACKET_IQUERY, "IQUERY" },
116  { LDNS_PACKET_STATUS, "STATUS" },
117  { LDNS_PACKET_NOTIFY, "NOTIFY" },
118  { LDNS_PACKET_UPDATE, "UPDATE" },
119  { 0, NULL }
120 };
121 
126  LDNS_COMMENT_KEY, NULL
127 };
132 
135 };
138 
139 static bool
140 ldns_output_format_covers_type(const ldns_output_format* fmt, ldns_rr_type t)
141 {
142  return fmt && (fmt->flags & LDNS_FMT_RFC3597) &&
143  ((ldns_output_format_storage*)fmt)->bitmap &&
145  ((ldns_output_format_storage*)fmt)->bitmap, t);
146 }
147 
150 {
152  ldns_status s;
153 
154  assert(fmt != NULL);
155 
156  if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
157  ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
158  }
159  if (! fmt_st->bitmap) {
161  if (s != LDNS_STATUS_OK) {
162  return s;
163  }
164  }
165  return ldns_nsec_bitmap_set_type(fmt_st->bitmap, t);
166 }
167 
170 {
172  ldns_status s;
173 
174  assert(fmt != NULL);
175 
176  if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
177  ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
178  }
179  if (! fmt_st->bitmap) {
181  if (s != LDNS_STATUS_OK) {
182  return s;
183  }
184  }
185  return ldns_nsec_bitmap_clear_type(fmt_st->bitmap, t);
186 }
187 
190 {
191  ldns_lookup_table *lt = ldns_lookup_by_id(ldns_opcodes, opcode);
192  if (lt && lt->name) {
193  ldns_buffer_printf(output, "%s", lt->name);
194  } else {
195  ldns_buffer_printf(output, "OPCODE%u", opcode);
196  }
197  return ldns_buffer_status(output);
198 }
199 
202 {
203  ldns_lookup_table *lt = ldns_lookup_by_id(ldns_rcodes, rcode);
204  if (lt && lt->name) {
205  ldns_buffer_printf(output, "%s", lt->name);
206  } else {
207  ldns_buffer_printf(output, "RCODE%u", rcode);
208  }
209  return ldns_buffer_status(output);
210 }
211 
214  ldns_algorithm algorithm)
215 {
216  ldns_lookup_table *lt = ldns_lookup_by_id(ldns_algorithms,
217  algorithm);
218  if (lt && lt->name) {
219  ldns_buffer_printf(output, "%s", lt->name);
220  } else {
221  ldns_buffer_printf(output, "ALG%u", algorithm);
222  }
223  return ldns_buffer_status(output);
224 }
225 
228  ldns_cert_algorithm cert_algorithm)
229 {
230  ldns_lookup_table *lt = ldns_lookup_by_id(ldns_cert_algorithms,
231  cert_algorithm);
232  if (lt && lt->name) {
233  ldns_buffer_printf(output, "%s", lt->name);
234  } else {
235  ldns_buffer_printf(output, "CERT_ALG%u",
236  cert_algorithm);
237  }
238  return ldns_buffer_status(output);
239 }
240 
241 char *
243 {
244  char *str;
245  ldns_buffer *buf;
246 
247  buf = ldns_buffer_new(12);
248  if (!buf) {
249  return NULL;
250  }
251 
252  str = NULL;
253  if (ldns_pkt_opcode2buffer_str(buf, opcode) == LDNS_STATUS_OK) {
254  str = ldns_buffer_export2str(buf);
255  }
256 
257  ldns_buffer_free(buf);
258  return str;
259 }
260 
261 char *
263 {
264  char *str;
265  ldns_buffer *buf;
266 
267  buf = ldns_buffer_new(10);
268  if (!buf) {
269  return NULL;
270  }
271 
272  str = NULL;
273  if (ldns_pkt_rcode2buffer_str(buf, rcode) == LDNS_STATUS_OK) {
274  str = ldns_buffer_export2str(buf);
275  }
276 
277  ldns_buffer_free(buf);
278  return str;
279 }
280 
281 char *
283 {
284  char *str;
285  ldns_buffer *buf;
286 
287  buf = ldns_buffer_new(10);
288  if (!buf) {
289  return NULL;
290  }
291 
292  str = NULL;
293  if (ldns_algorithm2buffer_str(buf, algorithm)
294  == LDNS_STATUS_OK) {
295  str = ldns_buffer_export2str(buf);
296  }
297 
298  ldns_buffer_free(buf);
299  return str;
300 }
301 
302 char *
304 {
305  char *str;
306  ldns_buffer *buf;
307 
308  buf = ldns_buffer_new(10);
309  if (!buf) {
310  return NULL;
311  }
312 
313  str = NULL;
314  if (ldns_cert_algorithm2buffer_str(buf, cert_algorithm)
315  == LDNS_STATUS_OK) {
316  str = ldns_buffer_export2str(buf);
317  }
318 
319  ldns_buffer_free(buf);
320  return str;
321 }
322 
323 
324 /* do NOT pass compressed data here :p */
327 {
328  /* can we do with 1 pos var? or without at all? */
329  uint8_t src_pos = 0;
330  uint8_t len;
331  uint8_t *data;
332  uint8_t i;
333  unsigned char c;
334 
335  data = (uint8_t*)ldns_rdf_data(dname);
336  len = data[src_pos];
337 
338  if (ldns_rdf_size(dname) > LDNS_MAX_DOMAINLEN) {
339  /* too large, return */
341  }
342 
343  /* special case: root label */
344  if (1 == ldns_rdf_size(dname)) {
345  ldns_buffer_printf(output, ".");
346  } else {
347  while ((len > 0) && src_pos < ldns_rdf_size(dname)) {
348  src_pos++;
349  for(i = 0; i < len; i++) {
350  /* paranoia check for various 'strange'
351  characters in dnames
352  */
353  c = (unsigned char) data[src_pos];
354  if(c == '.' || c == ';' ||
355  c == '(' || c == ')' ||
356  c == '\\') {
357  ldns_buffer_printf(output, "\\%c",
358  data[src_pos]);
359  } else if (!(isascii(c) && isgraph(c))) {
360  ldns_buffer_printf(output, "\\%03u",
361  data[src_pos]);
362  } else {
363  ldns_buffer_printf(output, "%c", data[src_pos]);
364  }
365  src_pos++;
366  }
367 
368  if (src_pos < ldns_rdf_size(dname)) {
369  ldns_buffer_printf(output, ".");
370  }
371  len = data[src_pos];
372  }
373  }
374  return ldns_buffer_status(output);
375 }
376 
379 {
380  uint8_t data = ldns_rdf_data(rdf)[0];
381  ldns_buffer_printf(output, "%lu", (unsigned long) data);
382  return ldns_buffer_status(output);
383 }
384 
387 {
388  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
389  ldns_buffer_printf(output, "%lu", (unsigned long) data);
390  return ldns_buffer_status(output);
391 }
392 
395 {
396  uint32_t data = ldns_read_uint32(ldns_rdf_data(rdf));
397  ldns_buffer_printf(output, "%lu", (unsigned long) data);
398  return ldns_buffer_status(output);
399 }
400 
403 {
404  /* create a YYYYMMDDHHMMSS string if possible */
405  struct tm tm;
406  char date_buf[16];
407 
408  memset(&tm, 0, sizeof(tm));
410  && strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) {
411  ldns_buffer_printf(output, "%s", date_buf);
412  }
413  return ldns_buffer_status(output);
414 }
415 
418 {
419  char str[INET_ADDRSTRLEN];
420 
421  if (inet_ntop(AF_INET, ldns_rdf_data(rdf), str, INET_ADDRSTRLEN)) {
422  ldns_buffer_printf(output, "%s", str);
423  }
424  return ldns_buffer_status(output);
425 }
426 
429 {
430  char str[INET6_ADDRSTRLEN];
431 
432  if (inet_ntop(AF_INET6, ldns_rdf_data(rdf), str, INET6_ADDRSTRLEN)) {
433  ldns_buffer_printf(output, "%s", str);
434  }
435 
436  return ldns_buffer_status(output);
437 }
438 
439 static void
440 ldns_characters2buffer_str(ldns_buffer* output,
441  size_t amount, const uint8_t* characters)
442 {
443  uint8_t ch;
444  while (amount > 0) {
445  ch = *characters++;
446  if (isprint((int)ch) || ch == '\t') {
447  if (ch == '\"' || ch == '\\')
448  ldns_buffer_printf(output, "\\%c", ch);
449  else
450  ldns_buffer_printf(output, "%c", ch);
451  } else {
452  ldns_buffer_printf(output, "\\%03u",
453  (unsigned)(uint8_t) ch);
454  }
455  amount--;
456  }
457 }
458 
461 {
462  if(ldns_rdf_size(rdf) < 1) {
464  }
465  if((int)ldns_rdf_size(rdf) < (int)ldns_rdf_data(rdf)[0] + 1) {
467  }
468  ldns_buffer_printf(output, "\"");
469  ldns_characters2buffer_str(output,
470  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf) + 1);
471  ldns_buffer_printf(output, "\"");
472  return ldns_buffer_status(output);
473 }
474 
477 {
478  size_t size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf));
479  char *b64 = LDNS_XMALLOC(char, size);
480  if(!b64) return LDNS_STATUS_MEM_ERR;
481  if (ldns_b64_ntop(ldns_rdf_data(rdf), ldns_rdf_size(rdf), b64, size)) {
482  ldns_buffer_printf(output, "%s", b64);
483  }
484  LDNS_FREE(b64);
485  return ldns_buffer_status(output);
486 }
487 
490 {
491  size_t size;
492  char *b32;
493  if(ldns_rdf_size(rdf) == 0)
494  return LDNS_STATUS_OK;
495  /* remove -1 for the b32-hash-len octet */
496  size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
497  /* add one for the end nul for the string */
498  b32 = LDNS_XMALLOC(char, size + 1);
499  if(!b32) return LDNS_STATUS_MEM_ERR;
500  size = (size_t) ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1,
501  ldns_rdf_size(rdf) - 1, b32, size+1);
502  if (size > 0) {
503  ldns_buffer_printf(output, "%s", b32);
504  }
505  LDNS_FREE(b32);
506  return ldns_buffer_status(output);
507 }
508 
511 {
512  size_t i;
513  for (i = 0; i < ldns_rdf_size(rdf); i++) {
514  ldns_buffer_printf(output, "%02x", ldns_rdf_data(rdf)[i]);
515  }
516 
517  return ldns_buffer_status(output);
518 }
519 
520 static ldns_status
521 ldns_rdf2buffer_str_type_fmt(ldns_buffer *output,
522  const ldns_output_format* fmt, const ldns_rdf *rdf)
523 {
524  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
525 
526  if (! ldns_output_format_covers_type(fmt, data) &&
527  ldns_rr_descript(data) &&
528  ldns_rr_descript(data)->_name) {
529 
530  ldns_buffer_printf(output, "%s",ldns_rr_descript(data)->_name);
531  } else {
532  ldns_buffer_printf(output, "TYPE%u", data);
533  }
534  return ldns_buffer_status(output);
535 }
536 
539 {
540  return ldns_rdf2buffer_str_type_fmt(output,
542 }
543 
546 {
547  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
548  ldns_lookup_table *lt;
549 
550  lt = ldns_lookup_by_id(ldns_rr_classes, (int) data);
551  if (lt) {
552  ldns_buffer_printf(output, "\t%s", lt->name);
553  } else {
554  ldns_buffer_printf(output, "\tCLASS%d", data);
555  }
556  return ldns_buffer_status(output);
557 }
558 
561 {
562  uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
563  ldns_lookup_table *lt;
564  lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data);
565  if (lt) {
566  ldns_buffer_printf(output, "%s", lt->name);
567  } else {
568  ldns_buffer_printf(output, "%d", data);
569  }
570  return ldns_buffer_status(output);
571 }
572 
575 {
576  return ldns_rdf2buffer_str_int8(output, rdf);
577 }
578 
579 static void
580 loc_cm_print(ldns_buffer *output, uint8_t mantissa, uint8_t exponent)
581 {
582  uint8_t i;
583  /* is it 0.<two digits> ? */
584  if(exponent < 2) {
585  if(exponent == 1)
586  mantissa *= 10;
587  ldns_buffer_printf(output, "0.%02ld", (long)mantissa);
588  return;
589  }
590  /* always <digit><string of zeros> */
591  ldns_buffer_printf(output, "%d", (int)mantissa);
592  for(i=0; i<exponent-2; i++)
593  ldns_buffer_printf(output, "0");
594 }
595 
598 {
599  const ldns_rr_descriptor *descriptor;
600 
601  descriptor = ldns_rr_descript(type);
602 
603  switch (type) {
604  case LDNS_RR_TYPE_IXFR:
605  ldns_buffer_printf(output, "IXFR");
606  break;
607  case LDNS_RR_TYPE_AXFR:
608  ldns_buffer_printf(output, "AXFR");
609  break;
610  case LDNS_RR_TYPE_MAILA:
611  ldns_buffer_printf(output, "MAILA");
612  break;
613  case LDNS_RR_TYPE_MAILB:
614  ldns_buffer_printf(output, "MAILB");
615  break;
616  case LDNS_RR_TYPE_ANY:
617  ldns_buffer_printf(output, "ANY");
618  break;
619  default:
620  if (descriptor && descriptor->_name) {
621  ldns_buffer_printf(output, "%s", descriptor->_name);
622  } else {
623  ldns_buffer_printf(output, "TYPE%u", type);
624  }
625  }
626  return ldns_buffer_status(output);
627 }
628 
629 char *
631 {
632  char *str;
633  ldns_buffer *buf;
634 
635  buf = ldns_buffer_new(10);
636  if (!buf) {
637  return NULL;
638  }
639 
640  str = NULL;
641  if (ldns_rr_type2buffer_str(buf, type) == LDNS_STATUS_OK) {
642  str = ldns_buffer_export2str(buf);
643  }
644 
645  ldns_buffer_free(buf);
646  return str;
647 }
648 
649 
652  const ldns_rr_class klass)
653 {
654  ldns_lookup_table *lt;
655 
656  lt = ldns_lookup_by_id(ldns_rr_classes, klass);
657  if (lt) {
658  ldns_buffer_printf(output, "%s", lt->name);
659  } else {
660  ldns_buffer_printf(output, "CLASS%d", klass);
661  }
662  return ldns_buffer_status(output);
663 }
664 
665 char *
667 {
668  ldns_buffer *buf;
669  char *str;
670 
671  buf = ldns_buffer_new(10);
672  if (!buf) {
673  return NULL;
674  }
675 
676  str = NULL;
677  if (ldns_rr_class2buffer_str(buf, klass) == LDNS_STATUS_OK) {
678  str = ldns_buffer_export2str(buf);
679  }
680  ldns_buffer_free(buf);
681  return str;
682 }
683 
686 {
687  /* we could do checking (ie degrees < 90 etc)? */
688  uint8_t version;
689  uint8_t size;
690  uint8_t horizontal_precision;
691  uint8_t vertical_precision;
692  uint32_t longitude;
693  uint32_t latitude;
694  uint32_t altitude;
695  char northerness;
696  char easterness;
697  uint32_t h;
698  uint32_t m;
699  double s;
700 
701  uint32_t equator = (uint32_t) ldns_power(2, 31);
702 
703  if(ldns_rdf_size(rdf) < 1) {
705  }
706  version = ldns_rdf_data(rdf)[0];
707  if (version == 0) {
708  if(ldns_rdf_size(rdf) < 16) {
710  }
711  size = ldns_rdf_data(rdf)[1];
712  horizontal_precision = ldns_rdf_data(rdf)[2];
713  vertical_precision = ldns_rdf_data(rdf)[3];
714 
715  latitude = ldns_read_uint32(&ldns_rdf_data(rdf)[4]);
716  longitude = ldns_read_uint32(&ldns_rdf_data(rdf)[8]);
717  altitude = ldns_read_uint32(&ldns_rdf_data(rdf)[12]);
718 
719  if (latitude > equator) {
720  northerness = 'N';
721  latitude = latitude - equator;
722  } else {
723  northerness = 'S';
724  latitude = equator - latitude;
725  }
726  h = latitude / (1000 * 60 * 60);
727  latitude = latitude % (1000 * 60 * 60);
728  m = latitude / (1000 * 60);
729  latitude = latitude % (1000 * 60);
730  s = (double) latitude / 1000.0;
731  ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
732  h, m, s, northerness);
733 
734  if (longitude > equator) {
735  easterness = 'E';
736  longitude = longitude - equator;
737  } else {
738  easterness = 'W';
739  longitude = equator - longitude;
740  }
741  h = longitude / (1000 * 60 * 60);
742  longitude = longitude % (1000 * 60 * 60);
743  m = longitude / (1000 * 60);
744  longitude = longitude % (1000 * 60);
745  s = (double) longitude / (1000.0);
746  ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
747  h, m, s, easterness);
748 
749 
750  s = ((double) altitude) / 100;
751  s -= 100000;
752 
753  if(altitude%100 != 0)
754  ldns_buffer_printf(output, "%.2f", s);
755  else
756  ldns_buffer_printf(output, "%.0f", s);
757 
758  ldns_buffer_printf(output, "m ");
759 
760  loc_cm_print(output, (size & 0xf0) >> 4, size & 0x0f);
761  ldns_buffer_printf(output, "m ");
762 
763  loc_cm_print(output, (horizontal_precision & 0xf0) >> 4,
764  horizontal_precision & 0x0f);
765  ldns_buffer_printf(output, "m ");
766 
767  loc_cm_print(output, (vertical_precision & 0xf0) >> 4,
768  vertical_precision & 0x0f);
769  ldns_buffer_printf(output, "m");
770 
771  return ldns_buffer_status(output);
772  } else {
773  return ldns_rdf2buffer_str_hex(output, rdf);
774  }
775 }
776 
779 {
780  ldns_buffer_printf(output, "\\# %u ", ldns_rdf_size(rdf));
781  return ldns_rdf2buffer_str_hex(output, rdf);
782 }
783 
786 {
787  ldns_buffer_printf(output, "0x");
788  return ldns_rdf2buffer_str_hex(output, rdf);
789 }
790 
793 {
794  return ldns_rdf2buffer_str_hex(output, rdf);
795 }
796 
799 {
800  /* protocol, followed by bitmap of services */
801  struct protoent *protocol;
802  char *proto_name = NULL;
803  uint8_t protocol_nr;
804  struct servent *service;
805  uint16_t current_service;
806 
807  if(ldns_rdf_size(rdf) < 1) {
809  }
810  protocol_nr = ldns_rdf_data(rdf)[0];
811  protocol = getprotobynumber((int) protocol_nr);
812  if (protocol && (protocol->p_name != NULL)) {
813  proto_name = protocol->p_name;
814  ldns_buffer_printf(output, "%s ", protocol->p_name);
815  } else {
816  ldns_buffer_printf(output, "%u ", protocol_nr);
817  }
818 
819 #ifdef HAVE_ENDPROTOENT
820  endprotoent();
821 #endif
822 
823  for (current_service = 0;
824  current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) {
825  if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) {
826  service = getservbyport((int) htons(current_service),
827  proto_name);
828  if (service && service->s_name) {
829  ldns_buffer_printf(output, "%s ", service->s_name);
830  } else {
831  ldns_buffer_printf(output, "%u ", current_service);
832  }
833 #ifdef HAVE_ENDSERVENT
834  endservent();
835 #endif
836  }
837  }
838  return ldns_buffer_status(output);
839 }
840 
841 static ldns_status
842 ldns_rdf2buffer_str_nsec_fmt(ldns_buffer *output,
843  const ldns_output_format* fmt, const ldns_rdf *rdf)
844 {
845  /* Note: this code is duplicated in higher.c in
846  * ldns_nsec_type_check() function
847  */
848  uint8_t window_block_nr;
849  uint8_t bitmap_length;
850  uint16_t type;
851  uint16_t pos = 0;
852  uint16_t bit_pos;
853  uint8_t *data = ldns_rdf_data(rdf);
854 
855  while((size_t)(pos + 2) < ldns_rdf_size(rdf)) {
856  window_block_nr = data[pos];
857  bitmap_length = data[pos + 1];
858  pos += 2;
859  if (ldns_rdf_size(rdf) < pos + bitmap_length) {
861  }
862  for (bit_pos = 0; bit_pos < (bitmap_length) * 8; bit_pos++) {
863  if (! ldns_get_bit(&data[pos], bit_pos)) {
864  continue;
865  }
866  type = 256 * (uint16_t) window_block_nr + bit_pos;
867 
868  if (! ldns_output_format_covers_type(fmt, type) &&
869  ldns_rr_descript(type) &&
870  ldns_rr_descript(type)->_name){
871 
872  ldns_buffer_printf(output, "%s ",
873  ldns_rr_descript(type)->_name);
874  } else {
875  ldns_buffer_printf(output, "TYPE%u ", type);
876  }
877  }
878  pos += (uint16_t) bitmap_length;
879  }
880  return ldns_buffer_status(output);
881 }
882 
885 {
886  return ldns_rdf2buffer_str_nsec_fmt(output,
888 }
889 
892 {
893  uint8_t salt_length;
894  uint8_t salt_pos;
895 
896  uint8_t *data = ldns_rdf_data(rdf);
897 
898  if(ldns_rdf_size(rdf) < 1) {
900  }
901  salt_length = data[0];
902  /* from now there are variable length entries so remember pos */
903  if (salt_length == 0 || ((size_t)salt_length)+1 > ldns_rdf_size(rdf)) {
904  ldns_buffer_printf(output, "- ");
905  } else {
906  for (salt_pos = 0; salt_pos < salt_length; salt_pos++) {
907  ldns_buffer_printf(output, "%02x", data[1 + salt_pos]);
908  }
909  ldns_buffer_printf(output, " ");
910  }
911 
912  return ldns_buffer_status(output);
913 }
914 
917 {
918  /* period is the number of seconds */
919  if (ldns_rdf_size(rdf) != 4) {
921  }
922  ldns_buffer_printf(output, "%u", ldns_read_uint32(ldns_rdf_data(rdf)));
923  return ldns_buffer_status(output);
924 }
925 
928 {
929  /* tsigtime is 48 bits network order unsigned integer */
930  uint64_t tsigtime = 0;
931  uint8_t *data = ldns_rdf_data(rdf);
932  uint64_t d0, d1, d2, d3, d4, d5;
933 
934  if (ldns_rdf_size(rdf) < 6) {
936  }
937  d0 = data[0]; /* cast to uint64 for shift operations */
938  d1 = data[1];
939  d2 = data[2];
940  d3 = data[3];
941  d4 = data[4];
942  d5 = data[5];
943  tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5;
944 
945  ldns_buffer_printf(output, "%llu ", (long long)tsigtime);
946 
947  return ldns_buffer_status(output);
948 }
949 
952 {
953  uint8_t *data = ldns_rdf_data(rdf);
954  uint16_t address_family;
955  uint8_t prefix;
956  bool negation;
957  uint8_t adf_length;
958  size_t i;
959  size_t pos = 0;
960 
961  while (pos < (unsigned int) ldns_rdf_size(rdf)) {
962  if(pos + 3 >= (unsigned)ldns_rdf_size(rdf))
964  address_family = ldns_read_uint16(&data[pos]);
965  prefix = data[pos + 2];
966  negation = data[pos + 3] & LDNS_APL_NEGATION;
967  adf_length = data[pos + 3] & LDNS_APL_MASK;
968  if (address_family == LDNS_APL_IP4) {
969  /* check if prefix < 32? */
970  if (negation) {
971  ldns_buffer_printf(output, "!");
972  }
973  ldns_buffer_printf(output, "%u:", address_family);
974  /* address is variable length 0 - 4 */
975  for (i = 0; i < 4; i++) {
976  if (i > 0) {
977  ldns_buffer_printf(output, ".");
978  }
979  if (i < (unsigned short) adf_length) {
980  if(pos+i+4 >= ldns_rdf_size(rdf))
982  ldns_buffer_printf(output, "%d",
983  data[pos + i + 4]);
984  } else {
985  ldns_buffer_printf(output, "0");
986  }
987  }
988  ldns_buffer_printf(output, "/%u ", prefix);
989  } else if (address_family == LDNS_APL_IP6) {
990  /* check if prefix < 128? */
991  if (negation) {
992  ldns_buffer_printf(output, "!");
993  }
994  ldns_buffer_printf(output, "%u:", address_family);
995  /* address is variable length 0 - 16 */
996  for (i = 0; i < 16; i++) {
997  if (i % 2 == 0 && i > 0) {
998  ldns_buffer_printf(output, ":");
999  }
1000  if (i < (unsigned short) adf_length) {
1001  if(pos+i+4 >= ldns_rdf_size(rdf))
1003  ldns_buffer_printf(output, "%02x",
1004  data[pos + i + 4]);
1005  } else {
1006  ldns_buffer_printf(output, "00");
1007  }
1008  }
1009  ldns_buffer_printf(output, "/%u ", prefix);
1010 
1011  } else {
1012  /* unknown address family */
1013  ldns_buffer_printf(output,
1014  "Unknown address family: %u data: ",
1015  address_family);
1016  for (i = 1; i < (unsigned short) (4 + adf_length); i++) {
1017  if(pos+i >= ldns_rdf_size(rdf))
1019  ldns_buffer_printf(output, "%02x", data[i]);
1020  }
1021  }
1022  pos += 4 + adf_length;
1023  }
1024  return ldns_buffer_status(output);
1025 }
1026 
1029 {
1030  size_t size;
1031  char *b64;
1032  if (ldns_rdf_size(rdf) < 2) {
1034  }
1035  /* Subtract the size (2) of the number that specifies the length */
1036  size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf) - 2);
1037  ldns_buffer_printf(output, "%u ", ldns_rdf_size(rdf) - 2);
1038  if (ldns_rdf_size(rdf) > 2) {
1039  b64 = LDNS_XMALLOC(char, size);
1040  if(!b64)
1041  return LDNS_STATUS_MEM_ERR;
1042 
1043  if (ldns_rdf_size(rdf) > 2 &&
1044  ldns_b64_ntop(ldns_rdf_data(rdf) + 2,
1045  ldns_rdf_size(rdf) - 2,
1046  b64, size)) {
1047  ldns_buffer_printf(output, "%s", b64);
1048  }
1049  LDNS_FREE(b64);
1050  }
1051  return ldns_buffer_status(output);
1052 }
1053 
1056 {
1057  /* wire format from
1058  http://www.ietf.org/internet-drafts/draft-ietf-ipseckey-rr-12.txt
1059  */
1060  uint8_t *data = ldns_rdf_data(rdf);
1061  uint8_t precedence;
1062  uint8_t gateway_type;
1063  uint8_t algorithm;
1064 
1065  ldns_rdf *gateway = NULL;
1066  uint8_t *gateway_data;
1067 
1068  size_t public_key_size;
1069  uint8_t *public_key_data;
1070  ldns_rdf *public_key;
1071 
1072  size_t offset = 0;
1073  ldns_status status;
1074 
1075  if (ldns_rdf_size(rdf) < 3) {
1077  }
1078  precedence = data[0];
1079  gateway_type = data[1];
1080  algorithm = data[2];
1081  offset = 3;
1082 
1083  switch (gateway_type) {
1084  case 0:
1085  /* no gateway */
1086  break;
1087  case 1:
1088  gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN);
1089  if(!gateway_data)
1090  return LDNS_STATUS_MEM_ERR;
1091  if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) {
1092  return LDNS_STATUS_ERR;
1093  }
1094  memcpy(gateway_data, &data[offset], LDNS_IP4ADDRLEN);
1095  gateway = ldns_rdf_new(LDNS_RDF_TYPE_A,
1096  LDNS_IP4ADDRLEN , gateway_data);
1097  offset += LDNS_IP4ADDRLEN;
1098  if(!gateway) {
1099  LDNS_FREE(gateway_data);
1100  return LDNS_STATUS_MEM_ERR;
1101  }
1102  break;
1103  case 2:
1104  gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN);
1105  if(!gateway_data)
1106  return LDNS_STATUS_MEM_ERR;
1107  if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) {
1108  return LDNS_STATUS_ERR;
1109  }
1110  memcpy(gateway_data, &data[offset], LDNS_IP6ADDRLEN);
1111  offset += LDNS_IP6ADDRLEN;
1112  gateway =
1114  LDNS_IP6ADDRLEN, gateway_data);
1115  if(!gateway) {
1116  LDNS_FREE(gateway_data);
1117  return LDNS_STATUS_MEM_ERR;
1118  }
1119  break;
1120  case 3:
1121  status = ldns_wire2dname(&gateway, data,
1122  ldns_rdf_size(rdf), &offset);
1123  if(status != LDNS_STATUS_OK)
1124  return status;
1125  break;
1126  default:
1127  /* error? */
1128  break;
1129  }
1130 
1131  if (ldns_rdf_size(rdf) <= offset) {
1132  return LDNS_STATUS_ERR;
1133  }
1134  public_key_size = ldns_rdf_size(rdf) - offset;
1135  public_key_data = LDNS_XMALLOC(uint8_t, public_key_size);
1136  if(!public_key_data) {
1137  ldns_rdf_deep_free(gateway);
1138  return LDNS_STATUS_MEM_ERR;
1139  }
1140  memcpy(public_key_data, &data[offset], public_key_size);
1141  public_key = ldns_rdf_new(LDNS_RDF_TYPE_B64,
1142  public_key_size, public_key_data);
1143  if(!public_key) {
1144  LDNS_FREE(public_key_data);
1145  ldns_rdf_deep_free(gateway);
1146  return LDNS_STATUS_MEM_ERR;
1147  }
1148 
1149  ldns_buffer_printf(output, "%u %u %u ", precedence, gateway_type, algorithm);
1150  if (gateway)
1151  (void) ldns_rdf2buffer_str(output, gateway);
1152  else
1153  ldns_buffer_printf(output, ".");
1154  ldns_buffer_printf(output, " ");
1155  (void) ldns_rdf2buffer_str(output, public_key);
1156 
1157  ldns_rdf_deep_free(gateway);
1158  ldns_rdf_deep_free(public_key);
1159 
1160  return ldns_buffer_status(output);
1161 }
1162 
1165 {
1166  if (ldns_rdf_size(rdf) != 8) {
1168  }
1169  ldns_buffer_printf(output,"%.4x:%.4x:%.4x:%.4x",
1170  ldns_read_uint16(ldns_rdf_data(rdf)),
1171  ldns_read_uint16(ldns_rdf_data(rdf)+2),
1172  ldns_read_uint16(ldns_rdf_data(rdf)+4),
1173  ldns_read_uint16(ldns_rdf_data(rdf)+6));
1174  return ldns_buffer_status(output);
1175 }
1176 
1179 {
1180  if (ldns_rdf_size(rdf) != 6) {
1182  }
1183  ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1184  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1185  ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1186  ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5]);
1187  return ldns_buffer_status(output);
1188 }
1189 
1192 {
1193  if (ldns_rdf_size(rdf) != 8) {
1195  }
1196  ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1197  ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1198  ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1199  ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5],
1200  ldns_rdf_data(rdf)[6], ldns_rdf_data(rdf)[7]);
1201  return ldns_buffer_status(output);
1202 }
1203 
1206 {
1207  size_t nchars;
1208  const uint8_t* chars;
1209  char ch;
1210  if (ldns_rdf_size(rdf) < 2) {
1212  }
1213  nchars = ldns_rdf_data(rdf)[0];
1214  if (nchars >= ldns_rdf_size(rdf) || /* should be rdf_size - 1 */
1215  nchars < 1) {
1217  }
1218  chars = ldns_rdf_data(rdf) + 1;
1219  while (nchars > 0) {
1220  ch = (char)*chars++;
1221  if (! isalnum((unsigned char)ch)) {
1223  }
1224  ldns_buffer_printf(output, "%c", ch);
1225  nchars--;
1226  }
1227  return ldns_buffer_status(output);
1228 }
1229 
1232 {
1233 
1234  ldns_buffer_printf(output, "\"");
1235  ldns_characters2buffer_str(output,
1236  ldns_rdf_size(rdf), ldns_rdf_data(rdf));
1237  ldns_buffer_printf(output, "\"");
1238  return ldns_buffer_status(output);
1239 }
1240 
1243 {
1244  uint8_t *data = ldns_rdf_data(rdf);
1245  size_t rdf_size = ldns_rdf_size(rdf);
1246  uint8_t hit_size;
1247  uint16_t pk_size;
1248  int written;
1249 
1250  if (rdf_size < 6) {
1252  }
1253  if ((hit_size = data[0]) == 0 ||
1254  (pk_size = ldns_read_uint16(data + 2)) == 0 ||
1255  rdf_size < (size_t) hit_size + pk_size + 4) {
1256 
1258  }
1259 
1260  ldns_buffer_printf(output, "%d ", (int) data[1]);
1261 
1262  for (data += 4; hit_size > 0; hit_size--, data++) {
1263 
1264  ldns_buffer_printf(output, "%02x", (int) *data);
1265  }
1266  ldns_buffer_write_u8(output, (uint8_t) ' ');
1267 
1268  if (ldns_buffer_reserve(output,
1269  ldns_b64_ntop_calculate_size(pk_size))) {
1270 
1271  written = ldns_b64_ntop(data, pk_size,
1272  (char *) ldns_buffer_current(output),
1273  ldns_buffer_remaining(output));
1274 
1275  if (written > 0 &&
1276  written < (int) ldns_buffer_remaining(output)) {
1277 
1278  output->_position += written;
1279  }
1280  }
1281  return ldns_buffer_status(output);
1282 }
1283 
1284 static ldns_status
1285 ldns_rdf2buffer_str_fmt(ldns_buffer *buffer,
1286  const ldns_output_format* fmt, const ldns_rdf *rdf)
1287 {
1289 
1290  /*ldns_buffer_printf(buffer, "%u:", ldns_rdf_get_type(rdf));*/
1291  if (rdf) {
1292  switch(ldns_rdf_get_type(rdf)) {
1293  case LDNS_RDF_TYPE_NONE:
1294  break;
1295  case LDNS_RDF_TYPE_DNAME:
1296  res = ldns_rdf2buffer_str_dname(buffer, rdf);
1297  break;
1298  case LDNS_RDF_TYPE_INT8: /* Don't output mnemonics for these */
1299  case LDNS_RDF_TYPE_ALG:
1303  res = ldns_rdf2buffer_str_int8(buffer, rdf);
1304  break;
1305  case LDNS_RDF_TYPE_INT16:
1306  res = ldns_rdf2buffer_str_int16(buffer, rdf);
1307  break;
1308  case LDNS_RDF_TYPE_INT32:
1309  res = ldns_rdf2buffer_str_int32(buffer, rdf);
1310  break;
1311  case LDNS_RDF_TYPE_PERIOD:
1312  res = ldns_rdf2buffer_str_period(buffer, rdf);
1313  break;
1315  res = ldns_rdf2buffer_str_tsigtime(buffer, rdf);
1316  break;
1317  case LDNS_RDF_TYPE_A:
1318  res = ldns_rdf2buffer_str_a(buffer, rdf);
1319  break;
1320  case LDNS_RDF_TYPE_AAAA:
1321  res = ldns_rdf2buffer_str_aaaa(buffer, rdf);
1322  break;
1323  case LDNS_RDF_TYPE_STR:
1324  res = ldns_rdf2buffer_str_str(buffer, rdf);
1325  break;
1326  case LDNS_RDF_TYPE_APL:
1327  res = ldns_rdf2buffer_str_apl(buffer, rdf);
1328  break;
1329  case LDNS_RDF_TYPE_B32_EXT:
1330  res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1331  break;
1332  case LDNS_RDF_TYPE_B64:
1333  res = ldns_rdf2buffer_str_b64(buffer, rdf);
1334  break;
1335  case LDNS_RDF_TYPE_HEX:
1336  res = ldns_rdf2buffer_str_hex(buffer, rdf);
1337  break;
1338  case LDNS_RDF_TYPE_NSEC:
1339  res = ldns_rdf2buffer_str_nsec_fmt(buffer, fmt, rdf);
1340  break;
1342  res = ldns_rdf2buffer_str_nsec3_salt(buffer, rdf);
1343  break;
1344  case LDNS_RDF_TYPE_TYPE:
1345  res = ldns_rdf2buffer_str_type_fmt(buffer, fmt, rdf);
1346  break;
1347  case LDNS_RDF_TYPE_CLASS:
1348  res = ldns_rdf2buffer_str_class(buffer, rdf);
1349  break;
1351  res = ldns_rdf2buffer_str_cert_alg(buffer, rdf);
1352  break;
1353  case LDNS_RDF_TYPE_UNKNOWN:
1354  res = ldns_rdf2buffer_str_unknown(buffer, rdf);
1355  break;
1356  case LDNS_RDF_TYPE_TIME:
1357  res = ldns_rdf2buffer_str_time(buffer, rdf);
1358  break;
1359  case LDNS_RDF_TYPE_HIP:
1360  res = ldns_rdf2buffer_str_hip(buffer, rdf);
1361  break;
1362  case LDNS_RDF_TYPE_LOC:
1363  res = ldns_rdf2buffer_str_loc(buffer, rdf);
1364  break;
1365  case LDNS_RDF_TYPE_WKS:
1366  case LDNS_RDF_TYPE_SERVICE:
1367  res = ldns_rdf2buffer_str_wks(buffer, rdf);
1368  break;
1369  case LDNS_RDF_TYPE_NSAP:
1370  res = ldns_rdf2buffer_str_nsap(buffer, rdf);
1371  break;
1372  case LDNS_RDF_TYPE_ATMA:
1373  res = ldns_rdf2buffer_str_atma(buffer, rdf);
1374  break;
1376  res = ldns_rdf2buffer_str_ipseckey(buffer, rdf);
1377  break;
1379  res = ldns_rdf2buffer_str_int16_data(buffer, rdf);
1380  break;
1382  res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1383  break;
1384  case LDNS_RDF_TYPE_ILNP64:
1385  res = ldns_rdf2buffer_str_ilnp64(buffer, rdf);
1386  break;
1387  case LDNS_RDF_TYPE_EUI48:
1388  res = ldns_rdf2buffer_str_eui48(buffer, rdf);
1389  break;
1390  case LDNS_RDF_TYPE_EUI64:
1391  res = ldns_rdf2buffer_str_eui64(buffer, rdf);
1392  break;
1393  case LDNS_RDF_TYPE_TAG:
1394  res = ldns_rdf2buffer_str_tag(buffer, rdf);
1395  break;
1397  res = ldns_rdf2buffer_str_long_str(buffer, rdf);
1398  break;
1399  }
1400  } else {
1402  ldns_buffer_printf(buffer, "(null) ");
1403  res = LDNS_STATUS_ERR;
1404  }
1405  return res;
1406 }
1407 
1410 {
1411  return ldns_rdf2buffer_str_fmt(buffer,ldns_output_format_default,rdf);
1412 }
1413 
1414 static ldns_rdf *
1415 ldns_b32_ext2dname(const ldns_rdf *rdf)
1416 {
1417  size_t size;
1418  char *b32;
1419  ldns_rdf *out;
1420  if(ldns_rdf_size(rdf) == 0)
1421  return NULL;
1422  /* remove -1 for the b32-hash-len octet */
1423  size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
1424  /* add one for the end nul for the string */
1425  b32 = LDNS_XMALLOC(char, size + 2);
1426  if (b32) {
1428  ldns_rdf_size(rdf) - 1, b32, size+1) > 0) {
1429  b32[size] = '.';
1430  b32[size+1] = '\0';
1431  if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) {
1432  LDNS_FREE(b32);
1433  return out;
1434  }
1435  }
1436  LDNS_FREE(b32);
1437  }
1438  return NULL;
1439 }
1440 
1441 static ldns_status
1442 ldns_rr2buffer_str_rfc3597(ldns_buffer *output, const ldns_rr *rr)
1443 {
1444  size_t total_rdfsize = 0;
1445  size_t i, j;
1446 
1447  ldns_buffer_printf(output, "TYPE%u\t", ldns_rr_get_type(rr));
1448  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1449  total_rdfsize += ldns_rdf_size(ldns_rr_rdf(rr, i));
1450  }
1451  if (total_rdfsize == 0) {
1452  ldns_buffer_printf(output, "\\# 0\n");
1453  return ldns_buffer_status(output);
1454  }
1455  ldns_buffer_printf(output, "\\# %d ", total_rdfsize);
1456  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1457  for (j = 0; j < ldns_rdf_size(ldns_rr_rdf(rr, i)); j++) {
1458  ldns_buffer_printf(output, "%.2x",
1459  ldns_rdf_data(ldns_rr_rdf(rr, i))[j]);
1460  }
1461  }
1462  ldns_buffer_printf(output, "\n");
1463  return ldns_buffer_status(output);
1464 }
1465 
1468  const ldns_output_format *fmt, const ldns_rr *rr)
1469 {
1470  uint16_t i, flags;
1471  ldns_status status = LDNS_STATUS_OK;
1473 
1474  if (fmt_st == NULL) {
1475  fmt_st = (ldns_output_format_storage*)
1477  }
1478  if (!rr) {
1479  if (LDNS_COMMENT_NULLS & fmt_st->flags) {
1480  ldns_buffer_printf(output, "; (null)\n");
1481  }
1482  return ldns_buffer_status(output);
1483  }
1484  if (ldns_rr_owner(rr)) {
1485  status = ldns_rdf2buffer_str_dname(output, ldns_rr_owner(rr));
1486  }
1487  if (status != LDNS_STATUS_OK) {
1488  return status;
1489  }
1490 
1491  /* TTL should NOT be printed if it is a question */
1492  if (!ldns_rr_is_question(rr)) {
1493  ldns_buffer_printf(output, "\t%d", ldns_rr_ttl(rr));
1494  }
1495 
1496  ldns_buffer_printf(output, "\t");
1497  status = ldns_rr_class2buffer_str(output, ldns_rr_get_class(rr));
1498  if (status != LDNS_STATUS_OK) {
1499  return status;
1500  }
1501  ldns_buffer_printf(output, "\t");
1502 
1503  if (ldns_output_format_covers_type(fmt, ldns_rr_get_type(rr))) {
1504  return ldns_rr2buffer_str_rfc3597(output, rr);
1505  }
1506  status = ldns_rr_type2buffer_str(output, ldns_rr_get_type(rr));
1507  if (status != LDNS_STATUS_OK) {
1508  return status;
1509  }
1510 
1511  if (ldns_rr_rd_count(rr) > 0) {
1512  ldns_buffer_printf(output, "\t");
1513  } else if (!ldns_rr_is_question(rr)) {
1514  ldns_buffer_printf(output, "\t\\# 0");
1515  }
1516 
1517  for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1518  /* ldns_rdf2buffer_str handles NULL input fine! */
1519  if ((fmt_st->flags & LDNS_FMT_ZEROIZE_RRSIGS) &&
1521  ((/* inception */ i == 4 &&
1522  ldns_rdf_get_type(ldns_rr_rdf(rr, 4)) ==
1523  LDNS_RDF_TYPE_TIME) ||
1524  (/* expiration */ i == 5 &&
1525  ldns_rdf_get_type(ldns_rr_rdf(rr, 5)) ==
1526  LDNS_RDF_TYPE_TIME) ||
1527  (/* signature */ i == 8 &&
1528  ldns_rdf_get_type(ldns_rr_rdf(rr, 8)) ==
1529  LDNS_RDF_TYPE_B64))) {
1530 
1531  ldns_buffer_printf(output, "(null)");
1532  status = ldns_buffer_status(output);
1533  } else if ((fmt_st->flags & LDNS_FMT_PAD_SOA_SERIAL) &&
1535  /* serial */ i == 2 &&
1536  ldns_rdf_get_type(ldns_rr_rdf(rr, 2)) ==
1538  ldns_buffer_printf(output, "%10lu",
1539  (unsigned long) ldns_read_uint32(
1540  ldns_rdf_data(ldns_rr_rdf(rr, 2))));
1541  status = ldns_buffer_status(output);
1542  } else {
1543  status = ldns_rdf2buffer_str_fmt(output,
1544  fmt, ldns_rr_rdf(rr, i));
1545  }
1546  if(status != LDNS_STATUS_OK)
1547  return status;
1548  if (i < ldns_rr_rd_count(rr) - 1) {
1549  ldns_buffer_printf(output, " ");
1550  }
1551  }
1552  /* per RR special comments - handy for DNSSEC types */
1553  /* check to prevent question sec. rr from
1554  * getting here */
1555  if (ldns_rr_rd_count(rr) > 0) {
1556  switch (ldns_rr_get_type(rr)) {
1557  case LDNS_RR_TYPE_DNSKEY:
1558  /* if ldns_rr_rd_count(rr) > 0
1559  then ldns_rr_rdf(rr, 0) exists! */
1560  if (! (fmt_st->flags & LDNS_COMMENT_KEY)) {
1561  break;
1562  }
1563  flags = ldns_rdf2native_int16(ldns_rr_rdf(rr, 0));
1564  ldns_buffer_printf(output, " ;{");
1565  if (fmt_st->flags & LDNS_COMMENT_KEY_ID) {
1566  ldns_buffer_printf(output, "id = %u",
1567  (unsigned int) ldns_calc_keytag(rr));
1568  }
1569  if ((fmt_st->flags & LDNS_COMMENT_KEY_TYPE) &&
1570  (flags & LDNS_KEY_ZONE_KEY)){
1571 
1572  if (flags & LDNS_KEY_SEP_KEY) {
1573  ldns_buffer_printf(output, " (ksk)");
1574  } else {
1575  ldns_buffer_printf(output, " (zsk)");
1576  }
1577  if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE){
1578  ldns_buffer_printf(output, ", ");
1579  }
1580  } else if (fmt_st->flags
1583  ldns_buffer_printf( output, ", ");
1584  }
1585  if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE) {
1586  ldns_buffer_printf(output, "size = %db",
1588  }
1589  ldns_buffer_printf(output, "}");
1590  break;
1591  case LDNS_RR_TYPE_RRSIG:
1592  if ((fmt_st->flags & LDNS_COMMENT_KEY)
1593  && (fmt_st->flags& LDNS_COMMENT_RRSIGS)
1594  && ldns_rr_rdf(rr, 6) != NULL) {
1595  ldns_buffer_printf(output, " ;{id = %d}",
1597  ldns_rr_rdf(rr, 6)));
1598  }
1599  break;
1600  case LDNS_RR_TYPE_DS:
1601  if ((fmt_st->flags & LDNS_COMMENT_BUBBLEBABBLE) &&
1602  ldns_rr_rdf(rr, 3) != NULL) {
1603 
1604  uint8_t *data = ldns_rdf_data(
1605  ldns_rr_rdf(rr, 3));
1606  size_t len = ldns_rdf_size(ldns_rr_rdf(rr, 3));
1607  char *babble = ldns_bubblebabble(data, len);
1608  if(babble) {
1609  ldns_buffer_printf(output,
1610  " ;{%s}", babble);
1611  }
1612  LDNS_FREE(babble);
1613  }
1614  break;
1615  case LDNS_RR_TYPE_NSEC3:
1616  if (! (fmt_st->flags & LDNS_COMMENT_FLAGS) &&
1617  ! (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN)) {
1618  break;
1619  }
1620  ldns_buffer_printf(output, " ;{");
1621  if ((fmt_st->flags & LDNS_COMMENT_FLAGS)) {
1622  if (ldns_nsec3_optout(rr)) {
1623  ldns_buffer_printf(output,
1624  " flags: optout");
1625  } else {
1626  ldns_buffer_printf(output," flags: -");
1627  }
1628  if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1629  fmt_st->hashmap != NULL) {
1630  ldns_buffer_printf(output, ", ");
1631  }
1632  }
1633  if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1634  fmt_st->hashmap != NULL) {
1635  ldns_rbnode_t *node;
1636  ldns_rdf *key = ldns_dname_label(
1637  ldns_rr_owner(rr), 0);
1638  if (key) {
1639  node = ldns_rbtree_search(
1640  fmt_st->hashmap,
1641  (void *) key);
1642  if (node->data) {
1643  ldns_buffer_printf(output,
1644  "from: ");
1645  (void) ldns_rdf2buffer_str(
1646  output,
1648  (ldns_dnssec_name*)
1649  node->data
1650  ));
1651  }
1652  ldns_rdf_free(key);
1653  }
1654  key = ldns_b32_ext2dname(
1655  ldns_nsec3_next_owner(rr));
1656  if (key) {
1657  node = ldns_rbtree_search(
1658  fmt_st->hashmap,
1659  (void *) key);
1660  if (node->data) {
1661  ldns_buffer_printf(output,
1662  " to: ");
1663  (void) ldns_rdf2buffer_str(
1664  output,
1666  (ldns_dnssec_name*)
1667  node->data
1668  ));
1669  }
1670  ldns_rdf_free(key);
1671  }
1672  }
1673  ldns_buffer_printf(output, "}");
1674  break;
1675  default:
1676  break;
1677 
1678  }
1679  }
1680  /* last */
1681  ldns_buffer_printf(output, "\n");
1682  return ldns_buffer_status(output);
1683 }
1684 
1687 {
1689 }
1690 
1693  const ldns_output_format *fmt, const ldns_rr_list *list)
1694 {
1695  uint16_t i;
1696 
1697  for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
1698  (void) ldns_rr2buffer_str_fmt(output, fmt,
1699  ldns_rr_list_rr(list, i));
1700  }
1701  return ldns_buffer_status(output);
1702 }
1703 
1706 {
1708  output, ldns_output_format_default, list);
1709 }
1710 
1713 {
1714  ldns_lookup_table *opcode = ldns_lookup_by_id(ldns_opcodes,
1715  (int) ldns_pkt_get_opcode(pkt));
1716  ldns_lookup_table *rcode = ldns_lookup_by_id(ldns_rcodes,
1717  (int) ldns_pkt_get_rcode(pkt));
1718 
1719  ldns_buffer_printf(output, ";; ->>HEADER<<- ");
1720  if (opcode) {
1721  ldns_buffer_printf(output, "opcode: %s, ", opcode->name);
1722  } else {
1723  ldns_buffer_printf(output, "opcode: ?? (%u), ",
1724  ldns_pkt_get_opcode(pkt));
1725  }
1726  if (rcode) {
1727  ldns_buffer_printf(output, "rcode: %s, ", rcode->name);
1728  } else {
1729  ldns_buffer_printf(output, "rcode: ?? (%u), ", ldns_pkt_get_rcode(pkt));
1730  }
1731  ldns_buffer_printf(output, "id: %d\n", ldns_pkt_id(pkt));
1732  ldns_buffer_printf(output, ";; flags: ");
1733 
1734  if (ldns_pkt_qr(pkt)) {
1735  ldns_buffer_printf(output, "qr ");
1736  }
1737  if (ldns_pkt_aa(pkt)) {
1738  ldns_buffer_printf(output, "aa ");
1739  }
1740  if (ldns_pkt_tc(pkt)) {
1741  ldns_buffer_printf(output, "tc ");
1742  }
1743  if (ldns_pkt_rd(pkt)) {
1744  ldns_buffer_printf(output, "rd ");
1745  }
1746  if (ldns_pkt_cd(pkt)) {
1747  ldns_buffer_printf(output, "cd ");
1748  }
1749  if (ldns_pkt_ra(pkt)) {
1750  ldns_buffer_printf(output, "ra ");
1751  }
1752  if (ldns_pkt_ad(pkt)) {
1753  ldns_buffer_printf(output, "ad ");
1754  }
1755  ldns_buffer_printf(output, "; ");
1756  ldns_buffer_printf(output, "QUERY: %u, ", ldns_pkt_qdcount(pkt));
1757  ldns_buffer_printf(output, "ANSWER: %u, ", ldns_pkt_ancount(pkt));
1758  ldns_buffer_printf(output, "AUTHORITY: %u, ", ldns_pkt_nscount(pkt));
1759  ldns_buffer_printf(output, "ADDITIONAL: %u ", ldns_pkt_arcount(pkt));
1760  return ldns_buffer_status(output);
1761 }
1762 
1765  const ldns_output_format *fmt, const ldns_pkt *pkt)
1766 {
1767  uint16_t i;
1768  ldns_status status = LDNS_STATUS_OK;
1769  char *tmp;
1770  struct timeval time;
1771  time_t time_tt;
1772 
1773  if (!pkt) {
1774  ldns_buffer_printf(output, "null");
1775  return LDNS_STATUS_OK;
1776  }
1777 
1778  if (ldns_buffer_status_ok(output)) {
1779  status = ldns_pktheader2buffer_str(output, pkt);
1780  if (status != LDNS_STATUS_OK) {
1781  return status;
1782  }
1783 
1784  ldns_buffer_printf(output, "\n");
1785 
1786  ldns_buffer_printf(output, ";; QUESTION SECTION:\n;; ");
1787 
1788 
1789  for (i = 0; i < ldns_pkt_qdcount(pkt); i++) {
1790  status = ldns_rr2buffer_str_fmt(output, fmt,
1792  ldns_pkt_question(pkt), i));
1793  if (status != LDNS_STATUS_OK) {
1794  return status;
1795  }
1796  }
1797  ldns_buffer_printf(output, "\n");
1798 
1799  ldns_buffer_printf(output, ";; ANSWER SECTION:\n");
1800  for (i = 0; i < ldns_pkt_ancount(pkt); i++) {
1801  status = ldns_rr2buffer_str_fmt(output, fmt,
1803  ldns_pkt_answer(pkt), i));
1804  if (status != LDNS_STATUS_OK) {
1805  return status;
1806  }
1807 
1808  }
1809  ldns_buffer_printf(output, "\n");
1810 
1811  ldns_buffer_printf(output, ";; AUTHORITY SECTION:\n");
1812 
1813  for (i = 0; i < ldns_pkt_nscount(pkt); i++) {
1814  status = ldns_rr2buffer_str_fmt(output, fmt,
1816  ldns_pkt_authority(pkt), i));
1817  if (status != LDNS_STATUS_OK) {
1818  return status;
1819  }
1820  }
1821  ldns_buffer_printf(output, "\n");
1822 
1823  ldns_buffer_printf(output, ";; ADDITIONAL SECTION:\n");
1824  for (i = 0; i < ldns_pkt_arcount(pkt); i++) {
1825  status = ldns_rr2buffer_str_fmt(output, fmt,
1827  ldns_pkt_additional(pkt), i));
1828  if (status != LDNS_STATUS_OK) {
1829  return status;
1830  }
1831 
1832  }
1833  ldns_buffer_printf(output, "\n");
1834  /* add some futher fields */
1835  ldns_buffer_printf(output, ";; Query time: %d msec\n",
1836  ldns_pkt_querytime(pkt));
1837  if (ldns_pkt_edns(pkt)) {
1838  ldns_buffer_printf(output,
1839  ";; EDNS: version %u; flags:",
1840  ldns_pkt_edns_version(pkt));
1841  if (ldns_pkt_edns_do(pkt)) {
1842  ldns_buffer_printf(output, " do");
1843  }
1844  /* the extended rcode is the value set, shifted four bits,
1845  * and or'd with the original rcode */
1846  if (ldns_pkt_edns_extended_rcode(pkt)) {
1847  ldns_buffer_printf(output, " ; ext-rcode: %d",
1849  }
1850  ldns_buffer_printf(output, " ; udp: %u\n",
1851  ldns_pkt_edns_udp_size(pkt));
1852 
1853  if (ldns_pkt_edns_data(pkt)) {
1854  ldns_buffer_printf(output, ";; Data: ");
1855  (void)ldns_rdf2buffer_str(output,
1856  ldns_pkt_edns_data(pkt));
1857  ldns_buffer_printf(output, "\n");
1858  }
1859  }
1860  if (ldns_pkt_tsig(pkt)) {
1861  ldns_buffer_printf(output, ";; TSIG:\n;; ");
1862  (void) ldns_rr2buffer_str_fmt(
1863  output, fmt, ldns_pkt_tsig(pkt));
1864  ldns_buffer_printf(output, "\n");
1865  }
1866  if (ldns_pkt_answerfrom(pkt)) {
1867  tmp = ldns_rdf2str(ldns_pkt_answerfrom(pkt));
1868  ldns_buffer_printf(output, ";; SERVER: %s\n", tmp);
1869  LDNS_FREE(tmp);
1870  }
1871  time = ldns_pkt_timestamp(pkt);
1872  time_tt = (time_t)time.tv_sec;
1873  ldns_buffer_printf(output, ";; WHEN: %s",
1874  (char*)ctime(&time_tt));
1875 
1876  ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n",
1877  (int)ldns_pkt_size(pkt));
1878  } else {
1879  return ldns_buffer_status(output);
1880  }
1881  return status;
1882 }
1883 
1886 {
1888 }
1889 
1890 
1891 #ifdef HAVE_SSL
1892 static ldns_status
1893 ldns_hmac_key2buffer_str(ldns_buffer *output, const ldns_key *k)
1894 {
1895  ldns_status status;
1896  size_t i;
1897  ldns_rdf *b64_bignum;
1898 
1899  ldns_buffer_printf(output, "Key: ");
1900 
1901  i = ldns_key_hmac_size(k);
1903  status = ldns_rdf2buffer_str(output, b64_bignum);
1904  ldns_rdf_deep_free(b64_bignum);
1905  ldns_buffer_printf(output, "\n");
1906  return status;
1907 }
1908 #endif
1909 
1910 #if defined(HAVE_SSL) && defined(USE_GOST)
1911 static ldns_status
1912 ldns_gost_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
1913 {
1914  unsigned char* pp = NULL;
1915  int ret;
1916  ldns_rdf *b64_bignum;
1917  ldns_status status;
1918 
1919  ldns_buffer_printf(output, "GostAsn1: ");
1920 
1921  ret = i2d_PrivateKey(p, &pp);
1922  b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)ret, pp);
1923  status = ldns_rdf2buffer_str(output, b64_bignum);
1924 
1925  ldns_rdf_deep_free(b64_bignum);
1926  OPENSSL_free(pp);
1927  ldns_buffer_printf(output, "\n");
1928  return status;
1929 }
1930 #endif
1931 
1933 static int
1934 ldns_print_bignum_b64_line(ldns_buffer* output, const char* label, const BIGNUM* num)
1935 {
1936  unsigned char *bignumbuf = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
1937  if(!bignumbuf) return 0;
1938 
1939  ldns_buffer_printf(output, "%s: ", label);
1940  if(num) {
1941  ldns_rdf *b64_bignum = NULL;
1942  int i = BN_bn2bin(num, bignumbuf);
1943  if (i > LDNS_MAX_KEYLEN) {
1944  LDNS_FREE(bignumbuf);
1945  return 0;
1946  }
1947  b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)i, bignumbuf);
1948  if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) {
1949  ldns_rdf_deep_free(b64_bignum);
1950  LDNS_FREE(bignumbuf);
1951  return 0;
1952  }
1953  ldns_rdf_deep_free(b64_bignum);
1954  ldns_buffer_printf(output, "\n");
1955  } else {
1956  ldns_buffer_printf(output, "(Not available)\n");
1957  }
1958  LDNS_FREE(bignumbuf);
1959  return 1;
1960 }
1961 
1964 {
1965  ldns_status status = LDNS_STATUS_OK;
1966  unsigned char *bignum;
1967 #ifdef HAVE_SSL
1968  RSA *rsa;
1969  DSA *dsa;
1970 #endif /* HAVE_SSL */
1971 
1972  if (!k) {
1973  return LDNS_STATUS_ERR;
1974  }
1975 
1976  bignum = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
1977  if (!bignum) {
1978  return LDNS_STATUS_ERR;
1979  }
1980 
1981  if (ldns_buffer_status_ok(output)) {
1982 #ifdef HAVE_SSL
1983  switch(ldns_key_algorithm(k)) {
1984  case LDNS_SIGN_RSASHA1:
1986  case LDNS_SIGN_RSASHA256:
1987  case LDNS_SIGN_RSASHA512:
1988  case LDNS_SIGN_RSAMD5:
1989  /* copied by looking at dnssec-keygen output */
1990  /* header */
1991  rsa = ldns_key_rsa_key(k);
1992 
1993  ldns_buffer_printf(output,"Private-key-format: v1.2\n");
1994  switch(ldns_key_algorithm(k)) {
1995  case LDNS_SIGN_RSAMD5:
1996  ldns_buffer_printf(output,
1997  "Algorithm: %u (RSA)\n",
1998  LDNS_RSAMD5);
1999  break;
2000  case LDNS_SIGN_RSASHA1:
2001  ldns_buffer_printf(output,
2002  "Algorithm: %u (RSASHA1)\n",
2003  LDNS_RSASHA1);
2004  break;
2006  ldns_buffer_printf(output,
2007  "Algorithm: %u (RSASHA1_NSEC3)\n",
2009  break;
2010 #ifdef USE_SHA2
2011  case LDNS_SIGN_RSASHA256:
2012  ldns_buffer_printf(output,
2013  "Algorithm: %u (RSASHA256)\n",
2014  LDNS_RSASHA256);
2015  break;
2016  case LDNS_SIGN_RSASHA512:
2017  ldns_buffer_printf(output,
2018  "Algorithm: %u (RSASHA512)\n",
2019  LDNS_RSASHA512);
2020  break;
2021 #endif
2022  default:
2023 #ifdef STDERR_MSGS
2024  fprintf(stderr, "Warning: unknown signature ");
2025  fprintf(stderr,
2026  "algorithm type %u\n",
2027  ldns_key_algorithm(k));
2028 #endif
2029  ldns_buffer_printf(output,
2030  "Algorithm: %u (Unknown)\n",
2031  ldns_key_algorithm(k));
2032  break;
2033  }
2034 
2035  /* print to buf, convert to bin, convert to b64,
2036  * print to buf */
2037 
2038 #ifndef S_SPLINT_S
2039  if(1) {
2040  const BIGNUM *n=NULL, *e=NULL, *d=NULL,
2041  *p=NULL, *q=NULL, *dmp1=NULL,
2042  *dmq1=NULL, *iqmp=NULL;
2043 #if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
2044  n = rsa->n;
2045  e = rsa->e;
2046  d = rsa->d;
2047  p = rsa->p;
2048  q = rsa->q;
2049  dmp1 = rsa->dmp1;
2050  dmq1 = rsa->dmq1;
2051  iqmp = rsa->iqmp;
2052 #else
2053  RSA_get0_key(rsa, &n, &e, &d);
2054  RSA_get0_factors(rsa, &p, &q);
2055  RSA_get0_crt_params(rsa, &dmp1,
2056  &dmq1, &iqmp);
2057 #endif
2058  if(!ldns_print_bignum_b64_line(output, "Modulus", n))
2059  goto error;
2060  if(!ldns_print_bignum_b64_line(output, "PublicExponent", e))
2061  goto error;
2062  if(!ldns_print_bignum_b64_line(output, "PrivateExponent", d))
2063  goto error;
2064  if(!ldns_print_bignum_b64_line(output, "Prime1", p))
2065  goto error;
2066  if(!ldns_print_bignum_b64_line(output, "Prime2", q))
2067  goto error;
2068  if(!ldns_print_bignum_b64_line(output, "Exponent1", dmp1))
2069  goto error;
2070  if(!ldns_print_bignum_b64_line(output, "Exponent2", dmq1))
2071  goto error;
2072  if(!ldns_print_bignum_b64_line(output, "Coefficient", iqmp))
2073  goto error;
2074  }
2075 #endif /* splint */
2076 
2077  RSA_free(rsa);
2078  break;
2079  case LDNS_SIGN_DSA:
2080  case LDNS_SIGN_DSA_NSEC3:
2081  dsa = ldns_key_dsa_key(k);
2082 
2083  ldns_buffer_printf(output,"Private-key-format: v1.2\n");
2084  if (ldns_key_algorithm(k) == LDNS_SIGN_DSA) {
2085  ldns_buffer_printf(output,"Algorithm: 3 (DSA)\n");
2086  } else if (ldns_key_algorithm(k) == LDNS_SIGN_DSA_NSEC3) {
2087  ldns_buffer_printf(output,"Algorithm: 6 (DSA_NSEC3)\n");
2088  }
2089 
2090  /* print to buf, convert to bin, convert to b64,
2091  * print to buf */
2092  if(1) {
2093  const BIGNUM *p=NULL, *q=NULL, *g=NULL,
2094  *priv_key=NULL, *pub_key=NULL;
2095 #if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
2096 #ifndef S_SPLINT_S
2097  p = dsa->p;
2098  q = dsa->q;
2099  g = dsa->g;
2100  priv_key = dsa->priv_key;
2101  pub_key = dsa->pub_key;
2102 #endif /* splint */
2103 #else
2104  DSA_get0_pqg(dsa, &p, &q, &g);
2105  DSA_get0_key(dsa, &pub_key, &priv_key);
2106 #endif
2107  if(!ldns_print_bignum_b64_line(output, "Prime(p)", p))
2108  goto error;
2109  if(!ldns_print_bignum_b64_line(output, "Subprime(q)", q))
2110  goto error;
2111  if(!ldns_print_bignum_b64_line(output, "Base(g)", g))
2112  goto error;
2113  if(!ldns_print_bignum_b64_line(output, "Private_value(x)", priv_key))
2114  goto error;
2115  if(!ldns_print_bignum_b64_line(output, "Public_value(y)", pub_key))
2116  goto error;
2117  }
2118  break;
2119  case LDNS_SIGN_ECC_GOST:
2120  /* no format defined, use blob */
2121 #if defined(HAVE_SSL) && defined(USE_GOST)
2122  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2123  ldns_buffer_printf(output, "Algorithm: %d (ECC-GOST)\n", LDNS_SIGN_ECC_GOST);
2124  status = ldns_gost_key2buffer_str(output,
2125 #ifndef S_SPLINT_S
2126  k->_key.key
2127 #else
2128  NULL
2129 #endif
2130  );
2131 #else
2132  goto error;
2133 #endif /* GOST */
2134  break;
2137 #ifdef USE_ECDSA
2138  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2139  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2141 #ifndef S_SPLINT_S
2142  ldns_buffer_printf(output, ")\n");
2143  if(k->_key.key) {
2144  EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
2145  const BIGNUM* b = EC_KEY_get0_private_key(ec);
2146  if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
2147  goto error;
2148  /* down reference count in EC_KEY
2149  * its still assigned to the PKEY */
2150  EC_KEY_free(ec);
2151  }
2152 #endif /* splint */
2153 #else
2154  goto error;
2155 #endif /* ECDSA */
2156  break;
2157 #ifdef USE_ED25519
2158  case LDNS_SIGN_ED25519:
2159  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2160  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2162  ldns_buffer_printf(output, ")\n");
2163  if(k->_key.key) {
2164  EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
2165  const BIGNUM* b = EC_KEY_get0_private_key(ec);
2166  if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
2167  goto error;
2168  /* down reference count in EC_KEY
2169  * its still assigned to the PKEY */
2170  EC_KEY_free(ec);
2171  }
2172  ldns_buffer_printf(output, "\n");
2173  break;
2174 #endif /* USE_ED25519 */
2175 #ifdef USE_ED448
2176  case LDNS_SIGN_ED448:
2177  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2178  ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2180  ldns_buffer_printf(output, ")\n");
2181  if(k->_key.key) {
2182  EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
2183  const BIGNUM* b = EC_KEY_get0_private_key(ec);
2184  if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
2185  goto error;
2186  /* down reference count in EC_KEY
2187  * its still assigned to the PKEY */
2188  EC_KEY_free(ec);
2189  }
2190  ldns_buffer_printf(output, "\n");
2191  break;
2192 #endif /* USE_ED448 */
2193  case LDNS_SIGN_HMACMD5:
2194  /* there's not much of a format defined for TSIG */
2195  /* It's just a binary blob, Same for all algorithms */
2196  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2197  ldns_buffer_printf(output, "Algorithm: 157 (HMAC_MD5)\n");
2198  status = ldns_hmac_key2buffer_str(output, k);
2199  break;
2200  case LDNS_SIGN_HMACSHA1:
2201  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2202  ldns_buffer_printf(output, "Algorithm: 158 (HMAC_SHA1)\n");
2203  status = ldns_hmac_key2buffer_str(output, k);
2204  break;
2205  case LDNS_SIGN_HMACSHA224:
2206  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2207  ldns_buffer_printf(output, "Algorithm: 162 (HMAC_SHA224)\n");
2208  status = ldns_hmac_key2buffer_str(output, k);
2209  break;
2210  case LDNS_SIGN_HMACSHA256:
2211  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2212  ldns_buffer_printf(output, "Algorithm: 159 (HMAC_SHA256)\n");
2213  status = ldns_hmac_key2buffer_str(output, k);
2214  break;
2215  case LDNS_SIGN_HMACSHA384:
2216  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2217  ldns_buffer_printf(output, "Algorithm: 164 (HMAC_SHA384)\n");
2218  status = ldns_hmac_key2buffer_str(output, k);
2219  break;
2220  case LDNS_SIGN_HMACSHA512:
2221  ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2222  ldns_buffer_printf(output, "Algorithm: 165 (HMAC_SHA512)\n");
2223  status = ldns_hmac_key2buffer_str(output, k);
2224  break;
2225  }
2226 #endif /* HAVE_SSL */
2227  } else {
2228  LDNS_FREE(bignum);
2229  return ldns_buffer_status(output);
2230  }
2231  LDNS_FREE(bignum);
2232  return status;
2233 
2234 #ifdef HAVE_SSL
2235  /* compiles warn the label isn't used */
2236 error:
2237  LDNS_FREE(bignum);
2238  return LDNS_STATUS_ERR;
2239 #endif /* HAVE_SSL */
2240 
2241 }
2242 
2243 /*
2244  * Zero terminate the buffer and copy data.
2245  */
2246 char *
2248 {
2249  char *str;
2250 
2251  /* check if buffer ends with \0, if not, and
2252  if there is space, add it */
2253  if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
2254  if (!ldns_buffer_reserve(buffer, 1)) {
2255  return NULL;
2256  }
2257  ldns_buffer_write_u8(buffer, (uint8_t) '\0');
2258  if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
2259  return NULL;
2260  }
2261  }
2262 
2263  str = strdup((const char *)ldns_buffer_begin(buffer));
2264  if(!str) {
2265  return NULL;
2266  }
2267  return str;
2268 }
2269 
2270 /*
2271  * Zero terminate the buffer and export data.
2272  */
2273 char *
2275 {
2276  /* Append '\0' as string terminator */
2277  if (! ldns_buffer_reserve(buffer, 1)) {
2278  return NULL;
2279  }
2280  ldns_buffer_write_u8(buffer, 0);
2281 
2282  /* reallocate memory to the size of the string and export */
2283  ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer));
2284  return ldns_buffer_export(buffer);
2285 }
2286 
2287 char *
2289 {
2290  char *result = NULL;
2292 
2293  if (!tmp_buffer) {
2294  return NULL;
2295  }
2296  if (ldns_rdf2buffer_str(tmp_buffer, rdf) == LDNS_STATUS_OK) {
2297  /* export and return string, destroy rest */
2298  result = ldns_buffer_export2str(tmp_buffer);
2299  }
2300  ldns_buffer_free(tmp_buffer);
2301  return result;
2302 }
2303 
2304 char *
2306 {
2307  char *result = NULL;
2309 
2310  if (!tmp_buffer) {
2311  return NULL;
2312  }
2313  if (ldns_rr2buffer_str_fmt(tmp_buffer, fmt, rr)
2314  == LDNS_STATUS_OK) {
2315  /* export and return string, destroy rest */
2316  result = ldns_buffer_export2str(tmp_buffer);
2317  }
2318  ldns_buffer_free(tmp_buffer);
2319  return result;
2320 }
2321 
2322 char *
2324 {
2326 }
2327 
2328 char *
2330 {
2331  char *result = NULL;
2333 
2334  if (!tmp_buffer) {
2335  return NULL;
2336  }
2337  if (ldns_pkt2buffer_str_fmt(tmp_buffer, fmt, pkt)
2338  == LDNS_STATUS_OK) {
2339  /* export and return string, destroy rest */
2340  result = ldns_buffer_export2str(tmp_buffer);
2341  }
2342 
2343  ldns_buffer_free(tmp_buffer);
2344  return result;
2345 }
2346 
2347 char *
2349 {
2351 }
2352 
2353 char *
2355 {
2356  char *result = NULL;
2358 
2359  if (!tmp_buffer) {
2360  return NULL;
2361  }
2362  if (ldns_key2buffer_str(tmp_buffer, k) == LDNS_STATUS_OK) {
2363  /* export and return string, destroy rest */
2364  result = ldns_buffer_export2str(tmp_buffer);
2365  }
2366  ldns_buffer_free(tmp_buffer);
2367  return result;
2368 }
2369 
2370 char *
2372 {
2373  char *result = NULL;
2375 
2376  if (!tmp_buffer) {
2377  return NULL;
2378  }
2379  if (list) {
2381  tmp_buffer, fmt, list)
2382  == LDNS_STATUS_OK) {
2383  }
2384  } else {
2385  if (fmt == NULL) {
2387  }
2388  if (fmt->flags & LDNS_COMMENT_NULLS) {
2389  ldns_buffer_printf(tmp_buffer, "; (null)\n");
2390  }
2391  }
2392 
2393  /* export and return string, destroy rest */
2394  result = ldns_buffer_export2str(tmp_buffer);
2395  ldns_buffer_free(tmp_buffer);
2396  return result;
2397 }
2398 
2399 char *
2401 {
2403 }
2404 
2405 void
2406 ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
2407 {
2408  char *str = ldns_rdf2str(rdf);
2409  if (str) {
2410  fprintf(output, "%s", str);
2411  } else {
2412  fprintf(output, ";Unable to convert rdf to string\n");
2413  }
2414  LDNS_FREE(str);
2415 }
2416 
2417 void
2418 ldns_rr_print_fmt(FILE *output,
2419  const ldns_output_format *fmt, const ldns_rr *rr)
2420 {
2421  char *str = ldns_rr2str_fmt(fmt, rr);
2422  if (str) {
2423  fprintf(output, "%s", str);
2424  } else {
2425  fprintf(output, ";Unable to convert rr to string\n");
2426  }
2427  LDNS_FREE(str);
2428 }
2429 
2430 void
2431 ldns_rr_print(FILE *output, const ldns_rr *rr)
2432 {
2434 }
2435 
2436 void
2437 ldns_pkt_print_fmt(FILE *output,
2438  const ldns_output_format *fmt, const ldns_pkt *pkt)
2439 {
2440  char *str = ldns_pkt2str_fmt(fmt, pkt);
2441  if (str) {
2442  fprintf(output, "%s", str);
2443  } else {
2444  fprintf(output, ";Unable to convert packet to string\n");
2445  }
2446  LDNS_FREE(str);
2447 }
2448 
2449 void
2450 ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
2451 {
2453 }
2454 
2455 void
2457  const ldns_output_format *fmt, const ldns_rr_list *lst)
2458 {
2459  size_t i;
2460  for (i = 0; i < ldns_rr_list_rr_count(lst); i++) {
2461  ldns_rr_print_fmt(output, fmt, ldns_rr_list_rr(lst, i));
2462  }
2463 }
2464 
2465 void
2466 ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
2467 {
2469 }
2470 
2471 void
2473  const ldns_output_format *fmt, const ldns_resolver *r)
2474 {
2475  uint16_t i;
2476  ldns_rdf **n;
2477  ldns_rdf **s;
2478  size_t *rtt;
2479  if (!r) {
2480  return;
2481  }
2483  s = ldns_resolver_searchlist(r);
2484  rtt = ldns_resolver_rtt(r);
2485 
2486  fprintf(output, "port: %d\n", (int)ldns_resolver_port(r));
2487  fprintf(output, "edns0 size: %d\n", (int)ldns_resolver_edns_udp_size(r));
2488  fprintf(output, "use ip6: %d\n", (int)ldns_resolver_ip6(r));
2489 
2490  fprintf(output, "recursive: %d\n", ldns_resolver_recursive(r));
2491  fprintf(output, "usevc: %d\n", ldns_resolver_usevc(r));
2492  fprintf(output, "igntc: %d\n", ldns_resolver_igntc(r));
2493  fprintf(output, "fail: %d\n", ldns_resolver_fail(r));
2494  fprintf(output, "retry: %d\n", (int)ldns_resolver_retry(r));
2495  fprintf(output, "retrans: %d\n", (int)ldns_resolver_retrans(r));
2496  fprintf(output, "fallback: %d\n", ldns_resolver_fallback(r));
2497  fprintf(output, "random: %d\n", ldns_resolver_random(r));
2498  fprintf(output, "timeout: %d\n", (int)ldns_resolver_timeout(r).tv_sec);
2499  fprintf(output, "dnssec: %d\n", ldns_resolver_dnssec(r));
2500  fprintf(output, "dnssec cd: %d\n", ldns_resolver_dnssec_cd(r));
2501  fprintf(output, "trust anchors (%d listed):\n",
2504  fprintf(output, "tsig: %s %s\n",
2507  fprintf(output, "debug: %d\n", ldns_resolver_debug(r));
2508 
2509  fprintf(output, "default domain: ");
2511  fprintf(output, "\n");
2512  fprintf(output, "apply default domain: %d\n", ldns_resolver_defnames(r));
2513 
2514  fprintf(output, "searchlist (%d listed):\n", (int)ldns_resolver_searchlist_count(r));
2515  for (i = 0; i < ldns_resolver_searchlist_count(r); i++) {
2516  fprintf(output, "\t");
2517  ldns_rdf_print(output, s[i]);
2518  fprintf(output, "\n");
2519  }
2520  fprintf(output, "apply search list: %d\n", ldns_resolver_dnsrch(r));
2521 
2522  fprintf(output, "nameservers (%d listed):\n", (int)ldns_resolver_nameserver_count(r));
2523  for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
2524  fprintf(output, "\t");
2525  ldns_rdf_print(output, n[i]);
2526 
2527  switch ((int)rtt[i]) {
2528  case LDNS_RESOLV_RTT_MIN:
2529  fprintf(output, " - reachable\n");
2530  break;
2531  case LDNS_RESOLV_RTT_INF:
2532  fprintf(output, " - unreachable\n");
2533  break;
2534  }
2535  }
2536 }
2537 
2538 void
2539 ldns_resolver_print(FILE *output, const ldns_resolver *r)
2540 {
2542 }
2543 
2544 void
2545 ldns_zone_print_fmt(FILE *output,
2546  const ldns_output_format *fmt, const ldns_zone *z)
2547 {
2548  if(ldns_zone_soa(z))
2549  ldns_rr_print_fmt(output, fmt, ldns_zone_soa(z));
2550  ldns_rr_list_print_fmt(output, fmt, ldns_zone_rrs(z));
2551 }
2552 void
2553 ldns_zone_print(FILE *output, const ldns_zone *z)
2554 {
2556 }
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition: rr.c:895
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
Definition: resolver.c:60
implementation of buffers to ease operations
Definition: buffer.h:50
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:2472
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:778
time (32 bits)
Definition: rdata.h:84
enum ldns_enum_cert_algorithm ldns_cert_algorithm
Definition: rdata.h:163
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:785
#define INET_ADDRSTRLEN
Definition: host2str.c:32
bool ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
Definition: resolver.c:78
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet&#39;s ar count.
Definition: packet.c:117
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:189
ldns_rr * ldns_zone_soa(const ldns_zone *z)
Return the soa record of a zone.
Definition: zone.c:17
void * ldns_buffer_export(ldns_buffer *buffer)
Makes the buffer fixed and returns a pointer to the data.
Definition: buffer.c:150
Output format struct with additional data for flags that use them.
Definition: host2str.h:100
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
Definition: resolver.c:42
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:1205
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition: rdata.c:230
#define LDNS_COMMENT_BUBBLEBABBLE
Provide bubblebabble representation for DS RR&#39;s as comment.
Definition: host2str.h:56
#define LDNS_COMMENT_KEY_TYPE
Show if a DNSKEY is a ZSK or KSK as comment.
Definition: host2str.h:52
DNSSEC.
Definition: rr.h:173
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:1712
b64 string
Definition: rdata.h:68
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet&#39;s question section.
Definition: packet.c:123
DNS stub resolver structure.
Definition: resolver.h:59
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:884
char * ldns_bubblebabble(uint8_t *data, size_t len)
Encode data as BubbleBabble.
Definition: util.c:418
Chaos class.
Definition: rr.h:52
enum ldns_enum_rr_class ldns_rr_class
Definition: rr.h:64
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
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:1055
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:428
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:303
size_t ldns_resolver_searchlist_count(const ldns_resolver *r)
Return the resolver&#39;s searchlist count.
Definition: resolver.c:231
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:927
List or Set of Resource Records.
Definition: rr.h:330
ldns_status ldns_str2rdf_dname(ldns_rdf **d, const char *str)
convert a dname string into wireformat
Definition: str2host.c:311
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:651
bool ldns_rr_is_question(const ldns_rr *rr)
returns the question flag of an rr structure.
Definition: rr.c:911
bool ldns_pkt_tc(const ldns_pkt *packet)
Read the packet&#39;s tc bit.
Definition: packet.c:57
#define LDNS_FMT_RFC3597
Definition: host2str.h:67
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet&#39;s respons code.
Definition: packet.c:93
Output format specifier.
Definition: host2str.h:86
const ldns_output_format * ldns_output_format_onlykeyids
Standard output format record that annotated only DNSKEY RR&#39;s with commenti text. ...
Definition: host2str.c:129
unknown types
Definition: rdata.h:82
int ldns_b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize)
A request for mailbox-related records (MB, MG or MR)
Definition: rr.h:218
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet&#39;s qd count.
Definition: packet.c:99
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:1231
bool ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
Definition: resolver.c:120
Definition: keys.h:48
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet&#39;s edns extended rcode
Definition: packet.c:212
a RR type
Definition: rdata.h:74
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:951
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition: packet.c:39
struct tm * ldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result)
The function interprets time as the number of seconds since epoch with respect to now using serial ar...
Definition: util.c:304
#define LDNS_XMALLOC(type, count)
Definition: util.h:51
#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
bool ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
Definition: packet.c:726
DSA * ldns_key_dsa_key(const ldns_key *k)
returns the (openssl) DSA struct contained in the key
Definition: keys.c:1557
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition: rdata.c:24
ldns_lookup_table ldns_rcodes[]
Response codes.
Definition: host2str.c:98
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, HIT and Public Key and adds it the output buffer .
Definition: host2str.c:1242
char * ldns_buffer2str(ldns_buffer *buffer)
Returns a copy of the data in the buffer as a null terminated char * string.
Definition: host2str.c:2247
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet&#39;s code.
Definition: packet.c:87
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:1963
bool ldns_pkt_aa(const ldns_pkt *packet)
Read the packet&#39;s aa bit.
Definition: packet.c:51
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
Definition: buffer.c:137
DNS Zone.
Definition: zone.h:42
struct ldns_struct_key::@0 _key
Storage pointers for the types of keys supported.
a class
Definition: rdata.h:76
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet&#39;s querytime.
Definition: packet.c:188
size_t ldns_rr_rd_count(const ldns_rr *rr)
returns the rd_count of an rr structure.
Definition: rr.c:923
#define LDNS_FMT_PAD_SOA_SERIAL
Definition: host2str.h:66
#define LDNS_MAX_PACKETLEN
Definition: packet.h:24
#define LDNS_COMMENT_KEY
Show key id, type and size as comment for DNSKEY RR&#39;s.
Definition: host2str.h:72
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:1409
ldns_lookup_table ldns_rr_classes[]
rr types
Definition: host2str.c:88
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:891
IPSECKEY.
Definition: rdata.h:107
uint16_t ldns_resolver_port(const ldns_resolver *r)
Get the port the resolver should use.
Definition: resolver.c:24
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
Definition: resolver.c:102
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:242
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:1421
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:2305
ldns_rr_list * ldns_resolver_dnssec_anchors(const ldns_resolver *r)
Get the resolver&#39;s DNSSEC anchors.
Definition: resolver.c:132
EVP_PKEY * key
Definition: keys.h:137
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:574
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:2400
void ldns_resolver_print(FILE *output, const ldns_resolver *r)
Print a resolver (in sofar that is possible) state to output.
Definition: host2str.c:2539
bool ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
Definition: resolver.c:126
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:1459
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition: rr.c:2569
bool ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
Definition: resolver.c:165
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:2371
protocol and port bitmaps
Definition: rdata.h:97
A non-zero sequence of US-ASCII letters and numbers in lower case.
Definition: rdata.h:126
const ldns_output_format * ldns_output_format_default
The default output format record.
Definition: host2str.c:131
A <character-string> encoding of the value field as specified [RFC1035], Section 5.1., encoded as remaining rdata.
Definition: rdata.h:132
apl data
Definition: rdata.h:64
#define LDNS_RESOLV_RTT_MIN
Definition: resolver.h:54
Resource Record.
Definition: rr.h:302
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
Definition: rdata.c:241
#define LDNS_COMMENT_KEY_SIZE
Show DNSKEY key size as comment.
Definition: host2str.h:54
size_t ldns_key_hmac_size(const ldns_key *k)
return the hmac key size
Definition: keys.c:1584
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:2437
const void * data
pointer to data
Definition: rbtree.h:70
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:545
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:1467
bool ldns_resolver_defnames(const ldns_resolver *r)
Does the resolver apply default domain name.
Definition: resolver.c:90
Including this file will include all ldns files, and define some lookup tables.
bool ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
Definition: resolver.c:54
certificate algorithm
Definition: rdata.h:78
marks the start of a zone of authority
Definition: rr.h:93
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet&#39;s ns count.
Definition: packet.c:111
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:489
General key structure, can contain all types of keys that are used in DNSSEC.
Definition: keys.h:126
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition: rdata.c:38
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_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:476
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:1339
void ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
print a rr_list to output
Definition: host2str.c:2466
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:976
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:2545
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:2418
#define LDNS_APL_IP4
Definition: host2str.h:37
16 bits
Definition: rdata.h:54
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
Definition: rdata.h:138
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition: packet.h:52
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:2323
#define LDNS_IP4ADDRLEN
Definition: ldns.h:131
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
Definition: rr.h:33
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:262
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:916
char * ldns_buffer_export2str(ldns_buffer *buffer)
Exports and returns the data in the buffer as a null terminated char * string.
Definition: host2str.c:2274
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet&#39;s an count.
Definition: packet.c:105
bool ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
Definition: resolver.c:171
bool ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
changes the buffer&#39;s capacity.
Definition: buffer.c:60
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:685
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:201
size_t ldns_resolver_nameserver_count(const ldns_resolver *r)
How many nameserver are configured in the resolver.
Definition: resolver.c:114
The rbnode_t struct definition.
Definition: rbtree.h:60
variable length any type rdata where the length is specified by the first 2 bytes ...
Definition: rdata.h:95
bool ldns_pkt_cd(const ldns_pkt *packet)
Read the packet&#39;s cd bit.
Definition: packet.c:69
None class, dynamic update.
Definition: rr.h:56
a key algorithm
Definition: rdata.h:80
#define LDNS_MAX_KEYLEN
Definition: dnssec.h:41
bool ldns_pkt_ra(const ldns_pkt *packet)
Read the packet&#39;s ra bit.
Definition: packet.c:75
uint16_t ldns_rdf2native_int16(const ldns_rdf *rd)
returns the native uint16_t representation from the rdf.
Definition: rdata.c:84
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:1028
b32 string
Definition: rdata.h:66
A record.
Definition: rdata.h:58
#define LDNS_APL_MASK
Definition: host2str.h:39
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:213
size_t _position
The current position used for reading/writing.
Definition: buffer.h:53
uint16_t ldns_resolver_edns_udp_size(const ldns_resolver *r)
Get the resolver&#39;s udp size.
Definition: resolver.c:36
nsec type codes
Definition: rdata.h:72
#define LDNS_IP6ADDRLEN
Definition: ldns.h:132
int flags
Specification of how RR&#39;s should be formatted in text.
Definition: host2str.h:89
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
Definition: util.c:41
ldns_lookup_table ldns_algorithms[]
Taken from RFC 2535, section 7.
Definition: host2str.c:41
#define LDNS_KEY_ZONE_KEY
Definition: keys.h:37
the Internet
Definition: rr.h:50
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:1178
AAAA record.
Definition: rdata.h:60
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:227
32 bits
Definition: rdata.h:56
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet&#39;s timestamp.
Definition: packet.c:200
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:402
bool ldns_nsec3_optout(const ldns_rr *nsec3_rr)
Returns true if the opt-out flag has been set in the given NSEC3 RR.
Definition: dnssec.c:1279
uint16_t ldns_calc_keytag(const ldns_rr *key)
calculates a keytag of a key for use in DNSSEC.
Definition: dnssec.c:271
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet&#39;s answerfrom.
Definition: packet.c:194
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition: packet.h:68
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:386
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:326
RSA * ldns_key_rsa_key(const ldns_key *k)
returns the (openssl) RSA struct contained in the key
Definition: keys.c:1547
Contains all information about resource record types.
Definition: rr.h:343
bool ldns_pkt_rd(const ldns_pkt *packet)
Read the packet&#39;s rd bit.
Definition: packet.c:63
#define LDNS_APL_IP6
Definition: host2str.h:38
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet&#39;s edns version
Definition: packet.c:218
RFC4034, RFC3658.
Definition: rr.h:167
bool ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
Definition: resolver.c:72
bool ldns_nsec_bitmap_covers_type(const ldns_rdf *bitmap, ldns_rr_type type)
Check if RR type t is enumerated and set in the RR type bitmap rdf.
Definition: dnssec.c:1384
ldns_rbnode_t * ldns_rbtree_search(ldns_rbtree_t *rbtree, const void *key)
Find key in tree.
Definition: rbtree.c:294
hex string
Definition: rdata.h:70
#define LDNS_APL_NEGATION
Definition: host2str.h:40
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
Definition: rdata.c:31
DNS packet.
Definition: packet.h:233
#define LDNS_KEY_SEP_KEY
Definition: keys.h:38
txt string
Definition: rdata.h:62
const ldns_output_format ldns_output_format_bubblebabble_record
Definition: host2str.c:133
ldns_lookup_table ldns_opcodes[]
Operation codes.
Definition: host2str.c:113
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:2406
uint32_t ldns_rdf2native_int32(const ldns_rdf *rd)
returns the native uint32_t representation from the rdf.
Definition: rdata.c:98
#define INET6_ADDRSTRLEN
Definition: host2str.c:35
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition: rr.c:929
bool ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
Definition: resolver.c:225
const char * ldns_resolver_tsig_algorithm(const ldns_resolver *r)
Return the tsig algorithm as used by the nameserver.
Definition: resolver.c:213
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:2329
tsig time 48 bits
Definition: rdata.h:88
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:792
const ldns_output_format ldns_output_format_onlykeyids_record
Definition: host2str.c:125
unsigned char * ldns_key_hmac_key(const ldns_key *k)
return the hmac key data
Definition: keys.c:1574
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:1885
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:124
const char * name
Definition: util.h:158
A request for mail agent RRs (Obsolete - see MX)
Definition: rr.h:220
nsec3 base32 string (with length byte on wire
Definition: rdata.h:111
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:1164
enum ldns_enum_status ldns_status
Definition: error.h:134
ldns_rdf * ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data)
allocates a new rdf structure and fills it.
Definition: rdata.c:193
ldns_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:149
ldns_buffer * ldns_buffer_new(size_t capacity)
creates a new buffer with the specified capacity.
Definition: buffer.c:16
Definition: keys.h:47
ldns_rdf * ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
allocates a new rdf structure and fills it.
Definition: rdata.c:179
void ldns_zone_print(FILE *output, const ldns_zone *z)
Print a zone structure * to output.
Definition: host2str.c:2553
A general purpose lookup table.
Definition: util.h:156
ldns_signing_algorithm ldns_key_algorithm(const ldns_key *k)
return the signing alg of the key
Definition: keys.c:1516
int ldns_b32_ntop_extended_hex(const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
Definition: util.c:588
uint8_t ldns_resolver_retrans(const ldns_resolver *r)
Get the retransmit interval.
Definition: resolver.c:48
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:666
#define LDNS_FMT_ZEROIZE_RRSIGS
Definition: host2str.h:65
const ldns_output_format ldns_output_format_nocomments_record
Definition: host2str.c:122
size_t ldns_rr_dnskey_key_size(const ldns_rr *key)
get the length of the keydata in bits
Definition: rr_functions.c:340
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:510
bool ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
ensures BUFFER can contain at least AMOUNT more bytes.
Definition: buffer.c:79
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:2431
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:1764
size_t * ldns_resolver_rtt(const ldns_resolver *r)
Return the used round trip times for the nameservers.
Definition: resolver.c:177
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet&#39;s edns udp size
Definition: packet.c:206
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:460
bool ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
Definition: resolver.c:84
#define LDNS_COMMENT_RRSIGS
Also comment KEY_ID with RRSIGS.
Definition: host2str.h:64
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:798
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:394
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition: rdata.h:116
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:1686
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:1705
Hesiod (Dyer 87)
Definition: rr.h:54
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet&#39;s edns data
Definition: packet.c:246
#define LDNS_COMMENT_FLAGS
Show when a NSEC3 RR has the optout flag set as comment.
Definition: host2str.h:58
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:169
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:630
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:2288
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:282
ldns_rr_list * ldns_zone_rrs(const ldns_zone *z)
Get a list of a zone&#39;s content.
Definition: zone.c:35
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:2450
ldns_rdf ** ldns_resolver_nameservers(const ldns_resolver *r)
Return the configured nameserver ip address.
Definition: resolver.c:108
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:1191
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:560
bool ldns_pkt_qr(const ldns_pkt *packet)
Read the packet&#39;s qr bit.
Definition: packet.c:45
Resource record data field.
Definition: rdata.h:174
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:597
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
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet&#39;s tsig pseudo rr&#39;s.
Definition: packet.c:450
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition: rdata.h:92
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:137
nsec3 hash salt
Definition: rdata.h:109
ldns_lookup_table ldns_cert_algorithms[]
Taken from RFC 2538.
Definition: host2str.c:73
8 bits
Definition: rdata.h:52
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition: rr.c:905
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:378
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr&#39;s in an rr_list.
Definition: rr.c:943
#define LDNS_COMMENT_KEY_ID
Show key id with DNSKEY RR&#39;s as comment.
Definition: host2str.h:50
enum ldns_enum_rr_type ldns_rr_type
Definition: rr.h:239
bool ldns_pkt_ad(const ldns_pkt *packet)
Read the packet&#39;s ad bit.
Definition: packet.c:81
const char * _name
Textual name of the RR type.
Definition: rr.h:348
#define LDNS_COMMENT_NSEC3_CHAIN
Show the unhashed owner and next owner names for NSEC3 RR&#39;s as comment.
Definition: host2str.h:60
#define LDNS_FREE(ptr)
Definition: util.h:60
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet&#39;s authority section.
Definition: packet.c:135
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:1692
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet&#39;s size in bytes.
Definition: packet.c:182
bool ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
Definition: resolver.c:66
#define LDNS_RESOLV_RTT_INF
Definition: resolver.h:53
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
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition: rr.c:917
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:2354
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition: rr.c:935
Any class.
Definition: rr.h:58
Definition: keys.h:49
domain name
Definition: rdata.h:50
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:2554
const char * ldns_resolver_tsig_keyname(const ldns_resolver *r)
Return the tsig keyname as used by the nameserver.
Definition: resolver.c:207
location data
Definition: rdata.h:99
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet&#39;s additional section.
Definition: packet.c:141
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet&#39;s answer section.
Definition: packet.c:129
8 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:121
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:394
6 * 8 bit hex numbers separated by dashes.
Definition: rdata.h:119
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:2348
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:538
well known services
Definition: rdata.h:101
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:2560
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
Definition: resolver.c:96
any type (wildcard)
Definition: rr.h:222
enum ldns_enum_algorithm ldns_algorithm
Definition: keys.h:72
bool ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet&#39;s edns do bit
Definition: packet.c:230
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
Definition: resolver.c:201
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:2456
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:417