void usageerr(const char *fmt, ...) { va_list al; fputs("adnshost usage error: ",stderr); va_start(al,fmt); vfprintf(stderr,fmt,al); va_end(al); putc('\n',stderr); quitnow(11); }
int main(int argc, const char *const *argv) { struct timeval *tv, tvbuf; adns_query qu; void *qun_v; adns_answer *answer; int r, maxfd; fd_set readfds, writefds, exceptfds; const char *arg; ensure_adns_init(); while ((arg= *++argv)) process_optarg(arg,&argv,0); if (!ov_pipe && !ads) usageerr("no domains given, and -f/--pipe not used; try --help"); for (;;) { for (;;) { qu= ov_asynch ? 0 : outstanding.head ? outstanding.head->qu : 0; r= adns_check(ads,&qu,&answer,&qun_v); if ((r == EAGAIN) || (r == EWOULDBLOCK)) break; if (r == ESRCH) { if (!ov_pipe) goto x_quit; else break; } assert(!r); query_done(qun_v,answer); } maxfd= 0; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); if (ov_pipe) { maxfd= 1; FD_SET(0,&readfds); } tv= 0; adns_beforeselect(ads, &maxfd, &readfds,&writefds,&exceptfds, &tv,&tvbuf,0); ADNS_CLEAR_ERRNO; r= select(maxfd, &readfds,&writefds,&exceptfds, tv); ADNS_CAPTURE_ERRNO; if (r == -1) { if (errno == EINTR) continue; sysfail("select",errno); } adns_afterselect(ads, maxfd, &readfds,&writefds,&exceptfds, 0); if (ov_pipe && FD_ISSET(0,&readfds)) read_stdin(); } x_quit: if (fclose(stdout)) outerr(); quitnow(rcode); }
void of_help(const struct optioninfo *oi, const char *arg, const char *arg2) { printusage(); if (fclose(stdout)) sysfail("finish writing output",errno); quitnow(0); }
void sysfail(const char *what, int errnoval) { fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval)); quitnow(10); }