xref: /dragonfly/contrib/ldns/ldns/host2wire.h (revision 37de577a)
1 /*
2  * host2wire.h - 2wire conversion routines
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 all functions to translate the main structures to wire format
15  */
16 
17 #ifndef LDNS_HOST2WIRE_H
18 #define LDNS_HOST2WIRE_H
19 
20 #include <ldns/common.h>
21 #include <ldns/error.h>
22 #include <ldns/rr.h>
23 #include <ldns/rdata.h>
24 #include <ldns/packet.h>
25 #include <ldns/buffer.h>
26 #include <ctype.h>
27 
28 #include "ldns/util.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
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
38  * \return ldns_status
39  */
40 ldns_status ldns_dname2buffer_wire(ldns_buffer *buffer, const ldns_rdf *name);
41 
42 /**
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
47  * \return ldns_status
48  */
49 ldns_status ldns_dname2buffer_wire_compress(ldns_buffer *buffer, const ldns_rdf *name, ldns_rbtree_t *compression_data);
50 
51 /**
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
55  * \return ldns_status
56  */
57 ldns_status ldns_rdf2buffer_wire(ldns_buffer *output, const ldns_rdf *rdf);
58 
59 /**
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
64  * \return ldns_status
65  */
66 ldns_status ldns_rdf2buffer_wire_compress(ldns_buffer *output, const ldns_rdf *rdf, ldns_rbtree_t *compression_data);
67 
68 /**
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
74  * \return ldns_status
75  */
76 ldns_status ldns_rdf2buffer_wire_canonical(ldns_buffer *output,
77 								   const ldns_rdf *rdf);
78 
79 /**
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)
85  * \return ldns_status
86  */
87 ldns_status ldns_rr2buffer_wire(ldns_buffer *output,
88 						  const ldns_rr *rr,
89 						  int section);
90 
91 /**
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
98  * \return ldns_status
99  */
100 ldns_status ldns_rr2buffer_wire_compress(ldns_buffer *output,
101 						  const ldns_rr *rr,
102 						  int section,
103 						  ldns_rbtree_t *compression_data);
104 
105 /**
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
114  */
115 ldns_status ldns_rr2buffer_wire_canonical(ldns_buffer *output,
116 								  const ldns_rr *rr,
117 								  int section);
118 
119 
120 /**
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
126  */
127 ldns_status ldns_rrsig2buffer_wire(ldns_buffer *output, const ldns_rr *sigrr);
128 
129 /**
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.
134  *
135  * \param[out] *output buffer where to put the result
136  * \param[in] *rr rr to operate on
137  * \return ldns_status
138  */
139 ldns_status ldns_rr_rdata2buffer_wire(ldns_buffer *output, const ldns_rr *rr);
140 
141 /**
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
146  */
147 ldns_status ldns_pkt2buffer_wire(ldns_buffer *output, const ldns_pkt *pkt);
148 
149 /**
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
154  */
155 ldns_status ldns_rr_list2buffer_wire(ldns_buffer *output, const ldns_rr_list *rrlist);
156 
157 /**
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)
162  *
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
166  */
167 ldns_status ldns_rdf2wire(uint8_t **dest, const ldns_rdf *rdf, size_t *size);
168 
169 /**
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)
174  *
175  * If the section argument is LDNS_SECTION_QUESTION, data like ttl and rdata
176  * are not put into the result
177  *
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
182  */
183 ldns_status ldns_rr2wire(uint8_t **dest, const ldns_rr *rr, int section, size_t *size);
184 
185 /**
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)
190  */
191 ldns_status ldns_pkt2wire(uint8_t **dest, const ldns_pkt *p, size_t *size);
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif /* LDNS_HOST2WIRE_H */
198