1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
//! Modern strongly typed DNS record creation, parsing and mutation APIs.
use libc::{c_char, c_uint, c_void};
use crate::*;
unsafe extern "C" {
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_rec_type_tostr(r#type: ares_dns_rec_type_t) -> *const c_char;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_class_tostr(qclass: ares_dns_class_t) -> *const c_char;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_opcode_tostr(opcode: ares_dns_opcode_t) -> *const c_char;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_rr_key_tostr(key: ares_dns_rr_key_t) -> *const c_char;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_section_tostr(section: ares_dns_section_t) -> *const c_char;
/// # Safety
/// qclass must be writable and str must be a readable NUL-terminated class name.
pub fn ares_dns_class_fromstr(
qclass: *mut ares_dns_class_t,
r#str: *const c_char,
) -> ares_bool_t;
/// # Safety
/// qtype must be writable and str must be a readable NUL-terminated record type name.
pub fn ares_dns_rec_type_fromstr(
qtype: *mut ares_dns_rec_type_t,
r#str: *const c_char,
) -> ares_bool_t;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_rcode_tostr(rcode: ares_dns_rcode_t) -> *const c_char;
/// # Safety
/// ipaddr must be NUL-terminated and addr initialized with a valid family. addr and out_len
/// must be writable. Any result borrows address storage inside addr.
pub fn ares_dns_pton(
ipaddr: *const c_char,
addr: *mut ares_addr,
out_len: *mut usize,
) -> *const c_void;
/// # Safety
/// addr must be readable and initialized for its family. A non-null returned string is owned
/// and must be released once with ares_free_string.
pub fn ares_dns_addr_to_ptr(addr: *const ares_addr) -> *mut c_char;
/// # Safety
/// Only integer value inputs are used; no pointer or ownership prerequisites apply.
pub fn ares_dns_opt_get_datatype(key: ares_dns_rr_key_t, opt: u16) -> ares_dns_opt_datatype_t;
/// # Safety
/// Any non-null returned name is static read-only storage and must not be freed or modified.
pub fn ares_dns_opt_get_name(key: ares_dns_rr_key_t, opt: u16) -> *const c_char;
/// # Safety
/// cnt must be writable. The returned key array is static storage; read only its reported
/// length and never free or modify it.
pub fn ares_dns_rr_get_keys(
r#type: ares_dns_rec_type_t,
cnt: *mut usize,
) -> *const ares_dns_rr_key_t;
/// # Safety
/// Only integer value inputs are used; no pointer or ownership prerequisites apply.
pub fn ares_dns_rr_key_datatype(key: ares_dns_rr_key_t) -> ares_dns_datatype_t;
/// # Safety
/// Only integer value inputs are used; no pointer or ownership prerequisites apply.
pub fn ares_dns_rr_key_to_rec_type(key: ares_dns_rr_key_t) -> ares_dns_rec_type_t;
/// # Safety
/// dnsrec must be writable. On success the returned record is exclusively owned and must be
/// destroyed once with ares_dns_record_destroy.
pub fn ares_dns_record_create(
dnsrec: *mut *mut ares_dns_record_t,
id: u16,
flags: u16,
opcode: ares_dns_opcode_t,
rcode: ares_dns_rcode_t,
) -> ares_status_t;
/// # Safety
/// dnsrec must be null or a live exclusively owned record. Invalidate every borrowed question,
/// RR, string, and binary slice before destroying it.
pub fn ares_dns_record_destroy(dnsrec: *mut ares_dns_record_t);
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_get_id(dnsrec: *const ares_dns_record_t) -> u16;
/// # Safety
/// dnsrec must be a live record with exclusive access during mutation.
pub fn ares_dns_record_set_id(dnsrec: *mut ares_dns_record_t, id: u16) -> ares_bool_t;
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_get_flags(dnsrec: *const ares_dns_record_t) -> u16;
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_get_opcode(dnsrec: *const ares_dns_record_t) -> ares_dns_opcode_t;
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_get_rcode(dnsrec: *const ares_dns_record_t) -> ares_dns_rcode_t;
/// # Safety
/// dnsrec must be live and exclusively accessible; name must be NUL-terminated. Mutation may
/// invalidate borrowed question data.
pub fn ares_dns_record_query_add(
dnsrec: *mut ares_dns_record_t,
name: *const c_char,
qtype: ares_dns_rec_type_t,
qclass: ares_dns_class_t,
) -> ares_status_t;
/// # Safety
/// dnsrec must be live and exclusively accessible; name must be NUL-terminated. Do not retain
/// a previous borrowed question name across this mutation.
pub fn ares_dns_record_query_set_name(
dnsrec: *mut ares_dns_record_t,
idx: usize,
name: *const c_char,
) -> ares_status_t;
/// # Safety
/// dnsrec must be live and exclusively accessible. Existing question borrows must not overlap
/// this mutation.
pub fn ares_dns_record_query_set_type(
dnsrec: *mut ares_dns_record_t,
idx: usize,
qtype: ares_dns_rec_type_t,
) -> ares_status_t;
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_query_cnt(dnsrec: *const ares_dns_record_t) -> usize;
/// # Safety
/// dnsrec must be live. Each non-null output slot must be writable; a returned name borrows
/// the record and must not outlive its next relevant mutation or destruction.
pub fn ares_dns_record_query_get(
dnsrec: *const ares_dns_record_t,
idx: usize,
name: *mut *const c_char,
qtype: *mut ares_dns_rec_type_t,
qclass: *mut ares_dns_class_t,
) -> ares_status_t;
/// # Safety
/// dnsrec must be a readable live record; do not race access with mutation or destruction.
pub fn ares_dns_record_rr_cnt(
dnsrec: *const ares_dns_record_t,
sect: ares_dns_section_t,
) -> usize;
/// # Safety
/// dnsrec must be live and exclusively accessible; rr_out must be writable and name NUL-
/// terminated. The returned RR borrows its parent section and is invalidated by section
/// addition/deletion or parent destruction.
pub fn ares_dns_record_rr_add(
rr_out: *mut *mut ares_dns_rr_t,
dnsrec: *mut ares_dns_record_t,
sect: ares_dns_section_t,
name: *const c_char,
r#type: ares_dns_rec_type_t,
rclass: ares_dns_class_t,
ttl: c_uint,
) -> ares_status_t;
/// # Safety
/// dnsrec must be live. The returned RR borrows the parent section; do not overlap mutable
/// access or retain it across section addition/deletion or parent destruction.
pub fn ares_dns_record_rr_get(
dnsrec: *mut ares_dns_record_t,
sect: ares_dns_section_t,
idx: usize,
) -> *mut ares_dns_rr_t;
/// # Safety
/// dnsrec must be live. The returned RR borrows the parent section; do not retain it across
/// section addition/deletion or parent destruction.
pub fn ares_dns_record_rr_get_const(
dnsrec: *const ares_dns_record_t,
sect: ares_dns_section_t,
idx: usize,
) -> *const ares_dns_rr_t;
/// # Safety
/// dnsrec must be live and exclusively accessible. All RR pointers borrowed from the affected
/// section are invalidated.
pub fn ares_dns_record_rr_del(
dnsrec: *mut ares_dns_record_t,
sect: ares_dns_section_t,
idx: usize,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live. A non-null result borrows the RR and must not be
/// modified, freed, or retained across relevant mutation or parent destruction.
pub fn ares_dns_rr_get_name(rr: *const ares_dns_rr_t) -> *const c_char;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_type(rr: *const ares_dns_rr_t) -> ares_dns_rec_type_t;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_class(rr: *const ares_dns_rr_t) -> ares_dns_class_t;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_ttl(rr: *const ares_dns_rr_t) -> c_uint;
/// # Safety
/// dns_rr must be live with exclusive access and key must select an IPv4 field. addr must hold
/// a readable in_addr; do not retain previous borrows of changed data.
pub fn ares_dns_rr_set_addr(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
addr: *const libc::in_addr,
) -> ares_status_t;
/// # Safety
/// dns_rr must be live with exclusive access and key must select an IPv6 field. addr must hold
/// a readable ares_in6_addr; release previous borrows of changed data.
pub fn ares_dns_rr_set_addr6(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
addr: *const ares_in6_addr,
) -> ares_status_t;
/// # Safety
/// dns_rr must be live with exclusive access and key must select a string/name field. val must
/// be NUL-terminated; mutation invalidates prior borrows of that field.
pub fn ares_dns_rr_set_str(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: *const c_char,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live with exclusive access. Use a key matching the field
/// datatype; mutation may invalidate existing field borrows.
pub fn ares_dns_rr_set_u8(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: u8,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live with exclusive access. Use a key matching the field
/// datatype; mutation may invalidate existing field borrows.
pub fn ares_dns_rr_set_u16(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: u16,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live with exclusive access. Use a key matching the field
/// datatype; mutation may invalidate existing field borrows.
pub fn ares_dns_rr_set_u32(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: c_uint,
) -> ares_status_t;
/// # Safety
/// dns_rr must be live with exclusive access and key must select a binary field. val must
/// cover len readable bytes, unless len is zero and val is null. Mutation invalidates prior
/// field borrows.
pub fn ares_dns_rr_set_bin(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: *const u8,
len: usize,
) -> ares_status_t;
/// # Safety
/// dns_rr must be live with exclusive access and key must select a binary-array field. val
/// must cover len readable bytes, unless len is zero and val is null; array borrows may be
/// invalidated.
pub fn ares_dns_rr_add_abin(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
val: *const u8,
len: usize,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live with exclusive access. Use a key matching the field
/// datatype; mutation may invalidate existing field borrows.
pub fn ares_dns_rr_del_abin(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
idx: usize,
) -> ares_status_t;
/// # Safety
/// dns_rr must be live with exclusive access and key must select options. val must cover
/// val_len readable bytes, unless the length is zero and val is null. Mutation may invalidate
/// borrowed option data.
pub fn ares_dns_rr_set_opt(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
opt: u16,
val: *const u8,
val_len: usize,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live with exclusive access. Use a key matching the field
/// datatype; mutation may invalidate existing field borrows.
pub fn ares_dns_rr_del_opt_byid(
dns_rr: *mut ares_dns_rr_t,
key: ares_dns_rr_key_t,
opt: u16,
) -> ares_status_t;
/// # Safety
/// The RR and its parent must remain live. A non-null result borrows the RR and must not be
/// modified, freed, or retained across relevant mutation or parent destruction.
pub fn ares_dns_rr_get_addr(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
) -> *const libc::in_addr;
/// # Safety
/// The RR and its parent must remain live. A non-null result borrows the RR and must not be
/// modified, freed, or retained across relevant mutation or parent destruction.
pub fn ares_dns_rr_get_addr6(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
) -> *const ares_in6_addr;
/// # Safety
/// The RR and its parent must remain live. A non-null result borrows the RR and must not be
/// modified, freed, or retained across relevant mutation or parent destruction.
pub fn ares_dns_rr_get_str(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
) -> *const c_char;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_u8(dns_rr: *const ares_dns_rr_t, key: ares_dns_rr_key_t) -> u8;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_u16(dns_rr: *const ares_dns_rr_t, key: ares_dns_rr_key_t) -> u16;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_u32(dns_rr: *const ares_dns_rr_t, key: ares_dns_rr_key_t) -> c_uint;
/// # Safety
/// dns_rr must be live, key must select binary data, and len must be writable. A non-null
/// result borrows the RR for the reported length until relevant mutation or destruction.
pub fn ares_dns_rr_get_bin(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
len: *mut usize,
) -> *const u8;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_abin_cnt(dns_rr: *const ares_dns_rr_t, key: ares_dns_rr_key_t) -> usize;
/// # Safety
/// dns_rr must be live, key must select a binary array, and len must be writable. A non-null
/// result borrows the RR for the reported length until array mutation or destruction.
pub fn ares_dns_rr_get_abin(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
idx: usize,
len: *mut usize,
) -> *const u8;
/// # Safety
/// The RR and its parent must remain live and readable; do not overlap access with mutation or
/// destruction.
pub fn ares_dns_rr_get_opt_cnt(dns_rr: *const ares_dns_rr_t, key: ares_dns_rr_key_t) -> usize;
/// # Safety
/// dns_rr must be live and key must select options. Non-null val and val_len output slots must
/// be writable; a returned value borrows the RR until relevant mutation or destruction.
pub fn ares_dns_rr_get_opt(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
idx: usize,
val: *mut *const u8,
val_len: *mut usize,
) -> u16;
/// # Safety
/// dns_rr must be live and key must select options. Non-null val and val_len output slots must
/// be writable; a returned value borrows the RR until relevant mutation or destruction.
pub fn ares_dns_rr_get_opt_byid(
dns_rr: *const ares_dns_rr_t,
key: ares_dns_rr_key_t,
opt: u16,
val: *mut *const u8,
val_len: *mut usize,
) -> ares_bool_t;
/// # Safety
/// buf must cover buf_len readable bytes and dnsrec must be writable. A successfully returned
/// record is owned and must be destroyed once with ares_dns_record_destroy.
pub fn ares_dns_parse(
buf: *const u8,
buf_len: usize,
flags: c_uint,
dnsrec: *mut *mut ares_dns_record_t,
) -> ares_status_t;
/// # Safety
/// dnsrec must be live; buf and buf_len must be writable output slots. A successfully returned
/// wire buffer is owned and must be freed once with ares_free_string.
pub fn ares_dns_write(
dnsrec: *const ares_dns_record_t,
buf: *mut *mut u8,
buf_len: *mut usize,
) -> ares_status_t;
/// # Safety
/// dnsrec must be null or a readable live record. Any non-null result is independently owned
/// and must be destroyed once with ares_dns_record_destroy.
pub fn ares_dns_record_duplicate(dnsrec: *const ares_dns_record_t) -> *mut ares_dns_record_t;
}