1/** 2 * host2str.h - txt presentation of RRs 3 * 4 * a Net::DNS like library for C 5 * 6 * (c) NLnet Labs, 2005-2006 7 * 8 * See the file LICENSE for the license 9 */ 10 11/** 12 * \file 13 * 14 * Contains functions to translate the main structures to their text 15 * representation, as well as functions to print them. 16 */ 17 18#ifndef LDNS_HOST2STR_H 19#define LDNS_HOST2STR_H 20 21#include <ldns/common.h> 22#include <ldns/error.h> 23#include <ldns/rr.h> 24#include <ldns/rdata.h> 25#include <ldns/packet.h> 26#include <ldns/buffer.h> 27#include <ldns/resolver.h> 28#include <ldns/zone.h> 29#include <ctype.h> 30 31#include "ldns/util.h" 32 33#ifdef __cplusplus 34extern "C" { 35#endif 36 37#define LDNS_APL_IP4 1 38#define LDNS_APL_IP6 2 39#define LDNS_APL_MASK 0x7f 40#define LDNS_APL_NEGATION 0x80 41 42/** 43 * Represent a NULL pointer (instead of a pointer to a ldns_rr as "; (null)" 44 * as opposed to outputting nothing at all in such a case. 45 */ 46/* Flag Name Flag Nr. Has data associated 47 ---------------------------------------------------------------------*/ 48#define LDNS_COMMENT_NULLS (1 << 0) 49/** Show key id with DNSKEY RR's as comment */ 50#define LDNS_COMMENT_KEY_ID (1 << 1) 51/** Show if a DNSKEY is a ZSK or KSK as comment */ 52#define LDNS_COMMENT_KEY_TYPE (1 << 2) 53/** Show DNSKEY key size as comment */ 54#define LDNS_COMMENT_KEY_SIZE (1 << 3) 55/** Provide bubblebabble representation for DS RR's as comment */ 56#define LDNS_COMMENT_BUBBLEBABBLE (1 << 4) 57/** Show when a NSEC3 RR has the optout flag set as comment */ 58#define LDNS_COMMENT_FLAGS (1 << 5) 59/** Show the unhashed owner and next owner names for NSEC3 RR's as comment */ 60#define LDNS_COMMENT_NSEC3_CHAIN (1 << 6) /* yes */ 61/** Print mark up */ 62#define LDNS_COMMENT_LAYOUT (1 << 7) 63/** Also comment KEY_ID with RRSIGS **/ 64#define LDNS_COMMENT_RRSIGS (1 << 8) 65#define LDNS_FMT_ZEROIZE_RRSIGS (1 << 9) 66#define LDNS_FMT_PAD_SOA_SERIAL (1 << 10) 67#define LDNS_FMT_RFC3597 (1 << 11) /* yes */ 68/** Prints only answer section of packets and only rdata of RRs **/ 69#define LDNS_FMT_SHORT (1 << 12) 70 71#define LDNS_FMT_FLAGS_WITH_DATA 2 72 73/** Show key id, type and size as comment for DNSKEY RR's */ 74#define LDNS_COMMENT_KEY (LDNS_COMMENT_KEY_ID \ 75 |LDNS_COMMENT_KEY_TYPE\ 76 |LDNS_COMMENT_KEY_SIZE) 77 78/** 79 * Output format specifier 80 * 81 * Determines how Packets, Resource Records and Resource record data field are 82 * formatted when printing or converting to string. 83 * Currently it is only used to specify what aspects of a Resource Record are 84 * annotated in the comment section of the textual representation the record. 85 * This is specified with flags and potential extra data (such as for example 86 * a lookup map of hashes to real names for annotation NSEC3 records). 87 */ 88struct ldns_struct_output_format 89{ 90 /** Specification of how RR's should be formatted in text */ 91 int flags; 92 /** Potential extra data to be used with formatting RR's in text */ 93 void *data; 94}; 95typedef struct ldns_struct_output_format ldns_output_format; 96 97/** 98 * Output format struct with additional data for flags that use them. 99 * This struct may not be initialized directly. Use ldns_output_format_init 100 * to initialize. 101 */ 102struct ldns_struct_output_format_storage 103{ int flags; 104 ldns_rbtree_t* hashmap; /* for LDNS_COMMENT_NSEC3_CHAIN */ 105 ldns_rdf* bitmap; /* for LDNS_FMT_RFC3597 */ 106}; 107typedef struct ldns_struct_output_format_storage ldns_output_format_storage; 108 109/** 110 * Standard output format record that disables commenting in the textual 111 * representation of Resource Records completely. 112 */ 113extern const ldns_output_format *ldns_output_format_nocomments; 114/** 115 * Standard output format record that annotated only DNSKEY RR's with comment 116 * text. 117 */ 118extern const ldns_output_format *ldns_output_format_onlykeyids; 119/** 120 * The default output format record. Same as ldns_output_format_onlykeyids. 121 */ 122extern const ldns_output_format *ldns_output_format_default; 123/** 124 * Standard output format record that shows all DNSKEY related information in 125 * the comment text, plus the optout flag when set with NSEC3's, plus the 126 * bubblebabble representation of DS RR's. 127 */ 128extern const ldns_output_format *ldns_output_format_bubblebabble; 129 130/** 131 * Initialize output format storage to the default value. 132 * \param[in] fmt A reference to an output_format_ storage struct 133 * \return The initialized storage struct typecasted to ldns_output_format 134 */ 135INLINE 136ldns_output_format* ldns_output_format_init(ldns_output_format_storage* fmt) { 137 fmt->flags = ldns_output_format_default->flags; 138 fmt->hashmap = NULL; 139 fmt->bitmap = NULL; 140 return (ldns_output_format*)fmt; 141} 142 143/** 144 * Set an output format flag. 145 */ 146INLINE void ldns_output_format_set(ldns_output_format* fmt, int flag) { 147 fmt->flags |= flag; 148} 149 150/** 151 * Clear an output format flag. 152 */ 153INLINE void ldns_output_format_clear(ldns_output_format* fmt, int flag) { 154 fmt->flags &= !flag; 155} 156 157/** 158 * Makes sure the LDNS_FMT_RFC3597 is set in the output format. 159 * Marks the type to be printed in RFC3597 format. 160 * /param[in] fmt the output format to update 161 * /param[in] the type to be printed in RFC3597 format 162 * /return LDNS_STATUS_OK on success 163 */ 164ldns_status 165ldns_output_format_set_type(ldns_output_format* fmt, ldns_rr_type type); 166 167/** 168 * Makes sure the LDNS_FMT_RFC3597 is set in the output format. 169 * Marks the type to not be printed in RFC3597 format. When no other types 170 * have been marked before, all known types (except the given one) will be 171 * marked for printing in RFC3597 format. 172 * /param[in] fmt the output format to update 173 * /param[in] the type not to be printed in RFC3597 format 174 * /return LDNS_STATUS_OK on success 175 */ 176ldns_status 177ldns_output_format_clear_type(ldns_output_format* fmt, ldns_rr_type type); 178 179/** 180 * Converts an ldns packet opcode value to its mnemonic, and adds that 181 * to the output buffer 182 * \param[in] *output the buffer to add the data to 183 * \param[in] opcode to find the string representation of 184 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error 185 */ 186ldns_status 187ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode); 188 189/** 190 * Converts an ldns packet rcode value to its mnemonic, and adds that 191 * to the output buffer 192 * \param[in] *output the buffer to add the data to 193 * \param[in] rcode to find the string representation of 194 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error 195 */ 196ldns_status 197ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode); 198 199/** 200 * Converts an ldns algorithm type to its mnemonic, and adds that 201 * to the output buffer 202 * \param[in] *output the buffer to add the data to 203 * \param[in] algorithm to find the string representation of 204 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error 205 */ 206ldns_status 207ldns_algorithm2buffer_str(ldns_buffer *output, 208 ldns_algorithm algorithm); 209 210/** 211 * Converts an ldns certificate algorithm type to its mnemonic, 212 * and adds that to the output buffer 213 * \param[in] *output the buffer to add the data to 214 * \param[in] cert_algorithm to find the string representation of 215 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error 216 */ 217ldns_status 218ldns_cert_algorithm2buffer_str(ldns_buffer *output, 219 ldns_cert_algorithm cert_algorithm); 220 221 222/** 223 * Converts a packet opcode to its mnemonic and returns that as 224 * an allocated null-terminated string. 225 * Remember to free it. 226 * 227 * \param[in] opcode the opcode to convert to text 228 * \return null terminated char * data, or NULL on error 229 */ 230char *ldns_pkt_opcode2str(ldns_pkt_opcode opcode); 231 232/** 233 * Converts a packet rcode to its mnemonic and returns that as 234 * an allocated null-terminated string. 235 * Remember to free it. 236 * 237 * \param[in] rcode the rcode to convert to text 238 * \return null terminated char * data, or NULL on error 239 */ 240char *ldns_pkt_rcode2str(ldns_pkt_rcode rcode); 241 242/** 243 * Converts a signing algorithms to its mnemonic and returns that as 244 * an allocated null-terminated string. 245 * Remember to free it. 246 * 247 * \param[in] algorithm the algorithm to convert to text 248 * \return null terminated char * data, or NULL on error 249 */ 250char *ldns_pkt_algorithm2str(ldns_algorithm algorithm); 251 252/** 253 * Converts a cert algorithm to its mnemonic and returns that as 254 * an allocated null-terminated string. 255 * Remember to free it. 256 * 257 * \param[in] cert_algorithm to convert to text 258 * \return null terminated char * data, or NULL on error 259 */ 260char *ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm); 261 262/** 263 * Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer 264 * \param[in] *rdf The rdata to convert 265 * \param[in] *output The buffer to add the data to 266 * \return LDNS_STATUS_OK on success, and error status on failure 267 */ 268ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf); 269 270/** 271 * Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer 272 * \param[in] *rdf The rdata to convert 273 * \param[in] *output The buffer to add the data to 274 * \return LDNS_STATUS_OK on success, and error status on failure 275 */ 276ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf); 277 278/** 279 * Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer 280 * \param[in] *rdf The rdata to convert 281 * \param[in] *output The buffer to add the data to 282 * \return LDNS_STATUS_OK on success, and error status on failure 283 */ 284ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf); 285 286/** 287 * Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer 288 * \param[in] *rdf The rdata to convert 289 * \param[in] *output The buffer to add the data to 290 * \return LDNS_STATUS_OK on success, and error status on failure 291 */ 292ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf); 293 294/** 295 * Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer 296 * \param[in] *rdf The rdata to convert 297 * \param[in] *output The buffer to add the data to 298 * \return LDNS_STATUS_OK on success, and error status on failure 299 */ 300ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf); 301 302/** 303 * Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer 304 * \param[in] *rdf The rdata to convert 305 * \param[in] *output The buffer to add the data to 306 * \return LDNS_STATUS_OK on success, and error status on failure 307 */ 308ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf); 309 310/** 311 * Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer 312 * \param[in] *rdf The rdata to convert 313 * \param[in] *output The buffer to add the data to 314 * \return LDNS_STATUS_OK on success, and error status on failure 315 */ 316ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf); 317 318/** 319 * Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer 320 * \param[in] *rdf The rdata to convert 321 * \param[in] *output The buffer to add the data to 322 * \return LDNS_STATUS_OK on success, and error status on failure 323 */ 324ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf); 325 326/** 327 * Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer 328 * \param[in] *rdf The rdata to convert 329 * \param[in] *output The buffer to add the data to 330 * \return LDNS_STATUS_OK on success, and error status on failure 331 */ 332ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf); 333 334/** 335 * Converts an ldns_rr_type value to its string representation, 336 * and places it in the given buffer 337 * \param[in] *output The buffer to add the data to 338 * \param[in] type the ldns_rr_type to convert 339 * \return LDNS_STATUS_OK on success, and error status on failure 340 */ 341ldns_status ldns_rr_type2buffer_str(ldns_buffer *output, 342 const ldns_rr_type type); 343 344/** 345 * Converts an ldns_rr_type value to its string representation, 346 * and returns that string. For unknown types, the string 347 * "TYPE<id>" is returned. This function allocates data that must be 348 * freed by the caller 349 * \param[in] type the ldns_rr_type to convert 350 * \return a newly allocated string 351 */ 352char *ldns_rr_type2str(const ldns_rr_type type); 353 354/** 355 * Converts an ldns_rr_class value to its string representation, 356 * and places it in the given buffer 357 * \param[in] *output The buffer to add the data to 358 * \param[in] klass the ldns_rr_class to convert 359 * \return LDNS_STATUS_OK on success, and error status on failure 360 */ 361ldns_status ldns_rr_class2buffer_str(ldns_buffer *output, 362 const ldns_rr_class klass); 363 364/** 365 * Converts an ldns_rr_class value to its string representation, 366 * and returns that string. For unknown types, the string 367 * "CLASS<id>" is returned. This function allocates data that must be 368 * freed by the caller 369 * \param[in] klass the ldns_rr_class to convert 370 * \return a newly allocated string 371 */ 372char *ldns_rr_class2str(const ldns_rr_class klass); 373 374 375/** 376 * Converts an LDNS_RDF_TYPE_CERT rdata element to string format and adds it to the output buffer 377 * \param[in] *rdf The rdata to convert 378 * \param[in] *output The buffer to add the data to 379 * \return LDNS_STATUS_OK on success, and error status on failure 380 */ 381ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf); 382 383/** 384 * Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer 385 * \param[in] *rdf The rdata to convert 386 * \param[in] *output The buffer to add the data to 387 * \return LDNS_STATUS_OK on success, and error status on failure 388 */ 389ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf); 390 391/** 392 * Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer 393 * \param[in] *rdf The rdata to convert 394 * \param[in] *output The buffer to add the data to 395 * \return LDNS_STATUS_OK on success, and error status on failure 396 */ 397ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf); 398 399/** 400 * Converts an LDNS_RDF_TYPE_NSAP rdata element to string format and adds it to the output buffer 401 * \param[in] *rdf The rdata to convert 402 * \param[in] *output The buffer to add the data to 403 * \return LDNS_STATUS_OK on success, and error status on failure 404 */ 405ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf); 406 407/** 408 * Converts an LDNS_RDF_TYPE_ATMA rdata element to string format and adds it to the output buffer 409 * \param[in] *rdf The rdata to convert 410 * \param[in] *output The buffer to add the data to 411 * \return LDNS_STATUS_OK on success, and error status on failure 412 */ 413ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf); 414 415/** 416 * Converts an LDNS_RDF_TYPE_WKS rdata element to string format and adds it to the output buffer 417 * \param[in] *rdf The rdata to convert 418 * \param[in] *output The buffer to add the data to 419 * \return LDNS_STATUS_OK on success, and error status on failure 420 */ 421ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf); 422 423/** 424 * Converts an LDNS_RDF_TYPE_NSEC rdata element to string format and adds it to the output buffer 425 * \param[in] *rdf The rdata to convert 426 * \param[in] *output The buffer to add the data to 427 * \return LDNS_STATUS_OK on success, and error status on failure 428 */ 429ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf); 430 431/** 432 * Converts an LDNS_RDF_TYPE_PERIOD rdata element to string format and adds it to the output buffer 433 * \param[in] *rdf The rdata to convert 434 * \param[in] *output The buffer to add the data to 435 * \return LDNS_STATUS_OK on success, and error status on failure 436 */ 437ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf); 438 439/** 440 * Converts an LDNS_RDF_TYPE_TSIGTIME rdata element to string format and adds it to the output buffer 441 * \param[in] *rdf The rdata to convert 442 * \param[in] *output The buffer to add the data to 443 * \return LDNS_STATUS_OK on success, and error status on failure 444 */ 445ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf); 446 447/** 448 * Converts an LDNS_RDF_TYPE_APL rdata element to string format and adds it to the output buffer 449 * \param[in] *rdf The rdata to convert 450 * \param[in] *output The buffer to add the data to 451 * \return LDNS_STATUS_OK on success, and error status on failure 452 */ 453ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf); 454 455/** 456 * Converts an LDNS_RDF_TYPE_INT16_DATA rdata element to string format and adds it to the output buffer 457 * \param[in] *rdf The rdata to convert 458 * \param[in] *output The buffer to add the data to 459 * \return LDNS_STATUS_OK on success, and error status on failure 460 */ 461ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf); 462 463/** 464 * Converts an LDNS_RDF_TYPE_IPSECKEY rdata element to string format and adds it to the output buffer 465 * \param[in] *rdf The rdata to convert 466 * \param[in] *output The buffer to add the data to 467 * \return LDNS_STATUS_OK on success, and error status on failure 468 */ 469ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf); 470 471/** 472 * Converts the data in the rdata field to presentation 473 * format (as char *) and appends it to the given buffer 474 * 475 * \param[in] output pointer to the buffer to append the data to 476 * \param[in] rdf the pointer to the rdafa field containing the data 477 * \return status 478 */ 479ldns_status ldns_rdf2buffer_str(ldns_buffer *output, const ldns_rdf *rdf); 480 481/** 482 * Converts the data in the resource record to presentation 483 * format (as char *) and appends it to the given buffer. 484 * The presentation format of DNSKEY record is annotated with comments giving 485 * the id, type and size of the key. 486 * 487 * \param[in] output pointer to the buffer to append the data to 488 * \param[in] rr the pointer to the rr field to convert 489 * \return status 490 */ 491ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr); 492 493/** 494 * Converts the data in the resource record to presentation 495 * format (as char *) and appends it to the given buffer. 496 * The presentation format is annotated with comments giving 497 * additional information on the record. 498 * 499 * \param[in] output pointer to the buffer to append the data to 500 * \param[in] fmt how to format the textual representation of the 501 * resource record. 502 * \param[in] rr the pointer to the rr field to convert 503 * \return status 504 */ 505ldns_status ldns_rr2buffer_str_fmt(ldns_buffer *output, 506 const ldns_output_format *fmt, const ldns_rr *rr); 507 508/** 509 * Converts the data in the DNS packet to presentation 510 * format (as char *) and appends it to the given buffer 511 * 512 * \param[in] output pointer to the buffer to append the data to 513 * \param[in] pkt the pointer to the packet to convert 514 * \return status 515 */ 516ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt); 517 518/** 519 * Converts the list of EDNS options to presentation 520 * format (as char *) and appends it to the given buffer 521 * 522 * \param[in] output pointer to the buffer to append the data to 523 * \param[in] edns_list the list of EDNS options 524 * \return status 525 */ 526ldns_status ldns_edns_option_list2buffer_str(ldns_buffer *output, 527 ldns_edns_option_list* edns_list); 528 529/** 530 * Converts the data in the DNS packet to presentation 531 * format (as char *) and appends it to the given buffer 532 * 533 * \param[in] output pointer to the buffer to append the data to 534 * \param[in] fmt how to format the textual representation of the packet 535 * \param[in] pkt the pointer to the packet to convert 536 * \return status 537 */ 538ldns_status ldns_pkt2buffer_str_fmt(ldns_buffer *output, 539 const ldns_output_format *fmt, const ldns_pkt *pkt); 540 541/** 542 * Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer 543 * \param[in] *rdf The rdata to convert 544 * \param[in] *output The buffer to add the data to 545 * \return LDNS_STATUS_OK on success, and error status on failure 546 */ 547ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf); 548 549 550/** 551 * Converts the data in the DNS packet to presentation 552 * format (as char *) and appends it to the given buffer 553 * 554 * \param[in] output pointer to the buffer to append the data to 555 * \param[in] k the pointer to the private key to convert 556 * \return status 557 */ 558ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k); 559 560/** 561 * Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer 562 * \param[in] *rdf The rdata to convert 563 * \param[in] *output The buffer to add the data to 564 * \return LDNS_STATUS_OK on success, and error status on failure 565 */ 566ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf); 567 568/** 569 * Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer 570 * \param[in] *rdf The rdata to convert 571 * \param[in] *output The buffer to add the data to 572 * \return LDNS_STATUS_OK on success, and error status on failure 573 */ 574ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf); 575 576/** 577 * Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer 578 * \param[in] *rdf The rdata to convert 579 * \param[in] *output The buffer to add the data to 580 * \return LDNS_STATUS_OK on success, and error status on failure 581 */ 582ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf); 583 584/** 585 * Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer 586 * \param[in] *rdf The rdata to convert 587 * \param[in] *output The buffer to add the data to 588 * \return LDNS_STATUS_OK on success, and error status on failure 589 */ 590ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf); 591 592/** 593 * Converts an LDNS_RDF_TYPE_ILNP64 rdata element to 4 hexadecimal numbers 594 * separated by colons and adds it to the output buffer 595 * \param[in] *rdf The rdata to convert 596 * \param[in] *output The buffer to add the data to 597 * \return LDNS_STATUS_OK on success, and error status on failure 598 */ 599ldns_status ldns_rdf2buffer_str_ilnp64(ldns_buffer *output, 600 const ldns_rdf *rdf); 601 602/** 603 * Converts an LDNS_RDF_TYPE_EUI48 rdata element to 6 hexadecimal numbers 604 * separated by dashes and adds it to the output buffer 605 * \param[in] *rdf The rdata to convert 606 * \param[in] *output The buffer to add the data to 607 * \return LDNS_STATUS_OK on success, and error status on failure 608 */ 609ldns_status ldns_rdf2buffer_str_eui48(ldns_buffer *output, 610 const ldns_rdf *rdf); 611 612/** 613 * Converts an LDNS_RDF_TYPE_EUI64 rdata element to 8 hexadecimal numbers 614 * separated by dashes and adds it to the output buffer 615 * \param[in] *rdf The rdata to convert 616 * \param[in] *output The buffer to add the data to 617 * \return LDNS_STATUS_OK on success, and error status on failure 618 */ 619ldns_status ldns_rdf2buffer_str_eui64(ldns_buffer *output, 620 const ldns_rdf *rdf); 621 622/** 623 * Adds the LDNS_RDF_TYPE_TAG rdata to the output buffer, 624 * provided it contains only alphanumeric characters. 625 * \param[in] *rdf The rdata to convert 626 * \param[in] *output The buffer to add the data to 627 * \return LDNS_STATUS_OK on success, and error status on failure 628 */ 629ldns_status ldns_rdf2buffer_str_tag(ldns_buffer *output, 630 const ldns_rdf *rdf); 631 632/** 633 * Adds the LDNS_RDF_TYPE_LONG_STR rdata to the output buffer, in-between 634 * double quotes and all non printable characters properly escaped. 635 * \param[in] *rdf The rdata to convert 636 * \param[in] *output The buffer to add the data to 637 * \return LDNS_STATUS_OK on success, and error status on failure 638 */ 639ldns_status ldns_rdf2buffer_str_long_str(ldns_buffer *output, 640 const ldns_rdf *rdf); 641 642/** 643 * Converts an LDNS_RDF_TYPE_HIP rdata element to presentation format for 644 * the algorithm, HIT and Public Key and adds it the output buffer . 645 * \param[in] *rdf The rdata to convert 646 * \param[in] *output The buffer to add the data to 647 * \return LDNS_STATUS_OK on success, and error status on failure 648 */ 649ldns_status ldns_rdf2buffer_str_hip(ldns_buffer *output, 650 const ldns_rdf *rdf); 651 652/** 653 * Converts an LDNS_RDF_TYPE_AMTRELAY rdata element to presentation format for 654 * the precedence, D-bit, type and relay and adds it to the output buffer 655 * \param[in] *rdf The rdata to convert 656 * \param[in] *output The buffer to add the data to 657 * \return LDNS_STATUS_OK on success, and error status on failure 658 */ 659ldns_status ldns_rdf2buffer_str_amtrelay(ldns_buffer *output, 660 const ldns_rdf *rdf); 661 662/** 663 * Converts an LDNS_RDF_TYPE_SVCPARAMS rdata element to presentation format. 664 * \param[in] *rdf The rdata to convert 665 * \param[in] *output The buffer to add the data to 666 * \return LDNS_STATUS_OK on success, and error status on failure 667 */ 668ldns_status ldns_rdf2buffer_str_svcparams(ldns_buffer *output, 669 const ldns_rdf *rdf); 670 671/** 672 * Converts the data in the rdata field to presentation format and 673 * returns that as a char *. 674 * Remember to free it. 675 * 676 * \param[in] rdf The rdata field to convert 677 * \return null terminated char * data, or NULL on error 678 */ 679char *ldns_rdf2str(const ldns_rdf *rdf); 680 681/** 682 * Converts the data in the resource record to presentation format and 683 * returns that as a char *. 684 * Remember to free it. 685 * 686 * \param[in] rr The rdata field to convert 687 * \return null terminated char * data, or NULL on error 688 */ 689char *ldns_rr2str(const ldns_rr *rr); 690 691/** 692 * Converts the data in the resource record to presentation format and 693 * returns that as a char *. 694 * Remember to free it. 695 * 696 * \param[in] fmt how to format the resource record 697 * \param[in] rr The rdata field to convert 698 * \return null terminated char * data, or NULL on error 699 */ 700char *ldns_rr2str_fmt(const ldns_output_format *fmt, const ldns_rr *rr); 701 702/** 703 * Converts the data in the DNS packet to presentation format and 704 * returns that as a char *. 705 * Remember to free it. 706 * 707 * \param[in] pkt The rdata field to convert 708 * \return null terminated char * data, or NULL on error 709 */ 710char *ldns_pkt2str(const ldns_pkt *pkt); 711 712/** 713 * Converts the data in the DNS packet to presentation format and 714 * returns that as a char *. 715 * Remember to free it. 716 * 717 * \param[in] fmt how to format the packet 718 * \param[in] pkt The rdata field to convert 719 * \return null terminated char * data, or NULL on error 720 */ 721char *ldns_pkt2str_fmt(const ldns_output_format *fmt, const ldns_pkt *pkt); 722 723/** 724 * Converts a private key to the test presentation fmt and 725 * returns that as a char *. 726 * Remember to free it. 727 * 728 * \param[in] k the key to convert to text 729 * \return null terminated char * data, or NULL on error 730 */ 731char *ldns_key2str(const ldns_key *k); 732 733/** 734 * Converts a list of resource records to presentation format 735 * and returns that as a char *. 736 * Remember to free it. 737 * 738 * \param[in] rr_list the rr_list to convert to text 739 * \return null terminated char * data, or NULL on error 740 */ 741char *ldns_rr_list2str(const ldns_rr_list *rr_list); 742 743/** 744 * Converts a list of resource records to presentation format 745 * and returns that as a char *. 746 * Remember to free it. 747 * 748 * \param[in] fmt how to format the list of resource records 749 * \param[in] rr_list the rr_list to convert to text 750 * \return null terminated char * data, or NULL on error 751 */ 752char *ldns_rr_list2str_fmt( 753 const ldns_output_format *fmt, const ldns_rr_list *rr_list); 754 755/** 756 * Returns a copy of the data in the buffer as a null terminated 757 * char * string. The returned string must be freed by the caller. 758 * The buffer must be in write modus and may thus not have been flipped. 759 * 760 * \param[in] buffer buffer containing char * data 761 * \return null terminated char * data, or NULL on error 762 */ 763char *ldns_buffer2str(ldns_buffer *buffer); 764 765/** 766 * Exports and returns the data in the buffer as a null terminated 767 * char * string. The returned string must be freed by the caller. 768 * The buffer must be in write modus and may thus not have been flipped. 769 * The buffer is fixed after this function returns. 770 * 771 * \param[in] buffer buffer containing char * data 772 * \return null terminated char * data, or NULL on error 773 */ 774char *ldns_buffer_export2str(ldns_buffer *buffer); 775 776/** 777 * Prints the data in the rdata field to the given file stream 778 * (in presentation format) 779 * 780 * \param[in] output the file stream to print to 781 * \param[in] rdf the rdata field to print 782 * \return void 783 */ 784void ldns_rdf_print(FILE *output, const ldns_rdf *rdf); 785 786/** 787 * Prints the data in the resource record to the given file stream 788 * (in presentation format) 789 * 790 * \param[in] output the file stream to print to 791 * \param[in] rr the resource record to print 792 * \return void 793 */ 794void ldns_rr_print(FILE *output, const ldns_rr *rr); 795 796/** 797 * Prints the data in the resource record to the given file stream 798 * (in presentation format) 799 * 800 * \param[in] output the file stream to print to 801 * \param[in] fmt format of the textual representation 802 * \param[in] rr the resource record to print 803 * \return void 804 */ 805void ldns_rr_print_fmt(FILE *output, 806 const ldns_output_format *fmt, const ldns_rr *rr); 807 808/** 809 * Prints the data in the DNS packet to the given file stream 810 * (in presentation format) 811 * 812 * \param[in] output the file stream to print to 813 * \param[in] pkt the packet to print 814 * \return void 815 */ 816void ldns_pkt_print(FILE *output, const ldns_pkt *pkt); 817 818/** 819 * Prints the data in the DNS packet to the given file stream 820 * (in presentation format) 821 * 822 * \param[in] output the file stream to print to 823 * \param[in] fmt format of the textual representation 824 * \param[in] pkt the packet to print 825 * \return void 826 */ 827void ldns_pkt_print_fmt(FILE *output, 828 const ldns_output_format *fmt, const ldns_pkt *pkt); 829 830/** 831 * Converts a rr_list to presentation format and appends it to 832 * the output buffer 833 * \param[in] output the buffer to append output to 834 * \param[in] list the ldns_rr_list to print 835 * \return ldns_status 836 */ 837ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list); 838 839/** 840 * Converts a rr_list to presentation format and appends it to 841 * the output buffer 842 * \param[in] output the buffer to append output to 843 * \param[in] fmt format of the textual representation 844 * \param[in] list the ldns_rr_list to print 845 * \return ldns_status 846 */ 847ldns_status ldns_rr_list2buffer_str_fmt(ldns_buffer *output, 848 const ldns_output_format *fmt, const ldns_rr_list *list); 849 850/** 851 * Converts the header of a packet to presentation format and appends it to 852 * the output buffer 853 * \param[in] output the buffer to append output to 854 * \param[in] pkt the packet to convert the header of 855 * \return ldns_status 856 */ 857ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt); 858 859/** 860 * print a rr_list to output 861 * \param[in] output the fd to print to 862 * \param[in] list the rr_list to print 863 */ 864void ldns_rr_list_print(FILE *output, const ldns_rr_list *list); 865 866/** 867 * print a rr_list to output 868 * \param[in] output the fd to print to 869 * \param[in] fmt format of the textual representation 870 * \param[in] list the rr_list to print 871 */ 872void ldns_rr_list_print_fmt(FILE *output, 873 const ldns_output_format *fmt, const ldns_rr_list *list); 874 875/** 876 * Print a resolver (in sofar that is possible) state 877 * to output. 878 * \param[in] output the fd to print to 879 * \param[in] r the resolver to print 880 */ 881void ldns_resolver_print(FILE *output, const ldns_resolver *r); 882 883/** 884 * Print a resolver (in sofar that is possible) state 885 * to output. 886 * \param[in] output the fd to print to 887 * \param[in] fmt format of the textual representation 888 * \param[in] r the resolver to print 889 */ 890void ldns_resolver_print_fmt(FILE *output, 891 const ldns_output_format *fmt, const ldns_resolver *r); 892 893/** 894 * Print a zone structure * to output. Note the SOA record 895 * is included in this output 896 * \param[in] output the fd to print to 897 * \param[in] z the zone to print 898 */ 899void ldns_zone_print(FILE *output, const ldns_zone *z); 900 901/** 902 * Print a zone structure * to output. Note the SOA record 903 * is included in this output 904 * \param[in] output the fd to print to 905 * \param[in] fmt format of the textual representation 906 * \param[in] z the zone to print 907 */ 908void ldns_zone_print_fmt(FILE *output, 909 const ldns_output_format *fmt, const ldns_zone *z); 910 911/** 912 * Print the ldns_rdf containing a dname to the buffer 913 * \param[in] output the buffer to print to 914 * \param[in] dname the dname to print 915 * \return ldns_status message if the printing succeeded 916 */ 917ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname); 918 919#ifdef __cplusplus 920} 921#endif 922 923#endif /* LDNS_HOST2STR_H */ 924