ReactOS 0.4.16-dev-303-g11d5cb8
adh-main.c File Reference
#include "adnshost.h"
Include dependency graph for adh-main.c:

Go to the source code of this file.

Functions

void quitnow (int rc)
 
void sysfail (const char *what, int errnoval)
 
void usageerr (const char *fmt,...)
 
void outerr (void)
 
voidxmalloc (size_t sz)
 
charxstrsave (const char *str)
 
void of_config (const struct optioninfo *oi, const char *arg, const char *arg2)
 
void of_type (const struct optioninfo *oi, const char *arg, const char *arg2)
 
static void process_optarg (const char *arg, const char *const **argv_p, const char *value)
 
static void read_stdin (void)
 
int main (int argc, const char *const *argv)
 

Variables

int rcode
 
const charconfig_text
 
static int used
 
static int avail
 
static charbuf
 

Function Documentation

◆ main()

int main ( int argc  ,
const char *const argv 
)

Definition at line 224 of file adh-main.c.

224 {
225 struct timeval *tv, tvbuf;
226 adns_query qu;
227 void *qun_v;
228 adns_answer *answer;
229 int r, maxfd;
230 fd_set readfds, writefds, exceptfds;
231 const char *arg;
232
234
235 while ((arg= *++argv)) process_optarg(arg,&argv,0);
236
237 if (!ov_pipe && !ads) usageerr("no domains given, and -f/--pipe not used; try --help");
238
239 for (;;) {
240 for (;;) {
241 qu= ov_asynch ? 0 : outstanding.head ? outstanding.head->qu : 0;
242 r= adns_check(ads,&qu,&answer,&qun_v);
243 if ((r == EAGAIN) || (r == EWOULDBLOCK)) break;
244 if (r == ESRCH) { if (!ov_pipe) goto x_quit; else break; }
245 assert(!r);
246 query_done(qun_v,answer);
247 }
248 maxfd= 0;
249 FD_ZERO(&readfds);
250 FD_ZERO(&writefds);
251 FD_ZERO(&exceptfds);
252 if (ov_pipe) {
253 maxfd= 1;
254 FD_SET(0,&readfds);
255 }
256 tv= 0;
257 adns_beforeselect(ads, &maxfd, &readfds,&writefds,&exceptfds, &tv,&tvbuf,0);
259 r= select(maxfd, &readfds,&writefds,&exceptfds, tv);
261 if (r == -1) {
262 if (errno == EINTR) continue;
263 sysfail("select",errno);
264 }
265 adns_afterselect(ads, maxfd, &readfds,&writefds,&exceptfds, 0);
266 if (ov_pipe && FD_ISSET(0,&readfds)) read_stdin();
267 }
268x_quit:
269 if (fclose(stdout)) outerr();
270 quitnow(rcode);
271}
#define EINTR
Definition: acclib.h:80
#define EAGAIN
Definition: acclib.h:83
void usageerr(const char *fmt,...)
Definition: adh-main.c:54
static void process_optarg(const char *arg, const char *const **argv_p, const char *value)
Definition: adh-main.c:125
int rcode
Definition: adh-main.c:36
void sysfail(const char *what, int errnoval)
Definition: adh-main.c:49
void quitnow(int rc)
Definition: adh-main.c:42
void outerr(void)
Definition: adh-main.c:64
static void read_stdin(void)
Definition: adh-main.c:186
int ov_asynch
Definition: adh-opts.c:35
int ov_pipe
Definition: adh-opts.c:35
struct outstanding_list outstanding
Definition: adh-query.c:36
void ensure_adns_init(void)
Definition: adh-query.c:40
void query_done(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:253
adns_state ads
Definition: adh-query.c:35
ADNS_API void adns_beforeselect(adns_state ads, int *maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval **tv_mod, struct timeval *tv_buf, const struct timeval *now)
Definition: event.c:562
ADNS_API int adns_check(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r)
Definition: event.c:731
ADNS_API void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds, const fd_set *writefds, const fd_set *exceptfds, const struct timeval *now)
Definition: event.c:595
#define ADNS_CLEAR_ERRNO
Definition: adns_win32.h:108
#define ADNS_CAPTURE_ERRNO
Definition: adns_win32.h:107
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
#define assert(x)
Definition: debug.h:53
#define ESRCH
Definition: errno.h:9
#define EWOULDBLOCK
Definition: errno.h:42
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define stdout
Definition: stdio.h:99
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define argv
Definition: mplay32.c:18
#define errno
Definition: errno.h:18
Definition: winsock.h:66
void * arg
Definition: msvc.h:10
#define FD_ISSET(fd, set)
Definition: winsock.h:100
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

◆ of_config()

void of_config ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 83 of file adh-main.c.

83 {
85}
const char * config_text
Definition: adh-main.c:37

◆ of_type()

void of_type ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 87 of file adh-main.c.

87 {
88 static const struct typename {
90 const char *desc;
91 } typenames[]= {
92 /* enhanced versions */
93 { adns_r_ns, "ns" },
94 { adns_r_soa, "soa" },
95 { adns_r_ptr, "ptr" },
96 { adns_r_mx, "mx" },
97 { adns_r_rp, "rp" },
98 { adns_r_addr, "addr" },
99
100 /* types with only one version */
101 { adns_r_cname, "cname" },
102 { adns_r_hinfo, "hinfo" },
103 { adns_r_txt, "txt" },
104
105 /* raw versions */
106 { adns_r_a, "a" },
107 { adns_r_ns_raw, "ns-" },
108 { adns_r_soa_raw, "soa-" },
109 { adns_r_ptr_raw, "ptr-" },
110 { adns_r_mx_raw, "mx-" },
111 { adns_r_rp_raw, "rp-" },
112
113 { adns_r_none, 0 }
114 };
115
116 const struct typename *tnp;
117
118 for (tnp=typenames;
119 tnp->type && strcmp(arg,tnp->desc);
120 tnp++);
121 if (!tnp->type) usageerr("unknown RR type %s",arg);
122 ov_type= tnp->type;
123}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
adns_rrtype ov_type
Definition: adh-opts.c:37
adns_rrtype
Definition: adns.h:113
@ 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_none
Definition: adns.h:118
@ 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
char typename[32]
Definition: main.c:84
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static const WCHAR desc[]
Definition: protectdata.c:36

◆ outerr()

void outerr ( void  )

Definition at line 64 of file adh-main.c.

64 {
65 sysfail("write to stdout",errno);
66}

Referenced by main(), print_dnsfail(), print_status(), print_ttl(), print_withspace(), and query_done().

◆ process_optarg()

static void process_optarg ( const char arg,
const char *const **  argv_p,
const char value 
)
static

Definition at line 125 of file adh-main.c.

127 {
128 const struct optioninfo *oip;
129 const char *arg2;
130 int invert;
131
132 if (arg[0] == '-' || arg[0] == '+') {
133 if (arg[0] == '-' && arg[1] == '-') {
134 if (!strncmp(arg,"--no-",5)) {
135 invert= 1;
136 oip= opt_findl(arg+5);
137 } else {
138 invert= 0;
139 oip= opt_findl(arg+2);
140 }
141 if (oip->type == ot_funcarg) {
142 arg= argv_p ? *++(*argv_p) : value;
143 if (!arg) usageerr("option --%s requires a value argument",oip->lopt);
144 arg2= 0;
145 } else if (oip->type == ot_funcarg2) {
146 assert(argv_p);
147 arg= *++(*argv_p);
148 arg2= arg ? *++(*argv_p) : 0;
149 if (!arg || !arg2)
150 usageerr("option --%s requires two more arguments", oip->lopt);
151 } else {
152 if (value) usageerr("option --%s does not take a value",oip->lopt);
153 arg= 0;
154 arg2= 0;
155 }
156 opt_do(oip,invert,arg,arg2);
157 } else if (arg[0] == '-' && arg[1] == 0) {
158 arg= argv_p ? *++(*argv_p) : value;
159 if (!arg) usageerr("option `-' must be followed by a domain");
160 query_do(arg);
161 } else { /* arg[1] != '-', != '\0' */
162 invert= (arg[0] == '+');
163 ++arg;
164 while (*arg) {
165 oip= opt_finds(&arg);
166 if (oip->type == ot_funcarg) {
167 if (!*arg) {
168 arg= argv_p ? *++(*argv_p) : value;
169 if (!arg) usageerr("option -%s requires a value argument",oip->sopt);
170 } else {
171 if (value) usageerr("two values for option -%s given !",oip->sopt);
172 }
173 opt_do(oip,invert,arg,0);
174 arg= "";
175 } else {
176 if (value) usageerr("option -%s does not take a value",oip->sopt);
177 opt_do(oip,invert,0,0);
178 }
179 }
180 }
181 } else { /* arg[0] != '-' */
182 query_do(arg);
183 }
184}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
void opt_do(const struct optioninfo *oip, int invert, const char *arg, const char *arg2)
Definition: adh-opts.c:342
const struct optioninfo * opt_findl(const char *opt)
Definition: adh-opts.c:331
const struct optioninfo * opt_finds(const char **optp)
Definition: adh-opts.c:332
void query_do(const char *domain)
Definition: adh-query.c:138
GLboolean invert
Definition: gl.h:1949
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
@ ot_funcarg2
Definition: adnshost.h:65
@ ot_funcarg
Definition: adnshost.h:65
int value
Definition: adnshost.h:69
const char * lopt
Definition: adnshost.h:68
const char * sopt
Definition: adnshost.h:68
enum optioninfo::oi_type type
Definition: pdh_main.c:94

Referenced by main(), and read_stdin().

◆ quitnow()

static void quitnow ( int  rc)

Definition at line 42 of file adh-main.c.

42 {
43 if (ads) adns_finish(ads);
44 free(buf);
45 free(ov_id);
46 exit(rc);
47}
char * ov_id
Definition: adh-opts.c:40
ADNS_API void adns_finish(adns_state ads)
Definition: setup.c:650
#define free
Definition: debug_ros.c:5
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define exit(n)
Definition: config.h:202

Referenced by main(), of_help(), sysfail(), and usageerr().

◆ read_stdin()

static void read_stdin ( void  )
static

Definition at line 186 of file adh-main.c.

186 {
187 int anydone, r;
188 char *newline, *space;
189
190 anydone= 0;
191 while (!anydone || used) {
192 while (!(newline= memchr(buf,'\n',used))) {
193 if (used == avail) {
194 avail += 20; avail <<= 1;
196 if (!buf) sysfail("realloc stdin buffer",errno);
197 }
198 do {
199 r= read(0,buf+used,avail-used);
200 } while (r < 0 && errno == EINTR);
201 if (r == 0) {
202 if (used) {
203 /* fake up final newline */
204 buf[used++]= '\n';
205 r= 1;
206 } else {
207 ov_pipe= 0;
208 return;
209 }
210 }
211 if (r < 0) sysfail("read stdin",errno);
212 used += r;
213 }
214 *newline++= 0;
215 space= strchr(buf,' ');
216 if (space) *space++= 0;
218 used -= (newline-buf);
219 memmove(buf,newline,used);
220 anydone= 1;
221 }
222}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define read
Definition: acwin.h:96
static char * buf
Definition: adh-main.c:40
static int used
Definition: adh-main.c:39
static int avail
Definition: adh-main.c:39
#define realloc
Definition: debug_ros.c:6
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define memchr(s, c, n)
Definition: mkisofs.h:875

Referenced by main().

◆ sysfail()

void sysfail ( const char what,
int  errnoval 
)

Definition at line 49 of file adh-main.c.

49 {
50 fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval));
51 quitnow(10);
52}
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
const char * strerror(int err)
Definition: compat_str.c:23

Referenced by ensure_adns_init(), main(), of_help(), of_ptr(), of_reverse(), outerr(), print_dnsfail(), print_ttl(), printusage(), query_do(), query_done(), read_stdin(), test_SHDeleteKey(), and xmalloc().

◆ usageerr()

void usageerr ( const char fmt,
  ... 
)

Definition at line 54 of file adh-main.c.

54 {
55 va_list al;
56 fputs("adnshost usage error: ",stderr);
57 va_start(al,fmt);
59 va_end(al);
60 putc('\n',stderr);
61 quitnow(11);
62}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
Definition: dsound.c:943

Referenced by find(), main(), noninvert(), of_ptr(), of_reverse(), of_type(), prep_query(), and process_optarg().

◆ xmalloc()

void * xmalloc ( size_t  sz)

Definition at line 68 of file adh-main.c.

68 {
69 void *p;
70
71 p= malloc(sz); if (!p) sysfail("malloc",sz);
72 return p;
73}
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by xstrsave().

◆ xstrsave()

char * xstrsave ( const char str)

Definition at line 75 of file adh-main.c.

75 {
76 char *p;
77
78 p= xmalloc(strlen(str)+1);
79 strcpy(p,str);
80 return p;
81}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
void * xmalloc(size_t sz)
Definition: adh-main.c:68
const WCHAR * str

Variable Documentation

◆ avail

◆ buf

char* buf
static

Definition at line 40 of file adh-main.c.

Referenced by read_stdin().

◆ config_text

const char* config_text

Definition at line 37 of file adh-main.c.

Referenced by ensure_adns_init(), and of_config().

◆ rcode

int rcode

Definition at line 36 of file adh-main.c.

Referenced by adns__procdgram(), check_status(), and main().

◆ used