ReactOS  0.4.14-dev-52-g6116262
adnsresfilter.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <search.h>
#include <assert.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include "config.h"
#include "adns.h"
#include "dlist.h"
#include "tvarith.h"
#include "client.h"
Include dependency graph for adnsresfilter.c:

Go to the source code of this file.

Classes

struct  outqueuenode
 
struct  treething
 

Functions

static int nonblock (int fd, int isnonblock)
 
void quitnow (int exitstatus)
 
static void sysfail (const char *what) NONRETURNING
 
static voidxmalloc (size_t sz)
 
static void outputerr (void)
 
static void usage (void)
 
static void usageerr (const char *why) NONRETURNING
 
static void adnsfail (const char *what, int e) NONRETURNING
 
static void settimeout (const char *arg)
 
static void parseargs (const char *const *argv)
 
static void queueoutchar (int c)
 
static void queueoutstr (const char *str, int len)
 
static void writestdout (struct outqueuenode *entry)
 
static void replacetextwithname (struct outqueuenode *entry)
 
static void checkadnsqueries (void)
 
static void restartbuf (void)
 
static int comparer (const void *a, const void *b)
 
static void procaddr (void)
 
static void startaddr (void)
 
static void readstdin (void)
 
static void startup (void)
 
int main (int argc, const char *const *argv)
 

Variables

static int bracket
 
static int forever
 
static int address
 
static unsigned long timeout = 1000
 
static adns_rrtype rrt = adns_r_ptr
 
static adns_initflags initflags = 0
 
static const charconfig_text
 
static int outblocked
 
static int inputeof
 
struct {
   struct outqueuenode *   head
 
   struct outqueuenode *   tail
 
outqueue
 
static int peroutqueuenode
 
static int outqueuelen
 
static struct sockaddr_in sa
 
static adns_state ads
 
static char addrtextbuf [14]
 
static int cbyte
 
static int inbyte
 
static int inbuf
 
static unsigned char bytes [4]
 
static struct timeval printbefore
 
static struct treethingnewthing
 
static voidtreeroot
 

Function Documentation

◆ adnsfail()

static void adnsfail ( const char what,
int  e 
)
static

Definition at line 141 of file adnsresfilter.c.

141  {
142  fprintf(stderr,"adnsresfilter: adns call failed: %s: %s\n",what,strerror(e));
143  quitnow(2);
144 }
const char * strerror(int err)
Definition: compat_str.c:23
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define e
Definition: ke_i.h:82
void quitnow(int exitstatus)
Definition: adnsresfilter.c:96
FILE * stderr

Referenced by procaddr(), and startup().

◆ checkadnsqueries()

static void checkadnsqueries ( void  )
static

Definition at line 281 of file adnsresfilter.c.

281  {
282  adns_query qu;
283  adns_answer *ans;
284  void *context;
285  struct treething *foundthing;
286  int r;
287 
288  for (;;) {
289  qu= 0; context= 0; ans= 0;
290  r= adns_check(ads,&qu,&ans,&context);
291  if (r == ESRCH || r == EAGAIN) break;
292  assert(!r);
293  foundthing= context;
294  foundthing->ans= ans;
295  foundthing->qu= 0;
296  }
297 }
static adns_state ads
Definition: adnsresfilter.c:70
adns_answer * ans
Definition: adnsresfilter.c:80
Definition: http.c:6587
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define assert(x)
Definition: debug.h:53
adns_query qu
Definition: adnsresfilter.c:79
#define ESRCH
Definition: errno.h:9
Definition: arc.h:35
adns_query qu
Definition: adnshost.h:103
ADNS_API int adns_check(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r)
Definition: event.c:731

Referenced by main().

◆ comparer()

static int comparer ( const void a,
const void b 
)
static

Definition at line 304 of file adnsresfilter.c.

304  {
305  return memcmp(a,b,4);
306 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by procaddr().

◆ main()

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

Definition at line 411 of file adnsresfilter.c.

411  {
412  int r, maxfd;
413  fd_set readfds, writefds, exceptfds;
414  struct outqueuenode *entry;
415  struct timeval *tv, tvbuf, now;
416 
417  parseargs(argv);
418  startup();
419 
420  while (!inputeof || outqueue.head) {
421  maxfd= 2;
422  tv= 0;
423  FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
424  if ((entry= outqueue.head) && !outblocked) {
425  if (!entry->addr) {
427  continue;
428  }
429  if (entry->addr->ans) {
430  if (entry->addr->ans->nrrs)
432  entry->addr= 0;
433  continue;
434  }
435  r= gettimeofday(&now,0); if (r) sysfail("gettimeofday");
436  if (forever) {
437  tv= 0;
438  } else if (!timercmp(&now,&entry->printbefore,<)) {
439  entry->addr= 0;
440  continue;
441  } else {
442  tvbuf.tv_sec= entry->printbefore.tv_sec - now.tv_sec - 1;
443  tvbuf.tv_usec= entry->printbefore.tv_usec - now.tv_usec + 1000000;
444  tvbuf.tv_sec += tvbuf.tv_usec / 1000000;
445  tvbuf.tv_usec %= 1000000;
446  tv= &tvbuf;
447  }
448  adns_beforeselect(ads,&maxfd,&readfds,&writefds,&exceptfds,
449  &tv,&tvbuf,&now);
450  }
451  if (outblocked) FD_SET(1,&writefds);
452  if (!inputeof && outqueuelen<1024) FD_SET(0,&readfds);
453 
455  r= select(maxfd,&readfds,&writefds,&exceptfds,tv);
457  if (r < 0) { if (r == EINTR) continue; else sysfail("select"); }
458 
459  r= gettimeofday(&now,0); if (r) sysfail("gettimeofday");
460  adns_afterselect(ads,maxfd,&readfds,&writefds,&exceptfds,&now);
462 
463  if (FD_ISSET(0,&readfds)) {
464  if (!forever) {
465  printbefore= now;
467  }
468  readstdin();
469  } else if (FD_ISSET(1,&writefds)) {
470  outblocked= 0;
471  }
472  }
473  if (nonblock(0,0)) sysfail("un-nonblock stdin");
474  if (nonblock(1,0)) sysfail("un-nonblock stdout");
475  adns_finish(ads);
476  exit(0);
477 }
static adns_state ads
Definition: adnsresfilter.c:70
static void readstdin(void)
Definition: winsock.h:66
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 void adns_finish(adns_state ads)
Definition: setup.c:650
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define EINTR
Definition: acclib.h:80
static void writestdout(struct outqueuenode *entry)
unsigned long tv_sec
Definition: linux.h:1738
static struct @3829 outqueue
Definition: dhcpd.h:245
#define FD_ZERO(set)
Definition: winsock.h:96
#define argv
Definition: mplay32.c:18
#define FD_SET(fd, set)
Definition: winsock.h:89
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 gettimeofday(tv, tz)
Definition: adns_win32.h:159
#define FD_ISSET(fd, set)
Definition: winsock.h:100
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
time_t now
Definition: finger.c:65
unsigned long tv_usec
Definition: linux.h:1739
static int outblocked
Definition: adnsresfilter.c:65
static int outqueuelen
Definition: adnsresfilter.c:67
#define ADNS_CLEAR_ERRNO
Definition: adns_win32.h:108
static void timevaladd(struct timeval *tv_io, long ms)
Definition: tvarith.h:31
static void checkadnsqueries(void)
static void sysfail(const char *what) NONRETURNING
static void parseargs(const char *const *argv)
static int nonblock(int fd, int isnonblock)
Definition: adnsresfilter.c:86
uint32_t entry
Definition: isohybrid.c:63
static void startup(void)
static struct timeval printbefore
Definition: adnsresfilter.c:75
#define ADNS_CAPTURE_ERRNO
Definition: adns_win32.h:107
#define timercmp(tvp, uvp, cmp)
Definition: rdesktop.h:184
void exit(int exitcode)
Definition: _exit.c:33
static void replacetextwithname(struct outqueuenode *entry)
static int inputeof
Definition: adnsresfilter.c:65
static int forever
Definition: adnsresfilter.c:59

◆ nonblock()

static int nonblock ( int  fd,
int  isnonblock 
)
static

Definition at line 86 of file adnsresfilter.c.

86  {
87  int r;
88 
89  r= fcntl(fd,F_GETFL);
90  if (r==-1) return -1;
91  r= fcntl(fd,F_SETFL, isnonblock ? r|O_NONBLOCK : r&~O_NONBLOCK);
92  if (r==-1) return -1;
93  return 0;
94 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define O_NONBLOCK
Definition: port.h:158
static int fd
Definition: io.c:51

Referenced by main(), quitnow(), setup_connector_socket(), and startup().

◆ outputerr()

static void outputerr ( void  )
static

Definition at line 114 of file adnsresfilter.c.

115  { sysfail("write to stdout"); }
static void sysfail(const char *what) NONRETURNING

Referenced by usage().

◆ parseargs()

static void parseargs ( const char *const argv)
static

Definition at line 152 of file adnsresfilter.c.

152  {
153  const char *arg;
154  int c;
155 
156  while ((arg= *++argv)) {
157  if (arg[0] != '-') usageerr("no non-option arguments are allowed");
158  if (arg[1] == '-') {
159  if (!strcmp(arg,"--timeout")) {
160  if (!(arg= *++argv)) usageerr("--timeout needs a value");
161  settimeout(arg);
162  forever= 0;
163  } else if (!strcmp(arg,"--wait")) {
164  forever= 1;
165  } else if (!strcmp(arg,"--brackets")) {
166  bracket= 1;
167  } else if (!strcmp(arg,"--address")) {
168  address= 1;
169  } else if (!strcmp(arg,"--unchecked")) {
171  } else if (!strcmp(arg,"--config")) {
172  if (!(arg= *++argv)) usageerr("--config needs a value");
173  config_text= arg;
174  } else if (!strcmp(arg,"--debug")) {
176  } else if (!strcmp(arg,"--help")) {
177  usage(); quitnow(0);
178  } else if (!strcmp(arg,"--version")) {
179  VERSION_PRINT_QUIT("adnsresfilter"); quitnow(0);
180  } else {
181  usageerr("unknown long option");
182  }
183  } else {
184  while ((c= *++arg)) {
185  switch (c) {
186  case 't':
187  if (*++arg) settimeout(arg);
188  else if ((arg= *++argv)) settimeout(arg);
189  else usageerr("-t needs a value");
190  forever= 0;
191  arg= "\0";
192  break;
193  case 'w':
194  forever= 1;
195  break;
196  case 'b':
197  bracket= 1;
198  break;
199  case 'a':
200  address= 1;
201  break;
202  case 'u':
204  break;
205  case 'h':
206  usage();
207  quitnow(0);
208  default:
209  usageerr("unknown short option");
210  }
211  }
212  }
213  }
214 }
void * arg
Definition: msvc.h:12
static void usage(void)
#define argv
Definition: mplay32.c:18
void quitnow(int exitstatus)
Definition: adnsresfilter.c:96
static adns_rrtype rrt
Definition: adnsresfilter.c:61
static int bracket
Definition: adnsresfilter.c:59
const GLubyte * c
Definition: glext.h:8905
GLuint address
Definition: glext.h:9393
#define VERSION_PRINT_QUIT(program)
Definition: client.h:42
static const char * config_text
Definition: adnsresfilter.c:63
static adns_initflags initflags
Definition: adnsresfilter.c:62
#define c
Definition: ke_i.h:80
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static void usageerr(const char *why) NONRETURNING
static void settimeout(const char *arg)
static int forever
Definition: adnsresfilter.c:59

Referenced by main().

◆ procaddr()

static void procaddr ( void  )
static

Definition at line 308 of file adnsresfilter.c.

308  {
309  struct treething *foundthing;
310  void **searchfound;
311  struct outqueuenode *entry;
312  int r;
313 
314  if (!newthing) {
315  newthing= xmalloc(sizeof(struct treething));
316  newthing->qu= 0;
317  newthing->ans= 0;
318  }
319 
320  memcpy(newthing->bytes,bytes,4);
321  searchfound= tsearch(newthing,&treeroot,comparer);
322  if (!searchfound) sysfail("tsearch");
323  foundthing= *searchfound;
324 
325  if (foundthing == newthing) {
326  newthing= 0;
327  memcpy(&sa.sin_addr,bytes,4);
328  r= adns_submit_reverse(ads, (const struct sockaddr*)&sa,
329  rrt,0,foundthing,&foundthing->qu);
330  if (r) adnsfail("submit",r);
331  }
332  entry= xmalloc(sizeof(*entry));
333  entry->buffer= xmalloc(inbuf);
334  entry->textp= entry->buffer;
335  memcpy(entry->textp,addrtextbuf,inbuf);
336  entry->textlen= inbuf;
337  entry->addr= foundthing;
338  entry->printbefore= printbefore;
340  outqueuelen++;
341  inbuf= 0;
342  cbyte= -1;
343 }
static adns_state ads
Definition: adnsresfilter.c:70
static void * xmalloc(size_t sz)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
ADNS_API int adns_submit_reverse(adns_state ads, const struct sockaddr *addr, adns_rrtype type, adns_queryflags flags, void *context, adns_query *query_r)
Definition: query.c:304
static int inbuf
Definition: adnsresfilter.c:73
static struct @3829 outqueue
adns_query qu
Definition: adnsresfilter.c:79
static void * treeroot
Definition: adnsresfilter.c:84
static void adnsfail(const char *what, int e) NONRETURNING
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static struct treething * newthing
Definition: adnsresfilter.c:83
static int outqueuelen
Definition: adnsresfilter.c:67
static int cbyte
Definition: adnsresfilter.c:73
static void sysfail(const char *what) NONRETURNING
static adns_rrtype rrt
Definition: adnsresfilter.c:61
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static struct timeval printbefore
Definition: adnsresfilter.c:75
static char addrtextbuf[14]
Definition: adnsresfilter.c:72
static int comparer(const void *a, const void *b)
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

Referenced by readstdin().

◆ queueoutchar()

static void queueoutchar ( int  c)
static

Definition at line 216 of file adnsresfilter.c.

216  {
217  struct outqueuenode *entry;
218 
219  entry= outqueue.tail;
220  if (!entry || entry->addr || entry->textlen >= peroutqueuenode) {
221  peroutqueuenode= !peroutqueuenode || !entry || entry->addr ? 128 :
222  peroutqueuenode >= 1024 ? 4096 : peroutqueuenode<<2;
223  entry= xmalloc(sizeof(*entry));
224  entry->buffer= xmalloc(peroutqueuenode);
225  entry->textp= entry->buffer;
226  entry->textlen= 0;
227  entry->addr= 0;
229  outqueuelen++;
230  }
231  entry->textp[entry->textlen++]= c;
232 }
static void * xmalloc(size_t sz)
static struct @3829 outqueue
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
static int outqueuelen
Definition: adnsresfilter.c:67
uint32_t entry
Definition: isohybrid.c:63
#define c
Definition: ke_i.h:80
static int peroutqueuenode
Definition: adnsresfilter.c:67

Referenced by queueoutstr(), and readstdin().

◆ queueoutstr()

static void queueoutstr ( const char str,
int  len 
)
static

Definition at line 234 of file adnsresfilter.c.

234  {
235  while (len-- > 0) queueoutchar(*str++);
236 }
const WCHAR * str
GLenum GLsizei len
Definition: glext.h:6722
static void queueoutchar(int c)

Referenced by restartbuf().

◆ quitnow()

void quitnow ( int  exitstatus)

Definition at line 96 of file adnsresfilter.c.

96  {
97  nonblock(0,0);
98  nonblock(1,0);
99  exit(exitstatus);
100 }
static int nonblock(int fd, int isnonblock)
Definition: adnsresfilter.c:86
void exit(int exitcode)
Definition: _exit.c:33

Referenced by adnsfail(), parseargs(), sysfail(), and usageerr().

◆ readstdin()

static void readstdin ( void  )
static

Definition at line 350 of file adnsresfilter.c.

350  {
351  char readbuf[512], *p;
352  int r, c, nbyte;
353 
354  while ((r= read(0,readbuf,sizeof(readbuf))) <= 0) {
355  if (r == 0) { inputeof= 1; return; }
356  if (r == EAGAIN) return;
357  if (r != EINTR) sysfail("read stdin");
358  }
359  for (p=readbuf; r>0; r--,p++) {
360  c= *p;
361  if (cbyte==-1 && bracket && c=='[') {
362  addrtextbuf[inbuf++]= c;
363  startaddr();
364  } else if (cbyte==-1 && !bracket && !isalnum(c)) {
365  queueoutchar(c);
366  startaddr();
367  } else if (cbyte>=0 && inbyte<3 && c>='0' && c<='9' &&
368  (nbyte= bytes[cbyte]*10 + (c-'0')) <= 255) {
369  bytes[cbyte]= nbyte;
370  addrtextbuf[inbuf++]= c;
371  inbyte++;
372  } else if (cbyte>=0 && cbyte<3 && inbyte>0 && c=='.') {
373  bytes[++cbyte]= 0;
374  addrtextbuf[inbuf++]= c;
375  inbyte= 0;
376  } else if (cbyte==3 && inbyte>0 && bracket && c==']') {
377  addrtextbuf[inbuf++]= c;
378  procaddr();
379  } else if (cbyte==3 && inbyte>0 && !bracket && !isalnum(c)) {
380  procaddr();
381  queueoutchar(c);
382  startaddr();
383  } else {
384  restartbuf();
385  queueoutchar(c);
386  cbyte= -1;
387  if (!bracket && !isalnum(c)) startaddr();
388  }
389  }
390 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define EINTR
Definition: acclib.h:80
static int inbuf
Definition: adnsresfilter.c:73
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
static void procaddr(void)
static int inbyte
Definition: adnsresfilter.c:73
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
Definition: arc.h:35
static int cbyte
Definition: adnsresfilter.c:73
static void sysfail(const char *what) NONRETURNING
static int bracket
Definition: adnsresfilter.c:59
const GLubyte * c
Definition: glext.h:8905
static void restartbuf(void)
static void startaddr(void)
static char addrtextbuf[14]
Definition: adnsresfilter.c:72
#define c
Definition: ke_i.h:80
static void queueoutchar(int c)
GLfloat GLfloat p
Definition: glext.h:8902
static int inputeof
Definition: adnsresfilter.c:65
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by main().

◆ replacetextwithname()

static void replacetextwithname ( struct outqueuenode entry)
static

Definition at line 260 of file adnsresfilter.c.

260  {
261  char *name, *newbuf;
262  int namelen, newlen;
263 
264  name= entry->addr->ans->rrs.str[0];
265  namelen= strlen(name);
266  if (!address) {
267  free(entry->buffer);
268  entry->buffer= 0;
269  entry->textp= name;
270  entry->textlen= namelen;
271  } else {
272  newlen= entry->textlen + namelen + (bracket ? 0 : 2);
273  newbuf= xmalloc(newlen + 1);
274  sprintf(newbuf, bracket ? "%s%.*s" : "%s[%.*s]", name, entry->textlen, entry->textp);
275  free(entry->buffer);
276  entry->buffer= entry->textp= newbuf;
277  entry->textlen= newlen;
278  }
279 }
static void * xmalloc(size_t sz)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
GLint namelen
Definition: glext.h:7232
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static int bracket
Definition: adnsresfilter.c:59
GLuint address
Definition: glext.h:9393
uint32_t entry
Definition: isohybrid.c:63
Definition: name.c:36
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by main().

◆ restartbuf()

static void restartbuf ( void  )
static

Definition at line 299 of file adnsresfilter.c.

299  {
301  inbuf= 0;
302 }
static void queueoutstr(const char *str, int len)
static int inbuf
Definition: adnsresfilter.c:73
static char addrtextbuf[14]
Definition: adnsresfilter.c:72

Referenced by readstdin().

◆ settimeout()

static void settimeout ( const char arg)
static

Definition at line 146 of file adnsresfilter.c.

146  {
147  char *ep;
148  timeout= strtoul(arg,&ep,0);
149  if (*ep) usageerr("invalid timeout");
150 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
Definition: dhcpd.h:245
static void usageerr(const char *why) NONRETURNING

Referenced by parseargs().

◆ startaddr()

static void startaddr ( void  )
static

Definition at line 345 of file adnsresfilter.c.

345  {
346  bytes[cbyte=0]= 0;
347  inbyte= 0;
348 }
static int inbyte
Definition: adnsresfilter.c:73
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static int cbyte
Definition: adnsresfilter.c:73

Referenced by add_checksum_entry(), readstdin(), and startup().

◆ startup()

static void startup ( void  )
static

Definition at line 392 of file adnsresfilter.c.

392  {
393  int r;
394 
395  if (nonblock(0,1)) sysfail("set stdin to nonblocking mode");
396  if (nonblock(1,1)) sysfail("set stdout to nonblocking mode");
397  memset(&sa,0,sizeof(sa));
398  sa.sin_family= AF_INET;
399  if (config_text) {
401  } else {
402  r= adns_init(&ads,initflags,0);
403  }
404  if (r) adnsfail("init",r);
405  cbyte= -1;
406  inbyte= -1;
407  inbuf= 0;
408  if (!bracket) startaddr();
409 }
static adns_state ads
Definition: adnsresfilter.c:70
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static int inbuf
Definition: adnsresfilter.c:73
static void adnsfail(const char *what, int e) NONRETURNING
static int inbyte
Definition: adnsresfilter.c:73
static int cbyte
Definition: adnsresfilter.c:73
ADNS_API int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags, FILE *diagfile, const char *configtext)
Definition: setup.c:629
static void sysfail(const char *what) NONRETURNING
static int bracket
Definition: adnsresfilter.c:59
static int nonblock(int fd, int isnonblock)
Definition: adnsresfilter.c:86
static void startaddr(void)
ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:568
static const char * config_text
Definition: adnsresfilter.c:63
static adns_initflags initflags
Definition: adnsresfilter.c:62
FILE * stderr
#define AF_INET
Definition: tcpip.h:117
#define memset(x, y, z)
Definition: compat.h:39
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

Referenced by main().

◆ sysfail()

static void sysfail ( const char what)
static

Definition at line 103 of file adnsresfilter.c.

103  {
104  fprintf(stderr,"adnsresfilter: system call failed: %s: %s\n",what,strerror(errno));
105  quitnow(2);
106 }
int errno
const char * strerror(int err)
Definition: compat_str.c:23
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
void quitnow(int exitstatus)
Definition: adnsresfilter.c:96
FILE * stderr

Referenced by main(), outputerr(), procaddr(), readstdin(), startup(), usage(), writestdout(), and xmalloc().

◆ usage()

static void usage ( void  )
static

Definition at line 117 of file adnsresfilter.c.

117  {
118  if (printf("usage: adnsresfilter [<options ...>]\n"
119  " adnsresfilter -h|--help | --version\n"
120  "options: -t<milliseconds>|--timeout <milliseconds>\n"
121  " -w|--wait (always wait for queries to time out or fail)\n"
122  " -b|--brackets (require [...] around IP addresses)\n"
123  " -a|--address (always include [address] in output)\n"
124  " -u|--unchecked (do not forward map for checking)\n"
125  " --config <text> (use this instead of resolv.conf)\n"
126  " --debug (turn on adns resolver debugging)\n"
127  "Timeout is the maximum amount to delay any particular bit of output for.\n"
128  "Lookups will go on in the background. Default timeout = 1000 (ms).\n")
129  == EOF) outputerr();
130  if (fflush(stdout)) sysfail("flush stdout");
131 }
static void outputerr(void)
FILE * stdout
static void sysfail(const char *what) NONRETURNING
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define EOF
Definition: stdio.h:24
#define printf
Definition: config.h:203

Referenced by parseargs(), and usageerr().

◆ usageerr()

static void usageerr ( const char why)
static

Definition at line 134 of file adnsresfilter.c.

134  {
135  fprintf(stderr,"adnsresfilter: bad usage: %s\n",why);
136  usage();
137  quitnow(1);
138 }
static void usage(void)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
void quitnow(int exitstatus)
Definition: adnsresfilter.c:96
FILE * stderr

Referenced by parseargs(), and settimeout().

◆ writestdout()

static void writestdout ( struct outqueuenode entry)
static

Definition at line 238 of file adnsresfilter.c.

238  {
239  int r;
240 
241  while (entry->textlen) {
242  r= write(1, entry->textp, entry->textlen);
243  if (r < 0) {
244  if (errno == EINTR) continue;
245  if (errno == EAGAIN) { outblocked= 1; break; }
246  sysfail("write stdout");
247  }
249  entry->textp += r;
250  entry->textlen -= r;
251  }
252  if (!entry->textlen) {
254  free(entry->buffer);
255  free(entry);
256  outqueuelen--;
257  }
258 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
#define EINTR
Definition: acclib.h:80
static struct @3829 outqueue
#define assert(x)
Definition: debug.h:53
int errno
#define write
Definition: acwin.h:97
static int outblocked
Definition: adnsresfilter.c:65
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
Definition: arc.h:35
static int outqueuelen
Definition: adnsresfilter.c:67
static void sysfail(const char *what) NONRETURNING
uint32_t entry
Definition: isohybrid.c:63

Referenced by main().

◆ xmalloc()

static void* xmalloc ( size_t  sz)
static

Definition at line 108 of file adnsresfilter.c.

108  {
109  void *r;
110  r= malloc(sz); if (r) return r;
111  sysfail("malloc");
112 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static void sysfail(const char *what) NONRETURNING
#define malloc
Definition: debug_ros.c:4

Referenced by procaddr(), queueoutchar(), and replacetextwithname().

Variable Documentation

◆ address

int address
static

Definition at line 59 of file adnsresfilter.c.

◆ addrtextbuf

char addrtextbuf[14]
static

Definition at line 72 of file adnsresfilter.c.

Referenced by procaddr(), readstdin(), and restartbuf().

◆ ads

adns_state ads
static

Definition at line 70 of file adnsresfilter.c.

Referenced by checkadnsqueries(), main(), procaddr(), and startup().

◆ bracket

int bracket
static

◆ bytes

unsigned char bytes[4]
static

Definition at line 74 of file adnsresfilter.c.

Referenced by _bdf_readstream(), _enumerateProvidersW(), _setmbcp_l(), _TIFFCheckRealloc(), _TIFFMultiply32(), _TIFFMultiply64(), advance_stream(), audio_membuffer::alloc_bytes(), audio_membuffer::alloc_mem_(), audio_membuffer::audio_membuffer(), audio_producer::backward(), bytes_to_ms(), bytes_to_samples(), cert_find_alt_name_entry(), cert_get_name_from_rdn_attr(), cert_name_to_str_with_indent(), CertGetNameStringW(), CertNameToStrA(), cff_index_get_name(), check_native_ie(), check_position(), check_storage_contents(), checksum(), copy(), create_test_file(), customWordBreakProc(), d3dx9_base_effect_get_value(), d3dx9_base_effect_set_value(), d3dx9_texture_shader_SetValue(), d3dx_include_from_file_open(), DECLARE_INTERFACE(), DECLARE_INTERFACE_(), do_process_key(), EMFDRV_GdiComment(), encodeBase64(), encodeBase64A(), encodeBase64W(), fdi_decomp(), feed_back_bytes(), format_bytes(), format_hash(), format_size(), audio_producer::forward(), gl_alloc_alpha_buffers(), gl_unpack_image(), gl_unpack_pixels(), http_receive(), hw_check_device(), ID3DXConstantTableImpl_SetValue(), ID3DXEffect25Impl_GetValue(), ID3DXEffect25Impl_SetValue(), ID3DXEffectCompilerImpl_GetValue(), ID3DXEffectCompilerImpl_SetValue(), ID3DXEffectImpl_GetValue(), ID3DXEffectImpl_SetValue(), ide_read(), idealsendbacklognotify(), idealsendbacklogquery(), IDirectPlay4AImpl_GetMessageQueue(), IDirectPlay4Impl_GetMessageQueue(), iocp_async_closesocket(), iocp_async_read(), iocp_async_read_closesocket(), iocp_async_read_thread(), iocp_async_read_thread_closesocket(), local_server_thread(), main(), mpg123_decode_frame(), mpg123_framebyframe_decode(), MSRLE32_CompressRLE4Line(), ParseStringSecurityDescriptorToSecurityDescriptor(), PCF_Glyph_Load(), procaddr(), propset_private_tests(), ps_hints_t2counter(), ps_hints_t2mask(), ps_parser_to_bytes(), ptransfer(), audio_membuffer::read(), read_backing_store(), read_clipformat(), read_raw_int(), read_table_int(), readstdin(), TCPSocketObject::recv(), recvrequest(), audio_membuffer::resize_bytes(), audio_format::samples_in_bytes(), TCPSocketObject::send(), sendrequest(), serial_get_event(), setByteArray(), SetupCreateDiskSpaceListW(), startaddr(), stream_back_bytes(), subtract_bytes(), test_async_read(), test_file_access(), test_file_security(), test_FlushFileBuffers(), test_GetDIBits(), test_LoadIconWithScaleDown(), test_no_stop(), test_nodeTypedValue(), test_read_write(), test_ReadConsole(), test_registrar(), test_select_object(), test_service(), test_WaitCommEvent(), test_waittxempty(), TestMessageHandler(), testNotifyAddrChange(), thunk_PSecPkgInfoWToA(), token_to_str(), TV1_GetDependants(), unintr_read(), unintr_write(), UserInitHandleTable(), W8_16(), write_backing_store(), write_watch_thread(), and wsa_recv_thread().

◆ cbyte

◆ config_text

const char* config_text
static

Definition at line 63 of file adnsresfilter.c.

Referenced by parseargs(), and startup().

◆ forever

int forever
static

Definition at line 59 of file adnsresfilter.c.

Referenced by main(), and parseargs().

◆ head

◆ inbuf

int inbuf
static

Definition at line 73 of file adnsresfilter.c.

Referenced by procaddr(), readstdin(), restartbuf(), and startup().

◆ inbyte

int inbyte
static

Definition at line 73 of file adnsresfilter.c.

Referenced by readstdin(), startaddr(), and startup().

◆ initflags

adns_initflags initflags = 0
static

Definition at line 62 of file adnsresfilter.c.

Referenced by ensure_adns_init(), main(), parseargs(), proclog(), and startup().

◆ inputeof

int inputeof
static

Definition at line 65 of file adnsresfilter.c.

Referenced by main(), and readstdin().

◆ newthing

struct treething* newthing
static

Definition at line 83 of file adnsresfilter.c.

Referenced by procaddr().

◆ outblocked

int outblocked
static

Definition at line 65 of file adnsresfilter.c.

Referenced by main(), and writestdout().

◆ outqueue

struct { ... } outqueue

◆ outqueuelen

int outqueuelen
static

Definition at line 67 of file adnsresfilter.c.

Referenced by main(), procaddr(), queueoutchar(), and writestdout().

◆ peroutqueuenode

int peroutqueuenode
static

Definition at line 67 of file adnsresfilter.c.

Referenced by queueoutchar().

◆ printbefore

struct timeval printbefore
static

Definition at line 75 of file adnsresfilter.c.

Referenced by main(), and procaddr().

◆ rrt

adns_rrtype rrt = adns_r_ptr
static

Definition at line 61 of file adnsresfilter.c.

Referenced by parseargs(), and procaddr().

◆ sa

struct sockaddr_in sa
static

Definition at line 69 of file adnsresfilter.c.

Referenced by __rpc_get_local_uid(), _pipe(), _tpopen(), _wsopen_s(), AddrStrToAddr(), adns__sigpipe_protect(), bindresvport_sa(), check_safearray(), ClOleCommandTarget_Exec(), ConnectToReactOSWebsite(), create_safearray_iter(), create_vbarray(), CreateClientProcess(), CreateHiddenConsoleProcess(), CreateInheritableDesktop(), CreateInheritableWinsta(), CreateSocket(), dictionary_Items(), dictionary_Keys(), doc_complex_write(), doc_write(), find_prop(), FT_MulFix(), get_dnshostname(), get_properties(), get_safearray_size(), getnameinfo(), Global_Array(), Global_UBound(), handle_navigation_error(), TMapLoader::LookForPart(), main(), make_listening_socket(), make_safearray(), mp_add(), mp_sub(), netconn_resolve(), of_ptr(), of_reverse(), OleCommandTarget_Exec(), open_http(), piaddr(), procaddr(), request_send(), resolve_hostname(), rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(), run_cmd(), sc_cb_open(), ScriptApplyLogicalWidth(), ScriptBreak(), ScriptGetLogicalWidths(), server_thread(), sparse_array_add(), sparse_array_find(), sparse_array_init(), sparse_array_length(), sparse_array_lookup(), start_server(), START_TEST(), startup(), test_AddMandatoryAce(), test_Console(), test_CreateDirectoryA(), test_CreateFileW(), test_default_dacl_owner_sid(), test_event(), test_extendedSocketOptions(), test_file_inherit(), test_getpeername(), test_GetProp(), test_invalid_stdin(), test_LockUnlock(), test_maximum_allowed(), test_safearray_layout(), test_SafeArrayAllocDestroyDescriptor(), test_SafeArrayChangeTypeEx(), test_SafeArrayClear(), test_SafeArrayCopy(), test_SafeArrayCopyData(), test_SafeArrayCreateEx(), test_SafeArrayCreateLockDestroy(), test_SafeArrayDestroyData(), test_SafeArrayGetPutElement(), test_SafeArrayGetPutElement_BSTR(), test_SafeArrayGetPutElement_IUnknown(), test_SafeArrayGetPutElement_VARIANT(), test_SafeArrayRedim_IUnknown(), test_saxreader(), test_ScriptGetLogicalWidths(), test_ScriptXtoX(), test_stdout_handle(), test_token_security_descriptor(), test_VectorCreateLockDestroy(), to_bstr_array(), to_byte_array(), to_i4_array(), WaitForConnect(), winhttp_request_get_ResponseBody(), WshShell3_RegRead(), and WspiapiGetNameInfo().

◆ tail

◆ timeout

unsigned long timeout = 1000
static

Definition at line 60 of file adnsresfilter.c.

◆ treeroot

void* treeroot
static

Definition at line 84 of file adnsresfilter.c.

Referenced by procaddr().