2 * host2wire.h - 2wire conversion routines
4 * a Net::DNS like library for C
6 * (c) NLnet Labs, 2005-2006
8 * See the file LICENSE for the license
14 * Contains all functions to translate the main structures to wire format
17 #ifndef LDNS_HOST2WIRE_H
18 #define LDNS_HOST2WIRE_H
20 #include <ldns/common.h>
21 #include <ldns/error.h>
23 #include <ldns/rdata.h>
24 #include <ldns/packet.h>
25 #include <ldns/buffer.h>
28 #include "ldns/util.h"
35 * Copies the dname data to the buffer in wire format
36 * \param[out] *buffer buffer to append the result to
37 * \param[in] *name rdata dname to convert
40 ldns_status ldns_dname2buffer_wire(ldns_buffer *buffer, const ldns_rdf *name);
43 * Copies the dname data to the buffer in wire format
44 * \param[out] *buffer buffer to append the result to
45 * \param[in] *name rdata dname to convert
46 * \param[out] *compression_data data structure holding state for compression
49 ldns_status ldns_dname2buffer_wire_compress(ldns_buffer *buffer, const ldns_rdf *name, ldns_rbtree_t *compression_data);
52 * Copies the rdata data to the buffer in wire format
53 * \param[out] *output buffer to append the result to
54 * \param[in] *rdf rdata to convert
57 ldns_status ldns_rdf2buffer_wire(ldns_buffer *output, const ldns_rdf *rdf);
60 * Copies the rdata data to the buffer in wire format
61 * \param[out] *output buffer to append the result to
62 * \param[in] *rdf rdata to convert
63 * \param[out] *compression_data data structure holding state for compression
66 ldns_status ldns_rdf2buffer_wire_compress(ldns_buffer *output, const ldns_rdf *rdf, ldns_rbtree_t *compression_data);
69 * Copies the rdata data to the buffer in wire format
70 * If the rdata is a dname, the letters will be lowercased
71 * during the conversion
72 * \param[out] *output buffer to append the result to
73 * \param[in] *rdf rdata to convert
76 ldns_status ldns_rdf2buffer_wire_canonical(ldns_buffer *output,
80 * Copies the rr data to the buffer in wire format
81 * \param[out] *output buffer to append the result to
82 * \param[in] *rr resource record to convert
83 * \param[in] section the section in the packet this rr is supposed to be in
84 * (to determine whether to add rdata or not)
87 ldns_status ldns_rr2buffer_wire(ldns_buffer *output,
92 * Copies the rr data to the buffer in wire format while doing DNAME compression
93 * \param[out] *output buffer to append the result to
94 * \param[in] *rr resource record to convert
95 * \param[in] section the section in the packet this rr is supposed to be in
96 * (to determine whether to add rdata or not)
97 * \param[out] *compression_data data structure holding state information for compression
100 ldns_status ldns_rr2buffer_wire_compress(ldns_buffer *output,
103 ldns_rbtree_t *compression_data);
106 * Copies the rr data to the buffer in wire format, in canonical format
107 * according to RFC3597 (every dname in rdata fields of RR's mentioned in
108 * that RFC will be lowercased)
109 * \param[out] *output buffer to append the result to
110 * \param[in] *rr resource record to convert
111 * \param[in] section the section in the packet this rr is supposed to be in
112 * (to determine whether to add rdata or not)
113 * \return ldns_status
115 ldns_status ldns_rr2buffer_wire_canonical(ldns_buffer *output,
121 * Converts a rrsig to wireformat BUT EXCLUDE the rrsig rdata
122 * This is needed in DNSSEC verification
123 * \param[out] output buffer to append the result to
124 * \param[in] sigrr signature rr to operate on
125 * \return ldns_status
127 ldns_status ldns_rrsig2buffer_wire(ldns_buffer *output, const ldns_rr *sigrr);
130 * Converts an rr's rdata to wireformat, while excluding
131 * the ownername and all the stuff before the rdata.
132 * This is needed in DNSSEC keytag calculation, the ds
133 * calcalution from the key and maybe elsewhere.
135 * \param[out] *output buffer where to put the result
136 * \param[in] *rr rr to operate on
137 * \return ldns_status
139 ldns_status ldns_rr_rdata2buffer_wire(ldns_buffer *output, const ldns_rr *rr);
142 * Copies the packet data to the buffer in wire format
143 * \param[out] *output buffer to append the result to
144 * \param[in] *pkt packet to convert
145 * \return ldns_status
147 ldns_status ldns_pkt2buffer_wire(ldns_buffer *output, const ldns_pkt *pkt);
150 * Copies the rr_list data to the buffer in wire format
151 * \param[out] *output buffer to append the result to
152 * \param[in] *rrlist rr_list to to convert
153 * \return ldns_status
155 ldns_status ldns_rr_list2buffer_wire(ldns_buffer *output, const ldns_rr_list *rrlist);
158 * Allocates an array of uint8_t at dest, and puts the wireformat of the
159 * given rdf in that array. The result_size value contains the
160 * length of the array, if it succeeds, and 0 otherwise (in which case
161 * the function also returns NULL)
163 * \param[out] dest pointer to the array of bytes to be created
164 * \param[in] rdf the rdata field to convert
165 * \param[out] size the size of the converted result
167 ldns_status ldns_rdf2wire(uint8_t **dest, const ldns_rdf *rdf, size_t *size);
170 * Allocates an array of uint8_t at dest, and puts the wireformat of the
171 * given rr in that array. The result_size value contains the
172 * length of the array, if it succeeds, and 0 otherwise (in which case
173 * the function also returns NULL)
175 * If the section argument is LDNS_SECTION_QUESTION, data like ttl and rdata
176 * are not put into the result
178 * \param[out] dest pointer to the array of bytes to be created
179 * \param[in] rr the rr to convert
180 * \param[in] section the rr section, determines how the rr is written.
181 * \param[out] size the size of the converted result
183 ldns_status ldns_rr2wire(uint8_t **dest, const ldns_rr *rr, int section, size_t *size);
186 * Allocates an array of uint8_t at dest, and puts the wireformat of the
187 * given packet in that array. The result_size value contains the
188 * length of the array, if it succeeds, and 0 otherwise (in which case
189 * the function also returns NULL)
191 ldns_status ldns_pkt2wire(uint8_t **dest, const ldns_pkt *p, size_t *size);
197 #endif /* LDNS_HOST2WIRE_H */