ReactOS 0.4.16-dev-257-g6aa11ac
adnstest.c File Reference
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "adns.h"
Include dependency graph for adnstest.c:

Go to the source code of this file.

Classes

struct  myctx
 

Macros

#define adns_beforepoll(a, b, c, d, e)   0
 
#define adns_afterpoll(a, b, c, d)   0
 

Functions

static void quitnow (int rc) NONRETURNING
 
int poll (struct pollfd *ufds, int nfds, int timeout)
 
static void failure_status (const char *what, adns_status st) NONRETURNING
 
static void failure_errno (const char *what, int errnoval) NONRETURNING
 
static void usageerr (const char *why) NONRETURNING
 
static void dumptype (adns_status ri, const char *rrtn, const char *fmtn)
 
static void fdom_split (const char *fdom, const char **dom_r, int *qf_r, char *ownflags, int ownflags_l)
 
static int consistsof (const char *string, const char *accept)
 
int main (int argc, char *const *argv)
 

Variables

static struct myctxmcs
 
static adns_state ads
 
static adns_rrtypetypes_a
 
static const adns_rrtype defaulttypes []
 

Macro Definition Documentation

◆ adns_afterpoll

#define adns_afterpoll (   a,
  b,
  c,
  d 
)    0

Definition at line 74 of file adnstest.c.

◆ adns_beforepoll

#define adns_beforepoll (   a,
  b,
  c,
  d,
  e 
)    0

Definition at line 73 of file adnstest.c.

Function Documentation

◆ consistsof()

static int consistsof ( const char string,
const char accept 
)
static

Definition at line 155 of file adnstest.c.

155 {
156 return strspn(string,accept) == strlen(string);
157}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_Check_return_ _CRTIMP size_t __cdecl strspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23

Referenced by main().

◆ dumptype()

static void dumptype ( adns_status  ri,
const char rrtn,
const char fmtn 
)
static

Definition at line 131 of file adnstest.c.

131 {
132 fprintf(stdout, "%s(%s)%s%s",
133 ri ? "?" : rrtn, ri ? "?" : fmtn ? fmtn : "-",
134 ri ? " " : "", ri ? adns_strerror(ri) : "");
135}
ADNS_API const char * adns_strerror(adns_status st)
Definition: general.c:268
#define stdout
Definition: stdio.h:99
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)

Referenced by main().

◆ failure_errno()

static void failure_errno ( const char what,
int  errnoval 
)
static

Definition at line 84 of file adnstest.c.

84 {
85 fprintf(stderr,"adns failure: %s: errno=%d\n",what,errnoval);
86 quitnow(2);
87}
static void quitnow(int rc) NONRETURNING
Definition: adnstest.c:58
#define stderr
Definition: stdio.h:100

Referenced by main().

◆ failure_status()

static void failure_status ( const char what,
adns_status  st 
)
static

Definition at line 78 of file adnstest.c.

78 {
79 fprintf(stderr,"adns failure: %s: %s\n",what,adns_strerror(st));
80 quitnow(2);
81}

Referenced by main().

◆ fdom_split()

static void fdom_split ( const char fdom,
const char **  dom_r,
int qf_r,
char ownflags,
int  ownflags_l 
)
static

Definition at line 137 of file adnstest.c.

138 {
139 int qf;
140 char *ep;
141
142 qf= strtoul(fdom,&ep,0);
143 if (*ep == ',' && strchr(ep,'/')) {
144 ep++;
145 while (*ep != '/') {
146 if (--ownflags_l <= 0) { fputs("too many flags\n",stderr); quitnow(3); }
147 *ownflags++= *ep++;
148 }
149 }
150 if (*ep != '/') { *dom_r= fdom; *qf_r= 0; }
151 else { *dom_r= ep+1; *qf_r= qf; }
152 *ownflags= 0;
153}
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
char * strchr(const char *String, int ch)
Definition: utclib.c:501
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)

Referenced by main().

◆ main()

int main ( int argc  ,
char *const argv 
)

Definition at line 159 of file adnstest.c.

159 {
160 adns_query qu;
161 struct myctx *mc, *mcw;
162 void *mcr;
163 adns_answer *ans;
164 const char *initstring, *rrtn, *fmtn;
165 const char *const *fdomlist, *domain;
166 char *show, *cp;
167 int len, i, qc, qi, tc, ti, ch, qflags, initflagsnum;
168 adns_status ri;
169 int r;
170 const adns_rrtype *types;
171 struct timeval now;
172 char ownflags[10];
173 char *ep;
174 const char *initflags, *owninitflags;
175
176 if (argv[0] && argv[1] && argv[1][0] == '-') {
177 initflags= argv[1]+1;
178 argv++;
179 } else {
180 initflags= "";
181 }
182 if (argv[0] && argv[1] && argv[1][0] == '/') {
183 initstring= argv[1]+1;
184 argv++;
185 } else {
186 initstring= 0;
187 }
188
189 initflagsnum= strtoul(initflags,&ep,0);
190 if (*ep == ',') {
191 owninitflags= ep+1;
192 if (!consistsof(owninitflags,"ps")) usageerr("unknown owninitflag");
193 } else if (!*ep) {
194 owninitflags= "";
195 } else {
196 usageerr("bad <initflagsnum>[,<owninitflags>]");
197 }
198
199 if (argv[0] && argv[1] && argv[1][0] == ':') {
200 for (cp= argv[1]+1, tc=1; (ch= *cp); cp++)
201 if (ch==',') tc++;
202 types_a= malloc(sizeof(*types_a)*(tc+1));
203 if (!types_a) { perror("malloc types"); quitnow(3); }
204 for (cp= argv[1]+1, ti=0; ti<tc; ti++) {
205 types_a[ti]= strtoul(cp,&cp,10);
206 if ((ch= *cp)) {
207 if (ch != ',') usageerr("unexpected char (not comma) in or between types");
208 cp++;
209 }
210 }
211 types_a[ti]= adns_r_none;
212 types= types_a;
213 argv++;
214 } else {
215 types_a= 0;
217 }
218
219 if (!(argv[0] && argv[1])) usageerr("no query domains supplied");
220 fdomlist= (const char *const*)argv+1;
221
222 for (qc=0; fdomlist[qc]; qc++);
223 for (tc=0; types[tc] != adns_r_none; tc++);
224 mcs= malloc(tc ? sizeof(*mcs)*qc*tc : 1);
225 if (!mcs) { perror("malloc mcs"); quitnow(3); }
226
227 setvbuf(stdout,0,_IOLBF,0);
228
229 if (initstring) {
232 ^initflagsnum,
233 stdout,initstring);
234 } else {
235 r= adns_init(&ads,
236 (adns_if_debug|adns_if_noautosys)^initflagsnum,
237 0);
238 }
239 if (r) failure_errno("init",r);
240
241 for (qi=0; qi<qc; qi++) {
242 fdom_split(fdomlist[qi],&domain,&qflags,ownflags,sizeof(ownflags));
243 if (!consistsof(ownflags,"a")) usageerr("unknown ownqueryflag");
244 for (ti=0; ti<tc; ti++) {
245 mc= &mcs[qi*tc+ti];
246 mc->doneyet= 0;
247 mc->fdom= fdomlist[qi];
248
249 fprintf(stdout,"%s flags %d type %d",domain,qflags,types[ti]);
250 r= adns_submit(ads,domain,types[ti],qflags,mc,&mc->qu);
251 if (r == ENOSYS) {
252 fprintf(stdout," not implemented\n");
253 mc->qu= 0;
254 mc->doneyet= 1;
255 } else if (r) {
256 failure_errno("submit",r);
257 } else {
258 ri= adns_rr_info(types[ti], &rrtn,&fmtn,0, 0,0);
259 putc(' ',stdout);
260 dumptype(ri,rrtn,fmtn);
261 fprintf(stdout," submitted\n");
262 }
263 }
264 }
265
266 for (;;) {
267 for (qi=0; qi<qc; qi++) {
268 for (ti=0; ti<tc; ti++) {
269 mc= &mcs[qi*tc+ti];
270 mc->found= 0;
271 }
272 }
274 (qu= adns_forallqueries_next(ads,&mcr));
275 ) {
276 mc= mcr;
277 assert(qu == mc->qu);
278 assert(!mc->doneyet);
279 mc->found= 1;
280 }
281 mcw= 0;
282 for (qi=0; qi<qc; qi++) {
283 for (ti=0; ti<tc; ti++) {
284 mc= &mcs[qi*tc+ti];
285 if (mc->doneyet) continue;
286 assert(mc->found);
287 if (!mcw) mcw= mc;
288 }
289 }
290 if (!mcw) break;
291
292 if (strchr(owninitflags,'s')) {
293 qu= mcw->qu;
294 mc= mcw;
295 } else {
296 qu= 0;
297 mc= 0;
298 }
299
300#ifdef HAVE_POLL
301 if (strchr(owninitflags,'p')) {
302 r= adns_wait_poll(ads,&qu,&ans,&mcr);
303 } else
304#endif
305 {
306 r= adns_wait(ads,&qu,&ans,&mcr);
307 }
308 if (r) failure_errno("wait/check",r);
309
310 if (mc) assert(mcr==mc);
311 else mc= mcr;
312 assert(qu==mc->qu);
313 assert(!mc->doneyet);
314
315 fdom_split(mc->fdom,&domain,&qflags,ownflags,sizeof(ownflags));
316
317 if (gettimeofday(&now,0)) { perror("gettimeofday"); quitnow(3); }
318
319 ri= adns_rr_info(ans->type, &rrtn,&fmtn,&len, 0,0);
320 fprintf(stdout, "%s flags %d type ",domain,qflags);
321 dumptype(ri,rrtn,fmtn);
322 fprintf(stdout, "%s%s: %s; nrrs=%d; cname=%s; owner=%s; ttl=%ld\n",
323 ownflags[0] ? " ownflags=" : "", ownflags,
324 strchr(ownflags,'a')
325 ? adns_errabbrev(ans->status)
326 : adns_strerror(ans->status),
327 ans->nrrs,
328 ans->cname ? ans->cname : "$",
329 ans->owner ? ans->owner : "$",
330 (long)ans->expires - (long)now.tv_sec);
331 if (ans->nrrs) {
332 assert(!ri);
333 for (i=0; i<ans->nrrs; i++) {
334 ri= adns_rr_info(ans->type, 0,0,0, ans->rrs.bytes + i*len, &show);
335 if (ri) failure_status("info",ri);
336 fprintf(stdout," %s\n",show);
337 free(show);
338 }
339 }
340 free(ans);
341
342 mc->doneyet= 1;
343 }
344
345 quitnow(0);
346}
adns_rrtype
Definition: adns.h:113
@ adns_r_none
Definition: adns.h:118
ADNS_API adns_status adns_rr_info(adns_rrtype type, const char **rrtname_r, const char **fmtname_r, int *len_r, const void *datap, char **data_r)
Definition: general.c:186
ADNS_API void adns_forallqueries_begin(adns_state ads)
Definition: setup.c:671
ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:568
ADNS_API int adns_wait(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r)
Definition: event.c:696
@ adns_if_checkc_freq
Definition: adns.h:97
@ adns_if_noautosys
Definition: adns.h:93
@ adns_if_debug
Definition: adns.h:91
ADNS_API adns_query adns_forallqueries_next(adns_state ads, void **context_r)
Definition: setup.c:680
adns_status
Definition: adns.h:215
ADNS_API const char * adns_errabbrev(adns_status st)
Definition: general.c:275
ADNS_API int adns_wait_poll(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r)
ADNS_API int adns_submit(adns_state ads, const char *owner, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:204
ADNS_API int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags, FILE *diagfile, const char *configtext)
Definition: setup.c:629
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
static adns_initflags initflags
Definition: adnsresfilter.c:62
static const adns_rrtype defaulttypes[]
Definition: adnstest.c:109
static int consistsof(const char *string, const char *accept)
Definition: adnstest.c:155
static void usageerr(const char *why) NONRETURNING
Definition: adnstest.c:90
static adns_rrtype * types_a
Definition: adnstest.c:55
static struct myctx * mcs
Definition: adnstest.c:53
static void dumptype(adns_status ri, const char *rrtn, const char *fmtn)
Definition: adnstest.c:131
static void failure_status(const char *what, adns_status st) NONRETURNING
Definition: adnstest.c:78
static void fdom_split(const char *fdom, const char **dom_r, int *qf_r, char *ownflags, int ownflags_l)
Definition: adnstest.c:137
static adns_state ads
Definition: adnstest.c:54
static void failure_errno(const char *what, int errnoval) NONRETURNING
Definition: adnstest.c:84
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define assert(x)
Definition: debug.h:53
time_t now
Definition: finger.c:65
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const GLfloat * tc
Definition: glext.h:8925
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
#define _IOLBF
Definition: stdio.h:128
_Check_return_opt_ _CRTIMP int __cdecl setvbuf(_Inout_ FILE *_File, _Inout_updates_opt_z_(_Size) char *_Buf, _In_ int _Mode, _In_ size_t _Size)
POINT cp
Definition: magnifier.c:59
#define argv
Definition: mplay32.c:18
#define ENOSYS
Definition: errno.h:57
int nrrs
Definition: adns.h:316
union adns_answer::@4225 rrs
time_t expires
Definition: adns.h:315
adns_status status
Definition: adns.h:311
unsigned char * bytes
Definition: adns.h:319
adns_rrtype type
Definition: adns.h:314
char * cname
Definition: adns.h:312
char * owner
Definition: adns.h:313
Definition: cookie.c:42
Definition: adnstest.c:47
const char * fdom
Definition: adnstest.c:50
adns_query qu
Definition: adnstest.c:48
int doneyet
Definition: adnstest.c:49
int found
Definition: adnstest.c:49
Definition: cmds.c:130

◆ poll()

int poll ( struct pollfd ufds,
int  nfds,
int  timeout 
)

Definition at line 68 of file adnstest.c.

68 {
69 fputs("poll(2) not supported on this system\n",stderr);
70 quitnow(5);
71 return -1; /* compiler food */
72}

◆ quitnow()

static void quitnow ( int  rc)
static

Definition at line 58 of file adnstest.c.

58 {
59 free(mcs);
61 if (ads) adns_finish(ads);
62
63 exit(rc);
64}
ADNS_API void adns_finish(adns_state ads)
Definition: setup.c:650
#define exit(n)
Definition: config.h:202

Referenced by failure_errno(), failure_status(), fdom_split(), main(), poll(), and usageerr().

◆ usageerr()

static void usageerr ( const char why)
static

Definition at line 90 of file adnstest.c.

90 {
92 "bad usage: %s\n"
93 "usage: adnstest [-<initflagsnum>[,<owninitflags>]] [/<initstring>]\n"
94 " [ :<typenum>,... ]\n"
95 " [ [<queryflagsnum>[,<ownqueryflags>]/]<domain> ... ]\n"
96 "initflags: p use poll(2) instead of select(2)\n"
97 " s use adns_wait with specified query, instead of 0\n"
98 "queryflags: a print status abbrevs instead of strings\n"
99 "exit status: 0 ok (though some queries may have failed)\n"
100 " 1 used by test harness to indicate test failed\n"
101 " 2 unable to submit or init or some such\n"
102 " 3 unexpected failure\n"
103 " 4 usage error\n"
104 " 5 operation not supported on this system\n",
105 why);
106 quitnow(4);
107}

Referenced by main().

Variable Documentation

◆ ads

adns_state ads
static

Definition at line 54 of file adnstest.c.

Referenced by main(), and quitnow().

◆ defaulttypes

const adns_rrtype defaulttypes[]
static
Initial value:
= {
}
@ adns_r_addr
Definition: adns.h:143
@ adns_r_ptr_raw
Definition: adns.h:130
@ adns_r_soa
Definition: adns.h:128
@ adns_r_mx
Definition: adns.h:136
@ adns_r_hinfo
Definition: adns.h:133
@ adns_r_rp_raw
Definition: adns.h:140
@ adns_r_cname
Definition: adns.h:125
@ adns_r_ptr
Definition: adns.h:131
@ adns_r_a
Definition: adns.h:120
@ adns_r_mx_raw
Definition: adns.h:135
@ adns_r_txt
Definition: adns.h:138
@ adns_r_rp
Definition: adns.h:141
@ adns_r_soa_raw
Definition: adns.h:127
@ adns_r_ns_raw
Definition: adns.h:122
@ adns_r_ns
Definition: adns.h:123

Definition at line 109 of file adnstest.c.

Referenced by main().

◆ mcs

◆ types_a

adns_rrtype* types_a
static

Definition at line 55 of file adnstest.c.

Referenced by main(), and quitnow().