root/src/udns/udns.h

Revision c478b725380bce173a7b7f4582ecdbd588b7a24b, 25.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

fixes #70

  • Property mode set to 100644
Line 
1 /* $Id: udns.h,v 1.51 2007/01/15 21:19:08 mjt Exp $
2    header file for the UDNS library.
3
4    Copyright (C) 2005  Michael Tokarev <mjt@corpit.ru>
5    This file is part of UDNS library, an async DNS stub resolver.
6
7    This library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with this library, in file named COPYING.LGPL; if not,
19    write to the Free Software Foundation, Inc., 59 Temple Place,
20    Suite 330, Boston, MA  02111-1307  USA
21
22  */
23
24 #ifndef UDNS_VERSION    /* include guard */
25
26 #define UDNS_VERSION "0.0.9"
27
28 #ifdef WINDOWS
29 # ifdef UDNS_DYNAMIC_LIBRARY
30 #  ifdef DNS_LIBRARY_BUILD
31 #   define UDNS_API __declspec(dllexport)
32 #   define UDNS_DATA_API __declspec(dllexport)
33 #  else
34 #   define UDNS_API __declspec(dllimport)
35 #   define UDNS_DATA_API __declspec(dllimport)
36 #  endif
37 # endif
38 #endif
39
40 #ifndef UDNS_API
41 # define UDNS_API
42 #endif
43 #ifndef UDNS_DATA_API
44 # define UDNS_DATA_API
45 #endif
46
47 #include <sys/types.h>          /* for time_t */
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 /* forward declarations if sockets stuff isn't #include'd */
54 struct in_addr;
55 struct in6_addr;
56 struct sockaddr;
57
58 /**************************************************************************/
59 /**************** Common definitions **************************************/
60
61 UDNS_API const char *
62 dns_version(void);
63
64 struct dns_ctx;
65 struct dns_query;
66
67 /* shorthand for [const] unsigned char */
68 typedef unsigned char dnsc_t;
69 typedef const unsigned char dnscc_t;
70
71 #define DNS_MAXDN       255     /* max DN length */
72 #define DNS_DNPAD       1       /* padding for DN buffers */
73 #define DNS_MAXLABEL    63      /* max DN label length */
74 #define DNS_MAXNAME     1024    /* max asciiz domain name length */
75 #define DNS_HSIZE       12      /* DNS packet header size */
76 #define DNS_PORT        53      /* default domain port */
77 #define DNS_MAXSERV     6       /* max servers to consult */
78 #define DNS_MAXPACKET   512     /* max traditional-DNS UDP packet size */
79 #define DNS_EDNS0PACKET 4096    /* EDNS0 packet size to use */
80
81 enum dns_class {        /* DNS RR Classes */
82   DNS_C_INVALID = 0,    /* invalid class */
83   DNS_C_IN      = 1,    /* Internet */
84   DNS_C_CH      = 3,    /* CHAOS */
85   DNS_C_HS      = 4,    /* HESIOD */
86   DNS_C_ANY     = 255   /* wildcard */
87 };
88
89 enum dns_type {         /* DNS RR Types */
90   DNS_T_INVALID         = 0,    /* Cookie. */
91   DNS_T_A               = 1,    /* Host address. */
92   DNS_T_NS              = 2,    /* Authoritative server. */
93   DNS_T_MD              = 3,    /* Mail destination. */
94   DNS_T_MF              = 4,    /* Mail forwarder. */
95   DNS_T_CNAME           = 5,    /* Canonical name. */
96   DNS_T_SOA             = 6,    /* Start of authority zone. */
97   DNS_T_MB              = 7,    /* Mailbox domain name. */
98   DNS_T_MG              = 8,    /* Mail group member. */
99   DNS_T_MR              = 9,    /* Mail rename name. */
100   DNS_T_NULL            = 10,   /* Null resource record. */
101   DNS_T_WKS             = 11,   /* Well known service. */
102   DNS_T_PTR             = 12,   /* Domain name pointer. */
103   DNS_T_HINFO           = 13,   /* Host information. */
104   DNS_T_MINFO           = 14,   /* Mailbox information. */
105   DNS_T_MX              = 15,   /* Mail routing information. */
106   DNS_T_TXT             = 16,   /* Text strings. */
107   DNS_T_RP              = 17,   /* Responsible person. */
108   DNS_T_AFSDB           = 18,   /* AFS cell database. */
109   DNS_T_X25             = 19,   /* X_25 calling address. */
110   DNS_T_ISDN            = 20,   /* ISDN calling address. */
111   DNS_T_RT              = 21,   /* Router. */
112   DNS_T_NSAP            = 22,   /* NSAP address. */
113   DNS_T_NSAP_PTR        = 23,   /* Reverse NSAP lookup (deprecated). */
114   DNS_T_SIG             = 24,   /* Security signature. */
115   DNS_T_KEY             = 25,   /* Security key. */
116   DNS_T_PX              = 26,   /* X.400 mail mapping. */
117   DNS_T_GPOS            = 27,   /* Geographical position (withdrawn). */
118   DNS_T_AAAA            = 28,   /* Ip6 Address. */
119   DNS_T_LOC             = 29,   /* Location Information. */
120   DNS_T_NXT             = 30,   /* Next domain (security). */
121   DNS_T_EID             = 31,   /* Endpoint identifier. */
122   DNS_T_NIMLOC          = 32,   /* Nimrod Locator. */
123   DNS_T_SRV             = 33,   /* Server Selection. */
124   DNS_T_ATMA            = 34,   /* ATM Address */
125   DNS_T_NAPTR           = 35,   /* Naming Authority PoinTeR */
126   DNS_T_KX              = 36,   /* Key Exchange */
127   DNS_T_CERT            = 37,   /* Certification record */
128   DNS_T_A6              = 38,   /* IPv6 address (deprecates AAAA) */
129   DNS_T_DNAME           = 39,   /* Non-terminal DNAME (for IPv6) */
130   DNS_T_SINK            = 40,   /* Kitchen sink (experimentatl) */
131   DNS_T_OPT             = 41,   /* EDNS0 option (meta-RR) */
132   DNS_T_DS              = 43,   /* DNSSEC */
133   DNS_T_NSEC            = 47,   /* DNSSEC */
134   DNS_T_TSIG            = 250,  /* Transaction signature. */
135   DNS_T_IXFR            = 251,  /* Incremental zone transfer. */
136   DNS_T_AXFR            = 252,  /* Transfer zone of authority. */
137   DNS_T_MAILB           = 253,  /* Transfer mailbox records. */
138   DNS_T_MAILA           = 254,  /* Transfer mail agent records. */
139   DNS_T_ANY             = 255,  /* Wildcard match. */
140   DNS_T_ZXFR            = 256,  /* BIND-specific, nonstandard. */
141   DNS_T_MAX             = 65536
142 };
143
144 /**************************************************************************/
145 /**************** Domain Names (DNs) **************************************/
146
147 /* return length of the DN */
148 UDNS_API unsigned
149 dns_dnlen(dnscc_t *dn);
150
151 /* return #of labels in a DN */
152 UDNS_API unsigned
153 dns_dnlabels(dnscc_t *dn);
154
155 /* lower- and uppercase single DN char */
156 #define DNS_DNLC(c) ((c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 'a' : (c))
157 #define DNS_DNUC(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
158
159 /* compare the DNs, return dnlen of equal or 0 if not */
160 UDNS_API unsigned
161 dns_dnequal(dnscc_t *dn1, dnscc_t *dn2);
162
163 /* copy one DN to another, size checking */
164 UDNS_API unsigned
165 dns_dntodn(dnscc_t *sdn, dnsc_t *ddn, unsigned ddnsiz);
166
167 /* convert asciiz string of length namelen (0 to use strlen) to DN */
168 UDNS_API int
169 dns_ptodn(const char *name, unsigned namelen,
170           dnsc_t *dn, unsigned dnsiz, int *isabs);
171
172 /* simpler form of dns_ptodn() */
173 #define dns_sptodn(name,dn,dnsiz) dns_ptodn((name),0,(dn),(dnsiz),0)
174
175 UDNS_DATA_API extern dnscc_t dns_inaddr_arpa_dn[14];
176 #define DNS_A4RSIZE     30
177 UDNS_API int
178 dns_a4todn(const struct in_addr *addr, dnscc_t *tdn,
179            dnsc_t *dn, unsigned dnsiz);
180 UDNS_API int
181 dns_a4ptodn(const struct in_addr *addr, const char *tname,
182             dnsc_t *dn, unsigned dnsiz);
183 UDNS_API dnsc_t *
184 dns_a4todn_(const struct in_addr *addr, dnsc_t *dn, dnsc_t *dne);
185
186 UDNS_DATA_API extern dnscc_t dns_ip6_arpa_dn[10];
187 #define DNS_A6RSIZE     74
188 UDNS_API int
189 dns_a6todn(const struct in6_addr *addr, dnscc_t *tdn,
190            dnsc_t *dn, unsigned dnsiz);
191 UDNS_API int
192 dns_a6ptodn(const struct in6_addr *addr, const char *tname,
193             dnsc_t *dn, unsigned dnsiz);
194 UDNS_API dnsc_t *
195 dns_a6todn_(const struct in6_addr *addr, dnsc_t *dn, dnsc_t *dne);
196
197 /* convert DN into asciiz string */
198 UDNS_API int
199 dns_dntop(dnscc_t *dn, char *name, unsigned namesiz);
200
201 /* convert DN into asciiz string, using static buffer (NOT thread-safe!) */
202 UDNS_API const char *
203 dns_dntosp(dnscc_t *dn);
204
205 /* return buffer size (incl. null byte) required for asciiz form of a DN */
206 UDNS_API unsigned
207 dns_dntop_size(dnscc_t *dn);
208
209 /* either wrappers or reimplementations for inet_ntop() and inet_pton() */
210 UDNS_API const char *dns_ntop(int af, const void *src, char *dst, int size);
211 UDNS_API int dns_pton(int af, const char *src, void *dst);
212
213 /**************************************************************************/
214 /**************** DNS raw packet layout ***********************************/
215
216 enum dns_rcode {        /* reply codes */
217   DNS_R_NOERROR         = 0,    /* ok, no error */
218   DNS_R_FORMERR         = 1,    /* format error */
219   DNS_R_SERVFAIL        = 2,    /* server failed */
220   DNS_R_NXDOMAIN        = 3,    /* domain does not exists */
221   DNS_R_NOTIMPL         = 4,    /* not implemented */
222   DNS_R_REFUSED         = 5,    /* query refused */
223   /* these are for BIND_UPDATE */
224   DNS_R_YXDOMAIN        = 6,    /* Name exists */
225   DNS_R_YXRRSET         = 7,    /* RRset exists */
226   DNS_R_NXRRSET         = 8,    /* RRset does not exist */
227   DNS_R_NOTAUTH         = 9,    /* Not authoritative for zone */
228   DNS_R_NOTZONE         = 10,   /* Zone of record different from zone section */
229   /*ns_r_max = 11,*/
230   /* The following are TSIG extended errors */
231   DNS_R_BADSIG          = 16,
232   DNS_R_BADKEY          = 17,
233   DNS_R_BADTIME         = 18
234 };
235
236 static inline unsigned dns_get16(dnscc_t *s) {
237   return ((unsigned)s[0]<<8) | s[1];
238 }
239 static inline unsigned dns_get32(dnscc_t *s) {
240   return ((unsigned)s[0]<<24) | ((unsigned)s[1]<<16)
241         | ((unsigned)s[2]<<8) | s[3];
242 }
243 static inline dnsc_t *dns_put16(dnsc_t *d, unsigned n) {
244   *d++ = (dnsc_t)((n >> 8) & 255); *d++ = (dnsc_t)(n & 255); return d;
245 }
246 static inline dnsc_t *dns_put32(dnsc_t *d, unsigned n) {
247   *d++ = (dnsc_t)((n >> 24) & 255); *d++ = (dnsc_t)((n >> 16) & 255);
248   *d++ = (dnsc_t)((n >>  8) & 255); *d++ = (dnsc_t)(n & 255);
249   return d;
250 }
251
252 /* return pseudo-random 16bits number */
253 UDNS_API unsigned dns_random16(void);
254
255 /* DNS Header layout */
256 enum {
257  /* bytes 0:1 - query ID */
258   DNS_H_QID1    = 0,
259   DNS_H_QID2    = 1,
260   DNS_H_QID     = DNS_H_QID1,
261 #define dns_qid(pkt)    dns_get16((pkt)+DNS_H_QID)
262  /* byte 2: flags1 */
263   DNS_H_F1      = 2,
264   DNS_HF1_QR    = 0x80, /* query response flag */
265 #define dns_qr(pkt)     ((pkt)[DNS_H_F1]&DNS_HF1_QR)
266   DNS_HF1_OPCODE = 0x78, /* opcode, 0 = query */
267 #define dns_opcode(pkt) (((pkt)[DNS_H_F1]&DNS_HF1_OPCODE)>>3)
268   DNS_HF1_AA    = 0x04, /* auth answer */
269 #define dns_aa(pkt)     ((pkt)[DNS_H_F1]&DNS_HF1_AA)
270   DNS_HF1_TC    = 0x02, /* truncation flag */
271 #define dns_tc(pkt)     ((pkt)[DNS_H_F1]&DNS_HF1_TC)
272   DNS_HF1_RD    = 0x01, /* recursion desired (may be set in query) */
273 #define dns_rd(pkt)     ((pkt)[DNS_H_F1]&DNS_HF1_RD)
274  /* byte 3: flags2 */
275   DNS_H_F2      = 3,
276   DNS_HF2_RA    = 0x80, /* recursion available */
277 #define dns_ra(pkt)     ((pkt)[DNS_H_F2]&DNS_HF2_RA)
278   DNS_HF2_Z     = 0x70, /* reserved */
279   DNS_HF2_RCODE = 0x0f, /* response code, DNS_R_XXX above */
280 #define dns_rcode(pkt)  ((pkt)[DNS_H_F2]&DNS_HF2_RCODE)
281  /* bytes 4:5: qdcount, numqueries */
282   DNS_H_QDCNT1  = 4,
283   DNS_H_QDCNT2  = 5,
284   DNS_H_QDCNT   = DNS_H_QDCNT1,
285 #define dns_numqd(pkt)  dns_get16((pkt)+4)
286  /* bytes 6:7: ancount, numanswers */
287   DNS_H_ANCNT1  = 6,
288   DNS_H_ANCNT2  = 7,
289   DNS_H_ANCNT   = DNS_H_ANCNT1,
290 #define dns_numan(pkt)  dns_get16((pkt)+6)
291  /* bytes 8:9: nscount, numauthority */
292   DNS_H_NSCNT1  = 8,
293   DNS_H_NSCNT2  = 9,
294   DNS_H_NSCNT   = DNS_H_NSCNT1,
295 #define dns_numns(pkt)  dns_get16((pkt)+8)
296  /* bytes 10:11: arcount, numadditional */
297   DNS_H_ARCNT1  = 10,
298   DNS_H_ARCNT2  = 11,
299   DNS_H_ARCNT   = DNS_H_ARCNT1,
300 #define dns_numar(pkt)  dns_get16((pkt)+10)
301 #define dns_payload(pkt) ((pkt)+DNS_HSIZE)
302 };
303
304 /* packet buffer: start at pkt, end before pkte, current pos *curp.
305  * extract a DN and set *curp to the next byte after DN in packet.
306  * return -1 on error, 0 if dnsiz is too small, or dnlen on ok.
307  */
308 UDNS_API int
309 dns_getdn(dnscc_t *pkt, dnscc_t **curp, dnscc_t *end,
310           dnsc_t *dn, unsigned dnsiz);
311
312 /* skip the DN at position cur in packet ending before pkte,
313  * return pointer to the next byte after the DN or NULL on error */
314 UDNS_API dnscc_t *
315 dns_skipdn(dnscc_t *end, dnscc_t *cur);
316
317 struct dns_rr {         /* DNS Resource Record */
318   dnsc_t dnsrr_dn[DNS_MAXDN];   /* the DN of the RR */
319   enum dns_class dnsrr_cls;     /* Class */
320   enum dns_type  dnsrr_typ;     /* Type */
321   unsigned dnsrr_ttl;           /* Time-To-Live (TTL) */
322   unsigned dnsrr_dsz;           /* data size */
323   dnscc_t *dnsrr_dptr;          /* pointer to start of data */
324   dnscc_t *dnsrr_dend;          /* past end of data */
325 };
326
327 struct dns_parse {      /* RR/packet parsing state */
328   dnscc_t *dnsp_pkt;            /* start of the packet */
329   dnscc_t *dnsp_end;            /* end of the packet */
330   dnscc_t *dnsp_cur;            /* current packet position */
331   dnscc_t *dnsp_ans;            /* start of answer section */
332   int dnsp_rrl;                 /* number of RRs left to go */
333   int dnsp_nrr;                 /* RR count so far */
334   unsigned dnsp_ttl;            /* TTL value so far */
335   dnscc_t *dnsp_qdn;            /* the RR DN we're looking for */
336   enum dns_class dnsp_qcls;     /* RR class we're looking for or 0 */
337   enum dns_type  dnsp_qtyp;     /* RR type we're looking for or 0 */
338   dnsc_t dnsp_dnbuf[DNS_MAXDN]; /* domain buffer */
339 };
340
341 /* initialize the parse structure */
342 UDNS_API void
343 dns_initparse(struct dns_parse *p, dnscc_t *qdn,
344               dnscc_t *pkt, dnscc_t *cur, dnscc_t *end);
345
346 /* search next RR, <0=error, 0=no more RRs, >0 = found. */
347 UDNS_API int
348 dns_nextrr(struct dns_parse *p, struct dns_rr *rr);
349
350 UDNS_API void
351 dns_rewind(struct dns_parse *p, dnscc_t *qdn);
352
353
354 /**************************************************************************/
355 /**************** Resolver Context ****************************************/
356
357 /* default resolver context */
358 UDNS_DATA_API extern struct dns_ctx dns_defctx;
359
360 /* reset resolver context to default state, close it if open, drop queries */
361 UDNS_API void
362 dns_reset(struct dns_ctx *ctx);
363
364 /* reset resolver context and read in system configuration */
365 UDNS_API int
366 dns_init(struct dns_ctx *ctx, int do_open);
367
368 /* return new resolver context with the same settings as copy */
369 UDNS_API struct dns_ctx *
370 dns_new(const struct dns_ctx *copy);
371
372 /* free resolver context returned by dns_new(); all queries are dropped */
373 UDNS_API void
374 dns_free(struct dns_ctx *ctx);
375
376 /* add nameserver for a resolver context (or reset nslist if serv==NULL) */
377 UDNS_API int
378 dns_add_serv(struct dns_ctx *ctx, const char *serv);
379
380 /* add nameserver using struct sockaddr structure (with ports) */
381 UDNS_API int
382 dns_add_serv_s(struct dns_ctx *ctx, const struct sockaddr *sa);
383
384 /* add search list element for a resolver context (or reset it if srch==NULL) */
385 UDNS_API int
386 dns_add_srch(struct dns_ctx *ctx, const char *srch);
387
388 /* set options for a resolver context */
389 UDNS_API int
390 dns_set_opts(struct dns_ctx *ctx, const char *opts);
391
392 enum dns_opt {          /* options */
393   DNS_OPT_FLAGS,        /* flags, DNS_F_XXX */
394   DNS_OPT_TIMEOUT,      /* timeout in secounds */
395   DNS_OPT_NTRIES,       /* number of retries */
396   DNS_OPT_NDOTS,        /* ndots */
397   DNS_OPT_UDPSIZE,      /* EDNS0 UDP size */
398   DNS_OPT_PORT,         /* port to use */
399 };
400
401 /* set or get (if val<0) an option */
402 UDNS_API int
403 dns_set_opt(struct dns_ctx *ctx, enum dns_opt opt, int val);
404
405 enum dns_flags {
406   DNS_NOSRCH    = 0x00010000,   /* do not perform search */
407   DNS_NORD      = 0x00020000,   /* request no recursion */
408   DNS_AAONLY    = 0x00040000,   /* set AA flag in queries */
409 };
410
411 /* set the debug function pointer */
412 typedef void
413 (dns_dbgfn)(int code, const struct sockaddr *sa, unsigned salen,
414             dnscc_t *pkt, int plen,
415             const struct dns_query *q, void *data);
416 UDNS_API void
417 dns_set_dbgfn(struct dns_ctx *ctx, dns_dbgfn *dbgfn);
418
419 /* open and return UDP socket */
420 UDNS_API int
421 dns_open(struct dns_ctx *ctx);
422
423 /* return UDP socket or -1 if not open */
424 UDNS_API int
425 dns_sock(const struct dns_ctx *ctx);
426
427 /* close the UDP socket */
428 UDNS_API void
429 dns_close(struct dns_ctx *ctx);
430
431 /* return number of requests queued */
432 UDNS_API int
433 dns_active(const struct dns_ctx *ctx);
434
435 /* return status of the last operation */
436 UDNS_API int
437 dns_status(const struct dns_ctx *ctx);
438 UDNS_API void
439 dns_setstatus(struct dns_ctx *ctx, int status);
440
441 /* handle I/O event on UDP socket */
442 UDNS_API void
443 dns_ioevent(struct dns_ctx *ctx, time_t now);
444
445 /* process any timeouts, return time in secounds to the
446  * next timeout (or -1 if none) but not greather than maxwait */
447 UDNS_API int
448 dns_timeouts(struct dns_ctx *ctx, int maxwait, time_t now);
449
450 /* define timer requesting routine to use */
451 typedef void dns_utm_fn(struct dns_ctx *ctx, int timeout, void *data);
452 UDNS_API void
453 dns_set_tmcbck(struct dns_ctx *ctx, dns_utm_fn *fn, void *data);
454
455 /**************************************************************************/
456 /**************** Making Queries ******************************************/
457
458 /* query callback routine */
459 typedef void dns_query_fn(struct dns_ctx *ctx, void *result, void *data);
460
461 /* query parse routine: raw DNS => application structure */
462 typedef int
463 dns_parse_fn(dnscc_t *qdn, dnscc_t *pkt, dnscc_t *cur, dnscc_t *end,
464              void **res);
465
466 enum dns_status {
467   DNS_E_NOERROR         = 0,    /* ok, not an error */
468   DNS_E_TEMPFAIL        = -1,   /* timeout, SERVFAIL or similar */
469   DNS_E_PROTOCOL        = -2,   /* got garbled reply */
470   DNS_E_NXDOMAIN        = -3,   /* domain does not exists */
471   DNS_E_NODATA          = -4,   /* domain exists but no data of reqd type */
472   DNS_E_NOMEM           = -5,   /* out of memory while processing */
473   DNS_E_BADQUERY        = -6    /* the query is malformed */
474 };
475
476 /* submit generic DN query */
477 UDNS_API struct dns_query *
478 dns_submit_dn(struct dns_ctx *ctx,
479               dnscc_t *dn, int qcls, int qtyp, int flags,
480               dns_parse_fn *parse, dns_query_fn *cbck, void *data);
481 /* submit generic name query */
482 UDNS_API struct dns_query *
483 dns_submit_p(struct dns_ctx *ctx,
484              const char *name, int qcls, int qtyp, int flags,
485              dns_parse_fn *parse, dns_query_fn *cbck, void *data);
486
487 /* cancel the given async query in progress */
488 UDNS_API int
489 dns_cancel(struct dns_ctx *ctx, struct dns_query *q);
490
491 /* resolve a generic query, return the answer */
492 UDNS_API void *
493 dns_resolve_dn(struct dns_ctx *ctx,
494                dnscc_t *qdn, int qcls, int qtyp, int flags,
495                dns_parse_fn *parse);
496 UDNS_API void *
497 dns_resolve_p(struct dns_ctx *ctx,
498               const char *qname, int qcls, int qtyp, int flags,
499               dns_parse_fn *parse);
500 UDNS_API void *
501 dns_resolve(struct dns_ctx *ctx, struct dns_query *q);
502
503
504 /* Specific RR handlers */
505
506 #define dns_rr_common(prefix)                                           \
507   char *prefix##_cname;         /* canonical name */                    \
508   char *prefix##_qname;         /* original query name */               \
509   unsigned prefix##_ttl;        /* TTL value */                         \
510   int prefix##_nrr              /* number of records */
511
512 struct dns_rr_null {            /* NULL RRset, aka RRset template */
513   dns_rr_common(dnsn);
514 };
515
516 UDNS_API int
517 dns_stdrr_size(const struct dns_parse *p);
518 UDNS_API void *
519 dns_stdrr_finish(struct dns_rr_null *ret, char *cp, const struct dns_parse *p);
520
521 struct dns_rr_a4 {              /* the A RRset */
522   dns_rr_common(dnsa4);
523   struct in_addr *dnsa4_addr;   /* array of addresses, naddr elements */
524 };
525
526 UDNS_API dns_parse_fn dns_parse_a4;     /* A RR parsing routine */
527 typedef void                            /* A query callback routine */
528 dns_query_a4_fn(struct dns_ctx *ctx, struct dns_rr_a4 *result, void *data);
529
530 /* submit A IN query */
531 UDNS_API struct dns_query *
532 dns_submit_a4(struct dns_ctx *ctx, const char *name, int flags,
533               dns_query_a4_fn *cbck, void *data);
534
535 /* resolve A IN query */
536 UDNS_API struct dns_rr_a4 *
537 dns_resolve_a4(struct dns_ctx *ctx, const char *name, int flags);
538
539
540 struct dns_rr_a6 {              /* the AAAA RRset */
541   dns_rr_common(dnsa6);
542   struct in6_addr *dnsa6_addr;  /* array of addresses, naddr elements */
543 };
544
545 UDNS_API dns_parse_fn dns_parse_a6;     /* A RR parsing routine */
546 typedef void                            /* A query callback routine */
547 dns_query_a6_fn(struct dns_ctx *ctx, struct dns_rr_a6 *result, void *data);
548
549 /* submit AAAA IN query */
550 UDNS_API struct dns_query *
551 dns_submit_a6(struct dns_ctx *ctx, const char *name, int flags,
552               dns_query_a6_fn *cbck, void *data);
553
554 /* resolve AAAA IN query */
555 UDNS_API struct dns_rr_a6 *
556 dns_resolve_a6(struct dns_ctx *ctx, const char *name, int flags);
557
558
559 struct dns_rr_ptr {             /* the PTR RRset */
560   dns_rr_common(dnsptr);
561   char **dnsptr_ptr;            /* array of PTRs */
562 };
563
564 UDNS_API dns_parse_fn dns_parse_ptr;    /* PTR RR parsing routine */
565 typedef void                            /* PTR query callback */
566 dns_query_ptr_fn(struct dns_ctx *ctx, struct dns_rr_ptr *result, void *data);
567 /* submit PTR IN in-addr.arpa query */
568 UDNS_API struct dns_query *
569 dns_submit_a4ptr(struct dns_ctx *ctx, const struct in_addr *addr,
570                  dns_query_ptr_fn *cbck, void *data);
571 /* resolve PTR IN in-addr.arpa query */
572 UDNS_API struct dns_rr_ptr *
573 dns_resolve_a4ptr(struct dns_ctx *ctx, const struct in_addr *addr);
574
575 /* the same as above, but for ip6.arpa */
576 UDNS_API struct dns_query *
577 dns_submit_a6ptr(struct dns_ctx *ctx, const struct in6_addr *addr,
578                  dns_query_ptr_fn *cbck, void *data);
579 UDNS_API struct dns_rr_ptr *
580 dns_resolve_a6ptr(struct dns_ctx *ctx, const struct in6_addr *addr);
581
582
583 struct dns_mx {         /* single MX RR */
584   int priority;         /* MX priority */
585   char *name;           /* MX name */
586 };
587 struct dns_rr_mx {              /* the MX RRset */
588   dns_rr_common(dnsmx);
589   struct dns_mx *dnsmx_mx;      /* array of MXes */
590 };
591 UDNS_API dns_parse_fn dns_parse_mx;     /* MX RR parsing routine */
592 typedef void                            /* MX RR callback */
593 dns_query_mx_fn(struct dns_ctx *ctx, struct dns_rr_mx *result, void *data);
594 /* submit MX IN query */
595 UDNS_API struct dns_query *
596 dns_submit_mx(struct dns_ctx *ctx, const char *name, int flags,
597               dns_query_mx_fn *cbck, void *data);
598 /* resolve MX IN query */
599 UDNS_API struct dns_rr_mx *
600 dns_resolve_mx(struct dns_ctx *ctx, const char *name, int flags);
601
602
603 struct dns_txt {        /* single TXT record */
604   int len;              /* length of the text */
605   dnsc_t *txt;  /* pointer to text buffer. May contain nulls. */
606 };
607 struct dns_rr_txt {             /* the TXT RRset */
608   dns_rr_common(dnstxt);
609   struct dns_txt *dnstxt_txt;   /* array of TXT records */
610 };
611 UDNS_API dns_parse_fn dns_parse_txt;    /* TXT RR parsing routine */
612 typedef void                            /* TXT RR callback */
613 dns_query_txt_fn(struct dns_ctx *ctx, struct dns_rr_txt *result, void *data);
614 /* submit TXT query */
615 UDNS_API struct dns_query *
616 dns_submit_txt(struct dns_ctx *ctx, const char *name, int qcls, int flags,
617                dns_query_txt_fn *cbck, void *data);
618 /* resolve TXT query */
619 UDNS_API struct dns_rr_txt *
620 dns_resolve_txt(struct dns_ctx *ctx, const char *name, int qcls, int flags);
621
622
623 struct dns_srv {        /* single SRV RR */
624   int priority;         /* SRV priority */
625   int weight;           /* SRV weight */
626   int port;             /* SRV port */
627   char *name;           /* SRV name */
628 };
629 struct dns_rr_srv {             /* the SRV RRset */
630   dns_rr_common(dnssrv);
631   struct dns_srv *dnssrv_srv;   /* array of SRVes */
632 };
633 UDNS_API dns_parse_fn dns_parse_srv;    /* SRV RR parsing routine */
634 typedef void                            /* SRV RR callback */
635 dns_query_srv_fn(struct dns_ctx *ctx, struct dns_rr_srv *result, void *data);
636 /* submit SRV IN query */
637 UDNS_API struct dns_query *
638 dns_submit_srv(struct dns_ctx *ctx,
639                const char *name, const char *srv, const char *proto,
640                int flags, dns_query_srv_fn *cbck, void *data);
641 /* resolve SRV IN query */
642 UDNS_API struct dns_rr_srv *
643 dns_resolve_srv(struct dns_ctx *ctx,
644                 const char *name, const char *srv, const char *proto,
645                 int flags);
646
647 /* NAPTR (RFC3403) RR type */
648 struct dns_naptr {      /* single NAPTR RR */
649   int order;            /* NAPTR order */
650   int preference;       /* NAPTR preference */
651   char *flags;          /* NAPTR flags */
652   char *service;        /* NAPTR service */
653   char *regexp;         /* NAPTR regexp */
654   char *replacement;    /* NAPTR replacement */
655 };
656
657 struct dns_rr_naptr {           /* the NAPTR RRset */
658   dns_rr_common(dnsnaptr);
659   struct dns_naptr *dnsnaptr_naptr;     /* array of NAPTRes */
660 };
661 UDNS_API dns_parse_fn dns_parse_naptr;  /* NAPTR RR parsing routine */
662 typedef void                            /* NAPTR RR callback */
663 dns_query_naptr_fn(struct dns_ctx *ctx,
664                    struct dns_rr_naptr *result, void *data);
665 /* submit NAPTR IN query */
666 UDNS_API struct dns_query *
667 dns_submit_naptr(struct dns_ctx *ctx, const char *name, int flags,
668                  dns_query_naptr_fn *cbck, void *data);
669 /* resolve NAPTR IN query */
670 UDNS_API struct dns_rr_naptr *
671 dns_resolve_naptr(struct dns_ctx *ctx, const char *name, int flags);
672
673
674 UDNS_API struct dns_query *
675 dns_submit_a4dnsbl(struct dns_ctx *ctx,
676                    const struct in_addr *addr, const char *dnsbl,
677                    dns_query_a4_fn *cbck, void *data);
678 UDNS_API struct dns_query *
679 dns_submit_a4dnsbl_txt(struct dns_ctx *ctx,
680                        const struct in_addr *addr, const char *dnsbl,
681                        dns_query_txt_fn *cbck, void *data);
682 UDNS_API struct dns_rr_a4 *
683 dns_resolve_a4dnsbl(struct dns_ctx *ctx,
684                     const struct in_addr *addr, const char *dnsbl);
685 UDNS_API struct dns_rr_txt *
686 dns_resolve_a4dnsbl_txt(struct dns_ctx *ctx,
687                         const struct in_addr *addr, const char *dnsbl);
688
689 UDNS_API struct dns_query *
690 dns_submit_a6dnsbl(struct dns_ctx *ctx,
691                    const struct in6_addr *addr, const char *dnsbl,
692                    dns_query_a4_fn *cbck, void *data);
693 UDNS_API struct dns_query *
694 dns_submit_a6dnsbl_txt(struct dns_ctx *ctx,
695                        const struct in6_addr *addr, const char *dnsbl,
696                        dns_query_txt_fn *cbck, void *data);
697 UDNS_API struct dns_rr_a4 *
698 dns_resolve_a6dnsbl(struct dns_ctx *ctx,
699                     const struct in6_addr *addr, const char *dnsbl);
700 UDNS_API struct dns_rr_txt *
701 dns_resolve_a6dnsbl_txt(struct dns_ctx *ctx,
702                         const struct in6_addr *addr, const char *dnsbl);
703
704 UDNS_API struct dns_query *
705 dns_submit_rhsbl(struct dns_ctx *ctx,
706                  const char *name, const char *rhsbl,
707                  dns_query_a4_fn *cbck, void *data);
708 UDNS_API struct dns_query *
709 dns_submit_rhsbl_txt(struct dns_ctx *ctx,
710                      const char *name, const char *rhsbl,
711                      dns_query_txt_fn *cbck, void *data);
712 UDNS_API struct dns_rr_a4 *
713 dns_resolve_rhsbl(struct dns_ctx *ctx, const char *name, const char *rhsbl);
714 UDNS_API struct dns_rr_txt *
715 dns_resolve_rhsbl_txt(struct dns_ctx *ctx, const char *name, const char *rhsbl);
716
717 /**************************************************************************/
718 /**************** Names, Names ********************************************/
719
720 struct dns_nameval {
721   int val;
722   const char *name;
723 };
724
725 UDNS_DATA_API extern const struct dns_nameval dns_classtab[];
726 UDNS_DATA_API extern const struct dns_nameval dns_typetab[];
727 UDNS_DATA_API extern const struct dns_nameval dns_rcodetab[];
728 UDNS_API const struct dns_nameval *dns_class_index(int);
729 UDNS_API const struct dns_nameval *dns_type_index(int);
730 UDNS_API const struct dns_nameval *dns_rcode_index(int);
731 UDNS_API int
732 dns_findname(const struct dns_nameval *nv, const char *name);
733 #define dns_findclassname(cls) dns_findname(dns_classtab, (cls))
734 #define dns_findtypename(type) dns_findname(dns_typetab, (type))
735 #define dns_findrcodename(rcode) dns_findname(dns_rcodetab, (rcode))
736
737 UDNS_API const char *dns_classname(enum dns_class cls);
738 UDNS_API const char *dns_typename(enum dns_type type);
739 UDNS_API const char *dns_rcodename(enum dns_rcode rcode);
740 const char *_dns_format_code(char *buf, const char *prefix, int code);
741
742 UDNS_API const char *dns_strerror(int errnum);
743
744 #ifdef __cplusplus
745 } /* extern "C" */
746 #endif
747
748 #endif  /* include guard */
Note: See TracBrowser for help on using the browser.