2 * host2str.h - txt presentation of RRs
4 * a Net::DNS like library for C
6 * (c) NLnet Labs, 2005-2006
8 * See the file LICENSE for the license
14 * Contains functions to translate the main structures to their text
15 * representation, as well as functions to print them.
18 #ifndef LDNS_HOST2STR_H
19 #define LDNS_HOST2STR_H
21 #include <ldns/common.h>
22 #include <ldns/error.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>
31 #include "ldns/util.h"
37 #define LDNS_APL_IP4 1
38 #define LDNS_APL_IP6 2
39 #define LDNS_APL_MASK 0x7f
40 #define LDNS_APL_NEGATION 0x80
43 * Converts an ldns packet opcode value to its mnemonic, and adds that
44 * to the output buffer
45 * \param[in] *output the buffer to add the data to
46 * \param[in] opcode to find the string representation of
47 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
50 ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode);
53 * Converts an ldns packet rcode value to its mnemonic, and adds that
54 * to the output buffer
55 * \param[in] *output the buffer to add the data to
56 * \param[in] rcode to find the string representation of
57 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
60 ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode);
63 * Converts an ldns algorithm type to its mnemonic, and adds that
64 * to the output buffer
65 * \param[in] *output the buffer to add the data to
66 * \param[in] algorithm to find the string representation of
67 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
70 ldns_algorithm2buffer_str(ldns_buffer *output,
71 ldns_algorithm algorithm);
74 * Converts an ldns certificate algorithm type to its mnemonic,
75 * and adds that to the output buffer
76 * \param[in] *output the buffer to add the data to
77 * \param[in] cert_algorithm to find the string representation of
78 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
81 ldns_cert_algorithm2buffer_str(ldns_buffer *output,
82 ldns_cert_algorithm cert_algorithm);
86 * Converts a packet opcode to its mnemonic and returns that as
87 * an allocated null-terminated string.
88 * Remember to free it.
90 * \param[in] opcode the opcode to convert to text
91 * \return null terminated char * data, or NULL on error
93 char *ldns_pkt_opcode2str(ldns_pkt_opcode opcode);
96 * Converts a packet rcode to its mnemonic and returns that as
97 * an allocated null-terminated string.
98 * Remember to free it.
100 * \param[in] rcode the rcode to convert to text
101 * \return null terminated char * data, or NULL on error
103 char *ldns_pkt_rcode2str(ldns_pkt_rcode rcode);
106 * Converts a signing algorithms to its mnemonic and returns that as
107 * an allocated null-terminated string.
108 * Remember to free it.
110 * \param[in] algorithm the algorithm to convert to text
111 * \return null terminated char * data, or NULL on error
113 char *ldns_pkt_algorithm2str(ldns_algorithm algorithm);
116 * Converts a cert algorithm to its mnemonic and returns that as
117 * an allocated null-terminated string.
118 * Remember to free it.
120 * \param[in] cert_algorithm to convert to text
121 * \return null terminated char * data, or NULL on error
123 char *ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm);
126 * Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer
127 * \param[in] *rdf The rdata to convert
128 * \param[in] *output The buffer to add the data to
129 * \return LDNS_STATUS_OK on success, and error status on failure
131 ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf);
134 * Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer
135 * \param[in] *rdf The rdata to convert
136 * \param[in] *output The buffer to add the data to
137 * \return LDNS_STATUS_OK on success, and error status on failure
139 ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf);
142 * Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer
143 * \param[in] *rdf The rdata to convert
144 * \param[in] *output The buffer to add the data to
145 * \return LDNS_STATUS_OK on success, and error status on failure
147 ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf);
150 * Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer
151 * \param[in] *rdf The rdata to convert
152 * \param[in] *output The buffer to add the data to
153 * \return LDNS_STATUS_OK on success, and error status on failure
155 ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf);
158 * Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer
159 * \param[in] *rdf The rdata to convert
160 * \param[in] *output The buffer to add the data to
161 * \return LDNS_STATUS_OK on success, and error status on failure
163 ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf);
166 * Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer
167 * \param[in] *rdf The rdata to convert
168 * \param[in] *output The buffer to add the data to
169 * \return LDNS_STATUS_OK on success, and error status on failure
171 ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf);
174 * Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer
175 * \param[in] *rdf The rdata to convert
176 * \param[in] *output The buffer to add the data to
177 * \return LDNS_STATUS_OK on success, and error status on failure
179 ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf);
182 * Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer
183 * \param[in] *rdf The rdata to convert
184 * \param[in] *output The buffer to add the data to
185 * \return LDNS_STATUS_OK on success, and error status on failure
187 ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf);
190 * Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer
191 * \param[in] *rdf The rdata to convert
192 * \param[in] *output The buffer to add the data to
193 * \return LDNS_STATUS_OK on success, and error status on failure
195 ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf);
198 * Converts an ldns_rr_type value to its string representation,
199 * and places it in the given buffer
200 * \param[in] *output The buffer to add the data to
201 * \param[in] type the ldns_rr_type to convert
202 * \return LDNS_STATUS_OK on success, and error status on failure
204 ldns_status ldns_rr_type2buffer_str(ldns_buffer *output,
205 const ldns_rr_type type);
208 * Converts an ldns_rr_type value to its string representation,
209 * and returns that string. For unknown types, the string
210 * "TYPE<id>" is returned. This function allocates data that must be
211 * freed by the caller
212 * \param[in] type the ldns_rr_type to convert
213 * \return a newly allocated string
215 char *ldns_rr_type2str(const ldns_rr_type type);
218 * Converts an ldns_rr_class value to its string representation,
219 * and places it in the given buffer
220 * \param[in] *output The buffer to add the data to
221 * \param[in] klass the ldns_rr_class to convert
222 * \return LDNS_STATUS_OK on success, and error status on failure
224 ldns_status ldns_rr_class2buffer_str(ldns_buffer *output,
225 const ldns_rr_class klass);
228 * Converts an ldns_rr_class value to its string representation,
229 * and returns that string. For unknown types, the string
230 * "CLASS<id>" is returned. This function allocates data that must be
231 * freed by the caller
232 * \param[in] klass the ldns_rr_class to convert
233 * \return a newly allocated string
235 char *ldns_rr_class2str(const ldns_rr_class klass);
239 * Converts an LDNS_RDF_TYPE_CERT rdata element to string format and adds it to the output buffer
240 * \param[in] *rdf The rdata to convert
241 * \param[in] *output The buffer to add the data to
242 * \return LDNS_STATUS_OK on success, and error status on failure
244 ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf);
247 * Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer
248 * \param[in] *rdf The rdata to convert
249 * \param[in] *output The buffer to add the data to
250 * \return LDNS_STATUS_OK on success, and error status on failure
252 ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf);
255 * Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer
256 * \param[in] *rdf The rdata to convert
257 * \param[in] *output The buffer to add the data to
258 * \return LDNS_STATUS_OK on success, and error status on failure
260 ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf);
263 * Converts an LDNS_RDF_TYPE_NSAP 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
268 ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf);
271 * Converts an LDNS_RDF_TYPE_ATMA 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
276 ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf);
279 * Converts an LDNS_RDF_TYPE_WKS 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
284 ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf);
287 * Converts an LDNS_RDF_TYPE_NSEC 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
292 ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf);
295 * Converts an LDNS_RDF_TYPE_PERIOD 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
300 ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf);
303 * Converts an LDNS_RDF_TYPE_TSIGTIME 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
308 ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf);
311 * Converts an LDNS_RDF_TYPE_APL 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
316 ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf);
319 * Converts an LDNS_RDF_TYPE_INT16_DATA 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
324 ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf);
327 * Converts an LDNS_RDF_TYPE_IPSECKEY 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
332 ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf);
335 * Converts an LDNS_RDF_TYPE_TSIG rdata element to string format and adds it to the output buffer
336 * \param[in] *rdf The rdata to convert
337 * \param[in] *output The buffer to add the data to
338 * \return LDNS_STATUS_OK on success, and error status on failure
340 ldns_status ldns_rdf2buffer_str_tsig(ldns_buffer *output, const ldns_rdf *rdf);
344 * Converts the data in the rdata field to presentation
345 * format (as char *) and appends it to the given buffer
347 * \param[in] output pointer to the buffer to append the data to
348 * \param[in] rdf the pointer to the rdafa field containing the data
351 ldns_status ldns_rdf2buffer_str(ldns_buffer *output, const ldns_rdf *rdf);
354 * Converts the data in the resource record to presentation
355 * format (as char *) and appends it to the given buffer
357 * \param[in] output pointer to the buffer to append the data to
358 * \param[in] rr the pointer to the rr field to convert
361 ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr);
364 * Converts the data in the DNS packet to presentation
365 * format (as char *) and appends it to the given buffer
367 * \param[in] output pointer to the buffer to append the data to
368 * \param[in] pkt the pointer to the packet to convert
371 ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
374 * Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer
375 * \param[in] *rdf The rdata to convert
376 * \param[in] *output The buffer to add the data to
377 * \return LDNS_STATUS_OK on success, and error status on failure
379 ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf);
383 * Converts the data in the DNS packet to presentation
384 * format (as char *) and appends it to the given buffer
386 * \param[in] output pointer to the buffer to append the data to
387 * \param[in] k the pointer to the private key to convert
390 ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k);
393 * Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer
394 * \param[in] *rdf The rdata to convert
395 * \param[in] *output The buffer to add the data to
396 * \return LDNS_STATUS_OK on success, and error status on failure
398 ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf);
401 * Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer
402 * \param[in] *rdf The rdata to convert
403 * \param[in] *output The buffer to add the data to
404 * \return LDNS_STATUS_OK on success, and error status on failure
406 ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf);
409 * Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer
410 * \param[in] *rdf The rdata to convert
411 * \param[in] *output The buffer to add the data to
412 * \return LDNS_STATUS_OK on success, and error status on failure
414 ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf);
417 * Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer
418 * \param[in] *rdf The rdata to convert
419 * \param[in] *output The buffer to add the data to
420 * \return LDNS_STATUS_OK on success, and error status on failure
422 ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf);
425 * Converts the data in the rdata field to presentation format and
426 * returns that as a char *.
427 * Remember to free it.
429 * \param[in] rdf The rdata field to convert
430 * \return null terminated char * data, or NULL on error
432 char *ldns_rdf2str(const ldns_rdf *rdf);
435 * Converts the data in the resource record to presentation format and
436 * returns that as a char *.
437 * Remember to free it.
439 * \param[in] rr The rdata field to convert
440 * \return null terminated char * data, or NULL on error
442 char *ldns_rr2str(const ldns_rr *rr);
445 * Converts the data in the DNS packet to presentation format and
446 * returns that as a char *.
447 * Remember to free it.
449 * \param[in] pkt The rdata field to convert
450 * \return null terminated char * data, or NULL on error
452 char *ldns_pkt2str(const ldns_pkt *pkt);
455 * Converts a private key to the test presentation fmt and
456 * returns that as a char *.
457 * Remember to free it.
459 * \param[in] k the key to convert to text
460 * \return null terminated char * data, or NULL on error
462 char *ldns_key2str(const ldns_key *k);
465 * Converts a list of resource records to presentation format
466 * and returns that as a char *.
467 * Remember to free it.
469 * \param[in] rr_list the rr_list to convert to text
470 * \return null terminated char * data, or NULL on error
472 char *ldns_rr_list2str(const ldns_rr_list *rr_list);
475 * Returns the data in the buffer as a null terminated char * string
476 * Buffer data must be char * type, and must be freed by the caller
478 * \param[in] buffer buffer containing char * data
479 * \return null terminated char * data, or NULL on error
481 char *ldns_buffer2str(ldns_buffer *buffer);
484 * Prints the data in the rdata field to the given file stream
485 * (in presentation format)
487 * \param[in] output the file stream to print to
488 * \param[in] rdf the rdata field to print
491 void ldns_rdf_print(FILE *output, const ldns_rdf *rdf);
494 * Prints the data in the resource record to the given file stream
495 * (in presentation format)
497 * \param[in] output the file stream to print to
498 * \param[in] rr the resource record to print
501 void ldns_rr_print(FILE *output, const ldns_rr *rr);
504 * Prints the data in the DNS packet to the given file stream
505 * (in presentation format)
507 * \param[in] output the file stream to print to
508 * \param[in] pkt the packet to print
511 void ldns_pkt_print(FILE *output, const ldns_pkt *pkt);
514 * Converts a rr_list to presentation format and appends it to
516 * \param[in] output the buffer to append output to
517 * \param[in] list the ldns_rr_list to print
518 * \return ldns_status
520 ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list);
523 * Converts the header of a packet to presentation format and appends it to
525 * \param[in] output the buffer to append output to
526 * \param[in] pkt the packet to convert the header of
527 * \return ldns_status
529 ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
532 * print a rr_list to output
533 * param[in] output the fd to print to
534 * param[in] list the rr_list to print
536 void ldns_rr_list_print(FILE *output, const ldns_rr_list *list);
539 * Print a resolver (in sofar that is possible) state
541 * \param[in] output the fd to print to
542 * \param[in] r the resolver to print
544 void ldns_resolver_print(FILE *output, const ldns_resolver *r);
547 * Print a zone structure * to output. Note the SOA record
548 * is included in this output
549 * \param[in] output the fd to print to
550 * \param[in] z the zone to print
552 void ldns_zone_print(FILE *output, const ldns_zone *z);
555 * Print the ldns_rdf containing a dname to the buffer
556 * \param[in] output the buffer to print to
557 * \param[in] dname the dname to print
558 * \return ldns_status message if the printing succeeded
560 ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname);
566 #endif /* LDNS_HOST2STR_H */