3 #ifndef ADNS_H_INCLUDED
4 #define ADNS_H_INCLUDED
6 #include <sys/socket.h>
7 #include <netinet/in.h>
9 typedef struct adns__state
*adns_state
;
10 typedef struct adns__query
*adns_query
;
13 adns_if_noenv
= 0x0001, /* do not look at environment */
14 adns_if_noerrprint
= 0x0002, /* never print output to stderr */
15 adns_if_debug
= 0x0004, /* print debugging output to stderr */
19 adns_f_search
= 0x0001, /* use the searchlist */
20 adns_f_usevc
= 0x0002, /* use a virtual circuit (TCP connection) */
21 adns_f_anyquote
= 0x0004,
25 adns__rrttype_mask
= 0x0fff,
26 adns__qtf_deref
= 0x1000, /* dereference domains and produce extra data */
27 adns__qtf_mailconv
= 0x2000, /* put @ between first and second labels */
31 adns_r_ns
= adns_r_ns_raw
|adns__qtf_deref
,
34 adns_r_soa
= adns_r_soa_raw
|adns__qtf_mailconv
,
37 adns_r_ptr
= adns_r_ptr_raw
|adns__qtf_deref
,
40 adns_r_mx
= adns_r_mx_raw
|adns__qtf_deref
,
43 adns_r_rp
= adns_r_rp_raw
|adns__qtf_mailconv
46 /* In queries without qtf_anyquote, all domains must have standard
47 * legal syntax. In queries _with_ qtf_anyquote, domains in the query
48 * or response may contain any characters, quoted according to
49 * RFC1035 5.1. On input to adns, the char* is a pointer to the
50 * interior of a " delimited string, except that " may appear in it,
51 * and on output, the char* is a pointer to a string which would be
52 * legal either inside or outside " delimiters, and any characters
53 * not usually legal in domain names will be quoted as \X
54 * (if the character is 33-126 except \ and ") or \DDD.
56 * Do not ask for records containing mailboxes without
57 * specifying qtf_mailconv or qtf_anyquote.
66 adns_s_max_tempfail
= 99,
72 /* In dereferenced answers, multiple addresses show up as multiple
73 * answers with all the dm pointers being the same. If no
74 * address is available (permanent failure) then INADDR_NONE is
80 char *cname
; /* always NULL if query was for CNAME records */
84 struct in_addr inaddr
[1]; /* a */
85 char (*str
)[1]; /* ns_raw, cname, ptr, ptr_raw, txt */
86 struct { char *dm
; struct in_addr addr
; } dmaddr
; /* ns */
87 struct { char *a
, *b
; } strpair
[1]; /* hinfo, rp, rp_raw */
88 struct { int pref
; char *dm
; struct in_addr addr
; } intdmaddr
[1]; /* mx */
89 struct { int pref
; char *str
; } intstr
[1]; /* mx_raw */
92 unsigned long serial
, refresh
, retry
, expire
, minimum
;
93 } soa
[1]; /* soa, soa_raw */
99 * adns_state and adns_query are actually pointers to malloc'd state;
100 * On submission questions are copied, including the owner domain;
101 * Answers are malloc'd as a single piece of memory.
103 * Must always be non-null pointer;
104 * If *query_io is 0 to start with then any query may be returned;
105 * If *query_io is !0 adns_query then only that query may be returned.
107 * Return values are 0 or an errno value;
108 * Seriously fatal system errors (eg, failure to create sockets,
109 * malloc failure, etc.) return errno values;
110 * Other errors (nameserver failure, timed out connections, &c)
111 * are returned in the status field of the answer. If status is
112 * nonzero then nrrs will be 0, otherwise it will be >0.
113 * type will always be the type requested;
114 * If no (appropriate) requests are done adns_query returns EWOULDBLOCK;
115 * If no requests are outstanding adns_query and adns_wait return ESRCH;
116 * If malloc failure occurs during internal allocation or processing
117 * ands_query, _wait and _answer set *answer to 0.
120 int adns_init(adns_state
*newstate_r
, adns_initflags flags
);
122 int adns_synchronous(adns_state ads
,
126 struct adns_answer
*answer
);
128 int adns_submit(adns_state ads
,
133 adns_query
*query_r
);
135 int adns_check(adns_state ads
,
136 adns_query
*query_io
,
137 struct adns_answer
*answer
,
140 int adns_wait(adns_state ads
,
141 adns_query
*query_io
,
142 struct adns_answer
*answer
,
145 int adns_cancel(adns_state ads
, adns_query query
);
147 int adns_finish(adns_state
);
149 void adns_interest(adns_state
, fd_set
*readfds_mod
,
150 fd_set
*writefds_mod
, fd_set
*exceptfds_mod
,
151 int *maxfd_mod
, struct timeval
**tv_mod
, struct timeval
*tv_buf
);
152 /* You may call this with *_mod=0 to allow adns to have flow-of-control
153 * briefly, or with *fds_mod=*maxfd_mod=0 but tv_mod!=0 if you are
154 * not going to sleep, or with all !=0 if you are going to sleep.
155 * If tv_mod!=0 and *tv_mod=0 then tv_buf must be !0 and *tv_buf is irrelevant
156 * and may be overwritten (and *tv_mod set to tv_buf); otherwise tv_buf is ignored.
159 int adns_callback(adns_state
, fd_set readfds
, fd_set writefds
,
160 fd_set exceptfds
, int maxfd
);
161 /* For select-driven programs, this allows adns to know which fd's are relevant,
162 * so that it doesn't need to make syscalls on others of its fd's. It's a kind
163 * of limited flow-of-control allowance. It will return how many adns fd's were
164 * in the set, so you can tell if your select handling code is missing things.
167 /* Example expected/legal calling sequences:
173 * adns_check 3 -> EWOULDBLOCK