ReactOS 0.4.15-dev-7942-gd23573b
internal.h File Reference
#include "config.h"
#include <stdarg.h>
#include <assert.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include "adns.h"
#include "dlist.h"
Include dependency graph for internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  rr_align
 
struct  vbuf
 
struct  parseinfo
 
struct  typeinfo
 
struct  allocnode
 
union  maxalign
 
struct  qcontext
 
struct  adns__query
 
struct  query_queue
 
struct  adns__state
 
struct  adns__state::server
 
struct  adns__state::sortlist
 
struct  findlabel_state
 

Macros

#define MAXSERVERS   5
 
#define MAXSORTLIST   15
 
#define UDPMAXRETRIES   15
 
#define UDPRETRYMS   2000
 
#define TCPWAITMS   30000
 
#define TCPCONNMS   14000
 
#define TCPIDLEMS   30000
 
#define MAXTTLBELIEVE   (7*86400) /* any TTL > 7 days is capped */
 
#define DNS_PORT   53
 
#define DNS_MAXUDP   512
 
#define DNS_MAXLABEL   63
 
#define DNS_MAXDOMAIN   255
 
#define DNS_HDRSIZE   12
 
#define DNS_IDOFFSET   0
 
#define DNS_CLASS_IN   1
 
#define DNS_INADDR_ARPA   "in-addr", "arpa"
 
#define MAX_POLLFDS   ADNS_POLLFDS_RECOMMENDED
 
#define MEM_ROUND(sz)
 
#define GETIL_B(cb)   (((dgram)[(cb)++]) & 0x0ff)
 
#define GET_B(cb, tv)   ((tv)= GETIL_B((cb)))
 
#define GET_W(cb, tv)   ((tv)=0, (tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb), (tv))
 
#define GET_L(cb, tv)
 

Typedefs

typedef unsigned char byte
 
typedef struct allocnode allocnode
 

Enumerations

enum  consistency_checks { cc_user , cc_entex , cc_freq }
 
enum  dns_rcode {
  rcode_noerror , rcode_formaterror , rcode_servfail , rcode_nxdomain ,
  rcode_notimp , rcode_refused
}
 
enum  parsedomain_flags { pdf_quoteok = 0x001 }
 

Functions

int adns__setnonblock (adns_state ads, ADNS_SOCKET fd)
 
void adns__vdiag (adns_state ads, const char *pfx, adns_initflags prevent, int serv, adns_query qu, const char *fmt, va_list al)
 
void adns__debug (adns_state ads, int serv, adns_query qu, const char *fmt,...) PRINTFFORMAT(4
 
void void adns__warn (adns_state ads, int serv, adns_query qu, const char *fmt,...) PRINTFFORMAT(4
 
void void void adns__diag (adns_state ads, int serv, adns_query qu, const char *fmt,...) PRINTFFORMAT(4
 
void void void int adns__vbuf_ensure (vbuf *vb, int want)
 
int adns__vbuf_appendstr (vbuf *vb, const char *data)
 
int adns__vbuf_append (vbuf *vb, const byte *data, int len)
 
void adns__vbuf_appendq (vbuf *vb, const byte *data, int len)
 
void adns__vbuf_init (vbuf *vb)
 
void adns__vbuf_free (vbuf *vb)
 
const charadns__diag_domain (adns_state ads, int serv, adns_query qu, vbuf *vb, const byte *dgram, int dglen, int cbyte)
 
void adns__isort (void *array, int nobjs, int sz, void *tempbuf, int(*needswap)(void *context, const void *a, const void *b), void *context)
 
void adns__sigpipe_protect (adns_state)
 
void adns__sigpipe_unprotect (adns_state)
 
adns_status adns__mkquery (adns_state ads, vbuf *vb, int *id_r, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags)
 
adns_status adns__mkquery_frdgram (adns_state ads, vbuf *vb, int *id_r, const byte *qd_dgram, int qd_dglen, int qd_begin, adns_rrtype type, adns_queryflags flags)
 
void adns__querysend_tcp (adns_query qu, struct timeval now)
 
void adns__query_send (adns_query qu, struct timeval now)
 
adns_status adns__internal_submit (adns_state ads, adns_query *query_r, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now, const qcontext *ctx)
 
void adns__search_next (adns_state ads, adns_query qu, struct timeval now)
 
voidadns__alloc_interim (adns_query qu, size_t sz)
 
voidadns__alloc_preserved (adns_query qu, size_t sz)
 
void adns__transfer_interim (adns_query from, adns_query to, void *block, size_t sz)
 
voidadns__alloc_mine (adns_query qu, size_t sz)
 
voidadns__alloc_final (adns_query qu, size_t sz)
 
void adns__makefinal_block (adns_query qu, void **blpp, size_t sz)
 
void adns__makefinal_str (adns_query qu, char **strp)
 
void adns__reset_preserved (adns_query qu)
 
void adns__query_done (adns_query qu)
 
void adns__query_fail (adns_query qu, adns_status stat)
 
void adns__procdgram (adns_state ads, const byte *dgram, int len, int serv, int viatcp, struct timeval now)
 
const typeinfoadns__findtype (adns_rrtype type)
 
void adns__findlabel_start (findlabel_state *fls, adns_state ads, int serv, adns_query qu, const byte *dgram, int dglen, int max, int dmbegin, int *dmend_rlater)
 
adns_status adns__findlabel_next (findlabel_state *fls, int *lablen_r, int *labstart_r)
 
adns_status adns__parse_domain (adns_state ads, int serv, adns_query qu, vbuf *vb, adns_queryflags flags, const byte *dgram, int dglen, int *cbyte_io, int max)
 
adns_status adns__parse_domain_more (findlabel_state *fls, adns_state ads, adns_query qu, vbuf *vb, parsedomain_flags flags, const byte *dgram)
 
adns_status adns__findrr (adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r)
 
adns_status adns__findrr_anychk (adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, const byte *eo_dgram, int eo_dglen, int eo_cbyte, int *eo_matched_r)
 
void adns__update_expires (adns_query qu, unsigned long ttl, struct timeval now)
 
int vbuf__append_quoted1035 (vbuf *vb, const byte *buf, int len)
 
void adns__tcp_broken (adns_state ads, const char *what, const char *why)
 
void adns__tcp_tryconnect (adns_state ads, struct timeval now)
 
void adns__autosys (adns_state ads, struct timeval now)
 
void adns__must_gettimeofday (adns_state ads, const struct timeval **now_io, struct timeval *tv_buf)
 
int adns__pollfds (adns_state ads, struct pollfd pollfds_buf[MAX_POLLFDS])
 
void adns__fdevents (adns_state ads, const struct pollfd *pollfds, int npollfds, int maxfd, const fd_set *readfds, const fd_set *writefds, const fd_set *exceptfds, struct timeval now, int *r_r)
 
int adns__internal_check (adns_state ads, adns_query *query_io, adns_answer **answer, void **context_r)
 
void adns__timeouts (adns_state ads, int act, struct timeval **tv_io, struct timeval *tvbuf, struct timeval now)
 
void adns__consistency (adns_state ads, adns_query qu, consistency_checks cc)
 
static int ctype_whitespace (int c)
 
static int ctype_digit (int c)
 
static int ctype_alpha (int c)
 
static int ctype_822special (int c)
 
static int ctype_domainunquoted (int c)
 
static int errno_resources (int e)
 

Macro Definition Documentation

◆ DNS_CLASS_IN

#define DNS_CLASS_IN   1

Definition at line 78 of file internal.h.

◆ DNS_HDRSIZE

#define DNS_HDRSIZE   12

Definition at line 76 of file internal.h.

◆ DNS_IDOFFSET

#define DNS_IDOFFSET   0

Definition at line 77 of file internal.h.

◆ DNS_INADDR_ARPA

#define DNS_INADDR_ARPA   "in-addr", "arpa"

Definition at line 80 of file internal.h.

◆ DNS_MAXDOMAIN

#define DNS_MAXDOMAIN   255

Definition at line 75 of file internal.h.

◆ DNS_MAXLABEL

#define DNS_MAXLABEL   63

Definition at line 74 of file internal.h.

◆ DNS_MAXUDP

#define DNS_MAXUDP   512

Definition at line 73 of file internal.h.

◆ DNS_PORT

#define DNS_PORT   53

Definition at line 72 of file internal.h.

◆ GET_B

#define GET_B (   cb,
  tv 
)    ((tv)= GETIL_B((cb)))

Definition at line 716 of file internal.h.

◆ GET_L

#define GET_L (   cb,
  tv 
)
Value:
( (tv)=0, \
(tv)|=(GETIL_B((cb))<<24), \
(tv)|=(GETIL_B((cb))<<16), \
(tv)|=(GETIL_B((cb))<<8), \
(tv)|=GETIL_B(cb), \
(tv) )
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define GETIL_B(cb)
Definition: internal.h:715

Definition at line 718 of file internal.h.

◆ GET_W

#define GET_W (   cb,
  tv 
)    ((tv)=0, (tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb), (tv))

Definition at line 717 of file internal.h.

◆ GETIL_B

#define GETIL_B (   cb)    (((dgram)[(cb)++]) & 0x0ff)

Definition at line 715 of file internal.h.

◆ MAX_POLLFDS

#define MAX_POLLFDS   ADNS_POLLFDS_RECOMMENDED

Definition at line 82 of file internal.h.

◆ MAXSERVERS

#define MAXSERVERS   5

Definition at line 63 of file internal.h.

◆ MAXSORTLIST

#define MAXSORTLIST   15

Definition at line 64 of file internal.h.

◆ MAXTTLBELIEVE

#define MAXTTLBELIEVE   (7*86400) /* any TTL > 7 days is capped */

Definition at line 70 of file internal.h.

◆ MEM_ROUND

#define MEM_ROUND (   sz)
Value:
(( ((sz)+sizeof(union maxalign)-1) / sizeof(union maxalign) ) \
* sizeof(union maxalign) )

Definition at line 711 of file internal.h.

◆ TCPCONNMS

#define TCPCONNMS   14000

Definition at line 68 of file internal.h.

◆ TCPIDLEMS

#define TCPIDLEMS   30000

Definition at line 69 of file internal.h.

◆ TCPWAITMS

#define TCPWAITMS   30000

Definition at line 67 of file internal.h.

◆ UDPMAXRETRIES

#define UDPMAXRETRIES   15

Definition at line 65 of file internal.h.

◆ UDPRETRYMS

#define UDPRETRYMS   2000

Definition at line 66 of file internal.h.

Typedef Documentation

◆ allocnode

◆ byte

typedef unsigned char byte

Definition at line 36 of file internal.h.

Enumeration Type Documentation

◆ consistency_checks

Enumerator
cc_user 
cc_entex 
cc_freq 

Definition at line 84 of file internal.h.

84 {
85 cc_user,
consistency_checks
Definition: internal.h:84
@ cc_user
Definition: internal.h:85
@ cc_freq
Definition: internal.h:87
@ cc_entex
Definition: internal.h:86

◆ dns_rcode

Enumerator
rcode_noerror 
rcode_formaterror 
rcode_servfail 
rcode_nxdomain 
rcode_notimp 
rcode_refused 

Definition at line 90 of file internal.h.

90 {
97} dns_rcode;
dns_rcode
Definition: internal.h:90
@ rcode_notimp
Definition: internal.h:95
@ rcode_refused
Definition: internal.h:96
@ rcode_servfail
Definition: internal.h:93
@ rcode_formaterror
Definition: internal.h:92
@ rcode_nxdomain
Definition: internal.h:94
@ rcode_noerror
Definition: internal.h:91

◆ parsedomain_flags

Enumerator
pdf_quoteok 

Definition at line 577 of file internal.h.

577 {
578 pdf_quoteok= 0x001
parsedomain_flags
Definition: internal.h:577
@ pdf_quoteok
Definition: internal.h:578

Function Documentation

◆ adns__alloc_final()

void * adns__alloc_final ( adns_query  qu,
size_t  sz 
)

Definition at line 385 of file query.c.

385 {
386 /* When we're in the _final stage, we _subtract_ from interim_alloc'd
387 * each allocation, and use final_allocspace to point to the next free
388 * bit.
389 */
390 void *rp;
391
392 sz= MEM_ROUND(sz);
393 rp= qu->final_allocspace;
394 assert(rp);
395 qu->interim_allocd -= sz;
396 assert(qu->interim_allocd>=0);
397 qu->final_allocspace= (byte*)rp + sz;
398 return rp;
399}
#define assert(x)
Definition: debug.h:53
#define MEM_ROUND(sz)
Definition: internal.h:711
int interim_allocd
Definition: internal.h:188
void * final_allocspace
Definition: internal.h:189

Referenced by adns__makefinal_block(), and adns__makefinal_str().

◆ adns__alloc_interim()

void * adns__alloc_interim ( adns_query  qu,
size_t  sz 
)

Definition at line 342 of file query.c.

342 {
343 void *rv;
344
345 sz= MEM_ROUND(sz);
346 rv= alloc_common(qu,sz);
347 if (!rv) return 0;
348 qu->interim_allocd += sz;
349 return rv;
350}
static void * alloc_common(adns_query qu, size_t sz)
Definition: query.c:331

Referenced by adns__alloc_preserved(), adns__procdgram(), pa_txt(), pap_domain(), pap_findaddrs(), pap_mailbox822(), and pap_qstring().

◆ adns__alloc_mine()

void * adns__alloc_mine ( adns_query  qu,
size_t  sz 
)

Definition at line 362 of file query.c.

362 {
363 return alloc_common(qu,MEM_ROUND(sz));
364}

Referenced by adns__procdgram().

◆ adns__alloc_preserved()

void * adns__alloc_preserved ( adns_query  qu,
size_t  sz 
)

Definition at line 352 of file query.c.

352 {
353 void *rv;
354
355 sz= MEM_ROUND(sz);
356 rv= adns__alloc_interim(qu,sz);
357 if (!rv) return 0;
358 qu->preserved_allocd += sz;
359 return rv;
360}
void * adns__alloc_interim(adns_query qu, size_t sz)
Definition: query.c:342
int preserved_allocd
Definition: internal.h:188

Referenced by adns__procdgram(), and save_owner().

◆ adns__autosys()

void adns__autosys ( adns_state  ads,
struct timeval  now 
)

Definition at line 665 of file event.c.

665 {
666 if (ads->iflags & adns_if_noautosys) return;
668}
adns_state ads
Definition: adh-query.c:35
@ adns_if_noautosys
Definition: adns.h:93
int adns_processany(adns_state ads)
Definition: event.c:639
adns_initflags iflags
Definition: internal.h:292

Referenced by adns_check(), and adns_submit().

◆ adns__consistency()

void adns__consistency ( adns_state  ads,
adns_query  qu,
consistency_checks  cc 
)

Definition at line 185 of file check.c.

185 {
187
188 switch (cc) {
189 case cc_user:
190 break;
191 case cc_entex:
192 if (!(ads->iflags & adns_if_checkc_entex)) return;
193 break;
194 case cc_freq:
196 break;
197 default:
198 abort();
199 }
200
206
207 if (qu) {
208 switch (qu->state) {
209 case query_tosend:
210 DLIST_ASSERTON(qu, search, ads->udpw, );
211 break;
212 case query_tcpw:
213 DLIST_ASSERTON(qu, search, ads->tcpw, );
214 break;
215 case query_childw:
216 DLIST_ASSERTON(qu, search, ads->childw, );
217 break;
218 case query_done:
220 break;
221 default:
222 assert(!"specific query state");
223 }
224 }
225}
#define DLIST_ASSERTON(node, nodevar, list, part)
Definition: check.c:70
static void checkc_queue_tcpw(adns_state ads)
Definition: check.c:146
static void checkc_queue_childw(adns_state ads)
Definition: check.c:158
static void checkc_queue_udpw(adns_state ads)
Definition: check.c:133
static void checkc_global(adns_state ads)
Definition: check.c:102
static void checkc_queue_output(adns_state ads)
Definition: check.c:173
void query_done(struct query_node *qun, adns_answer *answer)
Definition: adh-query.c:253
@ adns_if_checkc_freq
Definition: adns.h:97
@ adns_if_checkc_entex
Definition: adns.h:96
#define abort()
Definition: i386-dis.c:34
uint32_t cc
Definition: isohybrid.c:75
static short search(int val, const short *table, int size)
Definition: msg711.c:255
enum adns__query::@4227 state
struct query_queue udpw tcpw childw output
Definition: internal.h:295

Referenced by adns_afterselect(), adns_beforeselect(), adns_cancel(), adns_check(), adns_checkconsistency(), adns_finish(), adns_firsttimeout(), adns_forallqueries_begin(), adns_forallqueries_next(), adns_globalsystemfailure(), adns_init(), adns_init_strcfg(), adns_processany(), adns_processexceptional(), adns_processreadable(), adns_processtimeouts(), adns_processwriteable(), adns_submit(), and adns_wait().

◆ adns__debug()

void adns__debug ( adns_state  ads,
int  serv,
adns_query  qu,
const char fmt,
  ... 
)

◆ adns__diag()

void void void adns__diag ( adns_state  ads,
int  serv,
adns_query  qu,
const char fmt,
  ... 
)

◆ adns__diag_domain()

const char * adns__diag_domain ( adns_state  ads,
int  serv,
adns_query  qu,
vbuf vb,
const byte dgram,
int  dglen,
int  cbyte 
)

Definition at line 162 of file general.c.

163 {
164 adns_status st;
165
166 st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok, dgram,dglen,&cbyte,dglen);
167 if (st == adns_s_nomemory) {
168 return "<cannot report domain... out of memory>";
169 }
170 if (st) {
171 vb->used= 0;
172 if (!(adns__vbuf_appendstr(vb,"<bad format... ") &&
174 adns__vbuf_appendstr(vb,">") &&
175 adns__vbuf_append(vb,(byte*)"",1))) {
176 return "<cannot report bad format... out of memory>";
177 }
178 }
179 if (!vb->used) {
180 adns__vbuf_appendstr(vb,"<truncated ...>");
181 adns__vbuf_append(vb,(byte*)"",1);
182 }
183 return (char*)vb->buf;
184}
adns_status
Definition: adns.h:215
@ adns_s_nomemory
Definition: adns.h:219
static int cbyte
Definition: adnsresfilter.c:73
const char * adns_strerror(adns_status st)
Definition: general.c:268
int adns__vbuf_append(vbuf *vb, const byte *data, int len)
Definition: general.c:131
int adns__vbuf_appendstr(vbuf *vb, const char *data)
Definition: general.c:149
adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu, vbuf *vb, adns_queryflags flags, const byte *dgram, int dglen, int *cbyte_io, int max)
Definition: parse.c:117
int used
Definition: internal.h:111
byte * buf
Definition: internal.h:112

Referenced by adns__procdgram(), and adns__vdiag().

◆ adns__fdevents()

void adns__fdevents ( adns_state  ads,
const struct pollfd pollfds,
int  npollfds,
int  maxfd,
const fd_set readfds,
const fd_set writefds,
const fd_set exceptfds,
struct timeval  now,
int r_r 
)

Definition at line 542 of file event.c.

546 {
547 int i, revents;
549
550 for (i=0; i<npollfds; i++) {
551 fd= pollfds[i].fd;
552 if ((int)fd >= maxfd) maxfd= fd+1;
553 revents= pollfds[i].revents;
554 fd_event(ads,fd, revents,POLLIN, maxfd,readfds, adns_processreadable,now,r_r);
555 fd_event(ads,fd, revents,POLLOUT, maxfd,writefds, adns_processwriteable,now,r_r);
556 fd_event(ads,fd, revents,POLLPRI, maxfd,exceptfds, adns_processexceptional,now,r_r);
557 }
558}
#define ADNS_SOCKET
Definition: adns_win32.h:98
#define POLLIN
Definition: linux.h:1853
#define POLLOUT
Definition: linux.h:1855
#define POLLPRI
Definition: linux.h:1854
time_t now
Definition: finger.c:65
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
int adns_processexceptional(adns_state ads, ADNS_SOCKET fd, const struct timeval *now)
Definition: event.c:504
static void fd_event(adns_state ads, ADNS_SOCKET fd, int revent, int pollflag, int maxfd, const fd_set *fds, int(*func)(adns_state, ADNS_SOCKET fd, const struct timeval *now), struct timeval now, int *r_r)
Definition: event.c:522
int adns_processwriteable(adns_state ads, ADNS_SOCKET fd, const struct timeval *now)
Definition: event.c:443
int adns_processreadable(adns_state ads, ADNS_SOCKET fd, const struct timeval *now)
Definition: event.c:338
static int fd
Definition: io.c:51
int fd
Definition: linux.h:1868
short revents
Definition: linux.h:1870

Referenced by adns_afterselect(), and adns_processany().

◆ adns__findlabel_next()

adns_status adns__findlabel_next ( findlabel_state fls,
int lablen_r,
int labstart_r 
)

Definition at line 74 of file parse.c.

75 {
76 int lablen, jumpto;
77 const char *dgram;
78
79 dgram= (char*)fls->dgram;
80 for (;;) {
81 if (fls->cbyte >= fls->dglen) goto x_truncated;
82 if (fls->cbyte >= fls->max) goto x_badresponse;
83 GET_B(fls->cbyte,lablen);
84 if (!(lablen & 0x0c0)) break;
85 if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat;
86 if (fls->cbyte >= fls->dglen) goto x_truncated;
87 if (fls->cbyte >= fls->max) goto x_badresponse;
88 GET_B(fls->cbyte,jumpto);
89 jumpto |= (lablen&0x3f)<<8;
90 if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
91 fls->cbyte= jumpto;
92 fls->dmend_r= 0; fls->max= fls->dglen+1;
93 }
94 if (labstart_r) *labstart_r= fls->cbyte;
95 if (lablen) {
96 if (fls->namelen) fls->namelen++;
97 fls->namelen+= lablen;
98 if (fls->namelen > DNS_MAXDOMAIN) return adns_s_answerdomaintoolong;
99 fls->cbyte+= lablen;
100 if (fls->cbyte > fls->dglen) goto x_truncated;
101 if (fls->cbyte > fls->max) goto x_badresponse;
102 } else {
103 if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
104 }
105 *lablen_r= lablen;
106 return adns_s_ok;
107
108 x_truncated:
109 *lablen_r= -1;
110 return adns_s_ok;
111
112 x_badresponse:
113 adns__diag(fls->ads,fls->serv,fls->qu,"label in domain runs beyond end of domain");
115}
@ adns_s_answerdomaintoolong
Definition: adns.h:247
@ adns_s_ok
Definition: adns.h:216
@ adns_s_unknownformat
Definition: adns.h:230
@ adns_s_invalidresponse
Definition: adns.h:229
static int fls(int x)
Definition: bitops.h:157
#define for
Definition: utility.h:88
void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:102
#define DNS_MAXDOMAIN
Definition: internal.h:75
#define GET_B(cb, tv)
Definition: internal.h:716

Referenced by adns__findrr_anychk(), adns__mkquery_frdgram(), adns__parse_domain_more(), pa_ptr(), and pap_mailbox822().

◆ adns__findlabel_start()

void adns__findlabel_start ( findlabel_state fls,
adns_state  ads,
int  serv,
adns_query  qu,
const byte dgram,
int  dglen,
int  max,
int  dmbegin,
int dmend_rlater 
)

Definition at line 59 of file parse.c.

62 {
63 fls->ads= ads;
64 fls->qu= qu;
65 fls->serv= serv;
66 fls->dgram= dgram;
67 fls->dglen= dglen;
68 fls->max= max;
69 fls->cbyte= dmbegin;
70 fls->namelen= 0;
71 fls->dmend_r= dmend_rlater;
72}
#define max(a, b)
Definition: svc.c:63

Referenced by adns__findrr_anychk(), adns__mkquery_frdgram(), adns__parse_domain(), pa_ptr(), and pap_mailbox822().

◆ adns__findrr()

adns_status adns__findrr ( adns_query  qu,
int  serv,
const byte dgram,
int  dglen,
int cbyte_io,
int type_r,
int class_r,
unsigned long ttl_r,
int rdlen_r,
int rdstart_r,
int ownermatchedquery_r 
)

Definition at line 227 of file parse.c.

231 {
232 if (!ownermatchedquery_r) {
233 return adns__findrr_anychk(qu,serv,
234 dgram,dglen,cbyte_io,
235 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
236 0,0,0, 0);
237 } else if (!qu->cname_dgram) {
238 return adns__findrr_anychk(qu,serv,
239 dgram,dglen,cbyte_io,
240 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
242 ownermatchedquery_r);
243 } else {
244 return adns__findrr_anychk(qu,serv,
245 dgram,dglen,cbyte_io,
246 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
248 ownermatchedquery_r);
249 }
250}
#define DNS_HDRSIZE
Definition: internal.h:76
adns_status adns__findrr_anychk(adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, const byte *eo_dgram, int eo_dglen, int eo_cbyte, int *eo_matched_r)
Definition: parse.c:163
byte * query_dgram
Definition: internal.h:192
int query_dglen
Definition: internal.h:193
int cname_begin
Definition: internal.h:213
byte * cname_dgram
Definition: internal.h:212
int cname_dglen
Definition: internal.h:213

Referenced by adns__procdgram().

◆ adns__findrr_anychk()

adns_status adns__findrr_anychk ( adns_query  qu,
int  serv,
const byte dgram,
int  dglen,
int cbyte_io,
int type_r,
int class_r,
unsigned long ttl_r,
int rdlen_r,
int rdstart_r,
const byte eo_dgram,
int  eo_dglen,
int  eo_cbyte,
int eo_matched_r 
)

Definition at line 163 of file parse.c.

168 {
169 findlabel_state fls, eo_fls;
170 int cbyte;
171
172 int tmp, rdlen, mismatch;
173 unsigned long ttl;
174 int lablen, labstart, ch;
175 int eo_lablen, eo_labstart, eo_ch;
176 adns_status st;
177
178 cbyte= *cbyte_io;
179
180 adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
181 if (eo_dgram) {
182 adns__findlabel_start(&eo_fls,qu->ads, -1,0, eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
183 mismatch= 0;
184 } else {
185 mismatch= 1;
186 }
187
188 for (;;) {
189 st= adns__findlabel_next(&fls,&lablen,&labstart);
190 if (st) return st;
191 if (lablen<0) goto x_truncated;
192
193 if (!mismatch) {
194 st= adns__findlabel_next(&eo_fls,&eo_lablen,&eo_labstart);
195 assert(!st); assert(eo_lablen>=0);
196 if (lablen != eo_lablen) mismatch= 1;
197 while (!mismatch && eo_lablen-- > 0) {
198 ch= dgram[labstart++]; if (ctype_alpha(ch)) ch &= ~32;
199 eo_ch= eo_dgram[eo_labstart++]; if (ctype_alpha(eo_ch)) eo_ch &= ~32;
200 if (ch != eo_ch) mismatch= 1;
201 }
202 }
203 if (!lablen) break;
204 }
205 if (eo_matched_r) *eo_matched_r= !mismatch;
206
207 if (cbyte+10>dglen) goto x_truncated;
208 GET_W(cbyte,tmp); *type_r= tmp;
209 GET_W(cbyte,tmp); *class_r= tmp;
210
211 GET_L(cbyte,ttl);
212 if (ttl > MAXTTLBELIEVE) ttl= MAXTTLBELIEVE;
213 *ttl_r= ttl;
214
215 GET_W(cbyte,rdlen); if (rdlen_r) *rdlen_r= rdlen;
216 if (rdstart_r) *rdstart_r= cbyte;
217 cbyte+= rdlen;
218 if (cbyte>dglen) goto x_truncated;
219 *cbyte_io= cbyte;
220 return adns_s_ok;
221
222 x_truncated:
223 *type_r= -1;
224 return 0;
225}
_STLP_INLINE_LOOP _STLP_STD::pair< _InputIter1, _InputIter2 > mismatch(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2)
Definition: _algobase.h:522
#define GET_L(cb, tv)
Definition: internal.h:718
static int ctype_alpha(int c)
Definition: internal.h:699
#define MAXTTLBELIEVE
Definition: internal.h:70
#define GET_W(cb, tv)
Definition: internal.h:717
adns_status adns__findlabel_next(findlabel_state *fls, int *lablen_r, int *labstart_r)
Definition: parse.c:74
void adns__findlabel_start(findlabel_state *fls, adns_state ads, int serv, adns_query qu, const byte *dgram, int dglen, int max, int dmbegin, int *dmend_rlater)
Definition: parse.c:59
adns_state ads
Definition: internal.h:182

Referenced by adns__findrr(), and pap_findaddrs().

◆ adns__findtype()

const typeinfo * adns__findtype ( adns_rrtype  type)

Definition at line 1025 of file types.c.

1025 {
1026 const typeinfo *begin, *end, *mid;
1027
1028 begin= typeinfos; end= typeinfos+(sizeof(typeinfos)/sizeof(typeinfo));
1029
1030 while (begin < end) {
1031 mid= begin + ((end-begin)>>1);
1032 if (mid->type == type) return mid;
1033 if (type > mid->type) begin= mid+1;
1034 else end= mid;
1035 }
1036 return 0;
1037}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
adns_rrtype type
Definition: internal.h:125
static const typeinfo typeinfos[]
Definition: types.c:1002
static clock_t begin
Definition: xmllint.c:458

Referenced by adns_rr_info(), adns_submit(), pa_ptr(), and pap_hostaddr().

◆ adns__internal_check()

int adns__internal_check ( adns_state  ads,
adns_query query_io,
adns_answer **  answer,
void **  context_r 
)

Definition at line 670 of file event.c.

673 {
674 adns_query qu;
675
676 qu= *query_io;
677 if (!qu) {
678 if (ads->output.head) {
679 qu= ads->output.head;
680 } else if (ads->udpw.head || ads->tcpw.head) {
681 return EAGAIN;
682 } else {
683 return ESRCH;
684 }
685 } else {
686 if (qu->id>=0) return EAGAIN;
687 }
689 *answer= qu->answer;
690 if (context_r) *context_r= qu->ctx.ext;
691 *query_io= qu;
692 free(qu);
693 return 0;
694}
#define EAGAIN
Definition: acclib.h:83
#define free
Definition: debug_ros.c:5
#define ESRCH
Definition: errno.h:9
#define LIST_UNLINK(list, node)
Definition: dlist.h:50
adns_answer * answer
Definition: internal.h:201
qcontext ctx
Definition: internal.h:233
void * ext
Definition: internal.h:173

Referenced by adns_check(), and adns_wait().

◆ adns__internal_submit()

adns_status adns__internal_submit ( adns_state  ads,
adns_query query_r,
const typeinfo typei,
vbuf qumsg_vb,
int  id,
adns_queryflags  flags,
struct timeval  now,
const qcontext ctx 
)

Definition at line 111 of file query.c.

114 {
115 adns_query qu;
116
117 qu= query_alloc(ads,typei,flags,now);
118 if (!qu) { adns__vbuf_free(qumsg_vb); return adns_s_nomemory; }
119 *query_r= qu;
120
121 memcpy(&qu->ctx,ctx,(size_t) sizeof(qu->ctx));
122 query_submit(ads,qu, typei,qumsg_vb,id,flags,now);
123
124 return adns_s_ok;
125}
GLbitfield flags
Definition: glext.h:7161
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void adns__vbuf_free(vbuf *vb)
Definition: general.c:155
static void query_submit(adns_state ads, adns_query qu, const typeinfo *typei, vbuf *qumsg_vb, int id, adns_queryflags flags, struct timeval now)
Definition: query.c:91
static adns_query query_alloc(adns_state ads, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:41

Referenced by pa_ptr(), and pap_hostaddr().

◆ adns__isort()

void adns__isort ( void array,
int  nobjs,
int  sz,
void tempbuf,
int(*)(void *context, const void *a, const void *b needswap,
void context 
)

Definition at line 319 of file general.c.

321 {
322 byte *data= array;
323 int i, place;
324
325 for (i=0; i<nobjs; i++) {
326 for (place= i;
327 place>0 && needswap(context, data + (place-1)*sz, data + i*sz);
328 place--);
329 if (place != i) {
330 memcpy(tempbuf, data + i*sz, (size_t) sz);
331 memmove(data + (place+1)*sz, data + place*sz, (size_t) (i-place)*sz);
332 memcpy(data + place*sz, tempbuf, (size_t) sz);
333 }
334 }
335}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static char * place
Definition: getopt.c:55
Definition: http.c:7252

Referenced by adns__query_done(), and pap_findaddrs().

◆ adns__makefinal_block()

void adns__makefinal_block ( adns_query  qu,
void **  blpp,
size_t  sz 
)

Definition at line 565 of file query.c.

565 {
566 void *before, *after;
567
568 before= *blpp;
569 if (!before) return;
570 after= adns__alloc_final(qu,sz);
571 memcpy(after,before, (size_t) sz);
572 *blpp= after;
573}
void * adns__alloc_final(adns_query qu, size_t sz)
Definition: query.c:385
__inline int before(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2390
__inline int after(__u32 seq1, __u32 seq2)
Definition: tcpcore.h:2395

Referenced by makefinal_query(), mf_manyistr(), and mfp_hostaddr().

◆ adns__makefinal_str()

void adns__makefinal_str ( adns_query  qu,
char **  strp 
)

Definition at line 553 of file query.c.

553 {
554 int l;
555 char *before, *after;
556
557 before= *strp;
558 if (!before) return;
559 l= strlen(before)+1;
560 after= adns__alloc_final(qu, (size_t) l);
561 memcpy(after,before,(size_t) l);
562 *strp= after;
563}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
r l[0]
Definition: byte_order.h:168

Referenced by makefinal_query(), mf_intstr(), mf_intstrpair(), mf_manyistr(), mf_soa(), mf_str(), mf_strpair(), and mfp_hostaddr().

◆ adns__mkquery()

adns_status adns__mkquery ( adns_state  ads,
vbuf vb,
int id_r,
const char owner,
int  ol,
const typeinfo typei,
adns_queryflags  flags 
)

Definition at line 81 of file transmit.c.

83 {
84 int ll, c, nbytes;
85 byte label[255], *rqp;
86 const char *p, *pe;
87 adns_status st;
88
89 st= mkquery_header(ads,vb,id_r,ol+2); if (st) return st;
90
91 MKQUERY_START(vb);
92
93 p= owner; pe= owner+ol;
94 nbytes= 0;
95 while (p!=pe) {
96 ll= 0;
97 while (p!=pe && (c= *p++)!='.') {
98 if (c=='\\') {
100 if (ctype_digit(p[0])) {
101 if (ctype_digit(p[1]) && ctype_digit(p[2])) {
102 c= (p[0] - '0')*100 + (p[1] - '0')*10 + (p[2] - '0');
103 p += 3;
104 if (c >= 256) return adns_s_querydomaininvalid;
105 } else {
107 }
108 } else if (!(c= *p++)) {
110 }
111 }
112 if (!(flags & adns_qf_quoteok_query)) {
113 if (c == '-') {
114 if (!ll) return adns_s_querydomaininvalid;
115 } else if (!ctype_alpha(c) && !ctype_digit(c)) {
117 }
118 }
119 if (ll == sizeof(label)) return adns_s_querydomaininvalid;
120 label[ll++]= c;
121 }
122 if (!ll) return adns_s_querydomaininvalid;
124 nbytes+= ll+1;
125 if (nbytes >= DNS_MAXDOMAIN) return adns_s_querydomaintoolong;
127 memcpy(rqp,label,(size_t) ll); rqp+= ll;
128 }
129 MKQUERY_ADDB(0);
130
131 MKQUERY_STOP(vb);
132
133 st= mkquery_footer(vb,typei->type);
134
135 return adns_s_ok;
136}
@ adns_s_querydomaintoolong
Definition: adns.h:255
@ adns_s_querydomaininvalid
Definition: adns.h:254
@ adns_qf_quoteok_query
Definition: adns.h:104
w ll
Definition: byte_order.h:167
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
#define c
Definition: ke_i.h:80
static const WCHAR label[]
Definition: itemdlg.c:1546
static int ctype_digit(int c)
Definition: internal.h:698
#define DNS_MAXLABEL
Definition: internal.h:74
#define MKQUERY_START(vb)
Definition: transmit.c:41
static adns_status mkquery_footer(vbuf *vb, adns_rrtype type)
Definition: transmit.c:69
static adns_status mkquery_header(adns_state ads, vbuf *vb, int *id_r, int qdlen)
Definition: transmit.c:46
#define MKQUERY_ADDB(b)
Definition: transmit.c:42
#define MKQUERY_STOP(vb)
Definition: transmit.c:44

Referenced by query_simple().

◆ adns__mkquery_frdgram()

adns_status adns__mkquery_frdgram ( adns_state  ads,
vbuf vb,
int id_r,
const byte qd_dgram,
int  qd_dglen,
int  qd_begin,
adns_rrtype  type,
adns_queryflags  flags 
)

Definition at line 138 of file transmit.c.

140 {
141 byte *rqp;
143 int lablen, labstart;
144 adns_status st;
145
146 st= mkquery_header(ads,vb,id_r,qd_dglen); if (st) return st;
147
148 MKQUERY_START(vb);
149
150 adns__findlabel_start(&fls,ads,-1,0,qd_dgram,qd_dglen,qd_dglen,qd_begin,0);
151 for (;;) {
152 st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
153 if (!lablen) break;
154 assert(lablen<255);
155 MKQUERY_ADDB(lablen);
156 memcpy(rqp,qd_dgram+labstart, (size_t) lablen);
157 rqp+= lablen;
158 }
159 MKQUERY_ADDB(0);
160
161 MKQUERY_STOP(vb);
162
163 st= mkquery_footer(vb,type);
164
165 return adns_s_ok;
166}
adns_status adns__findlabel_next(findlabel_state *fls, int *lablen_r, int *labstart_r)
Definition: parse.c:74
void adns__findlabel_start(findlabel_state *fls, adns_state ads, int serv, adns_query qu, const byte *dgram, int dglen, int max, int dmbegin, int *dmend_rlater)
Definition: parse.c:59

Referenced by adns__procdgram(), pa_ptr(), and pap_hostaddr().

◆ adns__must_gettimeofday()

void adns__must_gettimeofday ( adns_state  ads,
const struct timeval **  now_io,
struct timeval tv_buf 
)

Definition at line 149 of file event.c.

150 {
151 const struct timeval *now;
152 int r;
153
154 now= *now_io;
155 if (now) return;
156 r= gettimeofday(tv_buf,0); if (!r) { *now_io= tv_buf; return; }
157 adns__diag(ads,-1,0,"gettimeofday failed: %s",strerror(errno));
159 return;
160}
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const char * strerror(int err)
Definition: compat_str.c:23
#define errno
Definition: errno.h:18
void adns_globalsystemfailure(adns_state ads)
Definition: event.c:619

Referenced by adns_afterselect(), adns_beforeselect(), and adns_processtimeouts().

◆ adns__parse_domain()

adns_status adns__parse_domain ( adns_state  ads,
int  serv,
adns_query  qu,
vbuf vb,
adns_queryflags  flags,
const byte dgram,
int  dglen,
int cbyte_io,
int  max 
)

Definition at line 117 of file parse.c.

119 {
121
122 adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max, *cbyte_io,cbyte_io);
123 vb->used= 0;
124 return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
125}
adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads, adns_query qu, vbuf *vb, parsedomain_flags flags, const byte *dgram)
Definition: parse.c:127

Referenced by adns__diag_domain(), adns__procdgram(), and pap_domain().

◆ adns__parse_domain_more()

adns_status adns__parse_domain_more ( findlabel_state fls,
adns_state  ads,
adns_query  qu,
vbuf vb,
parsedomain_flags  flags,
const byte dgram 
)

Definition at line 127 of file parse.c.

129 {
130 int lablen, labstart, i, ch, first;
131 adns_status st;
132
133 first= 1;
134 for (;;) {
135 st= adns__findlabel_next(fls,&lablen,&labstart);
136 if (st) return st;
137 if (lablen<0) { vb->used=0; return adns_s_ok; }
138 if (!lablen) break;
139 if (first) {
140 first= 0;
141 } else {
142 if (!adns__vbuf_append(vb,(byte*)".",1)) return adns_s_nomemory;
143 }
144 if (flags & pdf_quoteok) {
145 if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
146 return adns_s_nomemory;
147 } else {
148 ch= dgram[labstart];
149 if (!ctype_alpha(ch) && !ctype_digit(ch)) return adns_s_answerdomaininvalid;
150 for (i= labstart+1; i<labstart+lablen; i++) {
151 ch= dgram[i];
152 if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
154 }
155 if (!adns__vbuf_append(vb,dgram+labstart,lablen))
156 return adns_s_nomemory;
157 }
158 }
159 if (!adns__vbuf_append(vb,(byte*)"",1)) return adns_s_nomemory;
160 return adns_s_ok;
161}
@ adns_s_answerdomaininvalid
Definition: adns.h:246
const GLint * first
Definition: glext.h:5794
int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len)
Definition: parse.c:34

Referenced by adns__parse_domain(), and pap_mailbox822().

◆ adns__pollfds()

int adns__pollfds ( adns_state  ads,
struct pollfd  pollfds_buf[MAX_POLLFDS] 
)

Definition at line 312 of file event.c.

312 {
313 /* Returns the number of entries filled in. Always zeroes revents. */
314
316
317 pollfds_buf[0].fd= ads->udpsocket;
318 pollfds_buf[0].events= POLLIN;
319 pollfds_buf[0].revents= 0;
320
321 switch (ads->tcpstate) {
322 case server_disconnected:
323 case server_broken:
324 return 1;
325 case server_connecting:
326 pollfds_buf[1].events= POLLOUT;
327 break;
328 case server_ok:
330 break;
331 default:
332 abort();
333 }
334 pollfds_buf[1].fd= ads->tcpsocket;
335 return 2;
336}
#define MAX_POLLFDS
Definition: internal.h:82
ADNS_SOCKET tcpsocket
Definition: internal.h:298
enum adns__state::adns__tcpstate tcpstate
ADNS_SOCKET udpsocket
Definition: internal.h:298
vbuf tcpsend
Definition: internal.h:299
short events
Definition: linux.h:1869

Referenced by adns_afterselect(), adns_beforeselect(), and adns_processany().

◆ adns__procdgram()

void adns__procdgram ( adns_state  ads,
const byte dgram,
int  len,
int  serv,
int  viatcp,
struct timeval  now 
)

Definition at line 36 of file reply.c.

37 {
38 int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here;
39 int id, f1, f2, qdcount, ancount, nscount, arcount;
40 int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
41 int rrtype, rrclass, rdlength, rdstart;
42 int anstart, nsstart, arstart;
43 int ownermatched, l, nrrs;
44 unsigned long ttl, soattl;
45 const typeinfo *typei;
46 adns_query qu, nqu;
48 adns_status st;
49 vbuf tempvb;
50 byte *newquery, *rrsdata;
51 parseinfo pai;
52
53 if (dglen<DNS_HDRSIZE) {
54 adns__diag(ads,serv,0,"received datagram too short for message header (%d)",dglen);
55 return;
56 }
57 cbyte= 0;
58 GET_W(cbyte,id);
59 GET_B(cbyte,f1);
60 GET_B(cbyte,f2);
61 GET_W(cbyte,qdcount);
62 GET_W(cbyte,ancount);
63 GET_W(cbyte,nscount);
64 GET_W(cbyte,arcount);
66
67 flg_qr= f1&0x80;
68 opcode= (f1&0x78)>>3;
69 flg_tc= f1&0x02;
70 flg_rd= f1&0x01;
71 flg_ra= f2&0x80;
72 rcode= (f2&0x0f);
73
74 cname_here= 0;
75
76 if (!flg_qr) {
77 adns__diag(ads,serv,0,"server sent us a query, not a response");
78 return;
79 }
80 if (opcode) {
81 adns__diag(ads,serv,0,"server sent us unknown opcode %d (wanted 0=QUERY)",opcode);
82 return;
83 }
84
85 qu= 0;
86 /* See if we can find the relevant query, or leave qu=0 otherwise ... */
87
88 if (qdcount == 1) {
89 for (qu= viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu= nqu) {
90 nqu= qu->next;
91 if (qu->id != id) continue;
92 if (dglen < qu->query_dglen) continue;
94 dgram+DNS_HDRSIZE,
95 (size_t) qu->query_dglen-DNS_HDRSIZE))
96 continue;
97 if (viatcp) {
98 assert(qu->state == query_tcpw);
99 } else {
100 assert(qu->state == query_tosend);
101 if (!(qu->udpsent & (1<<serv))) continue;
102 }
103 break;
104 }
105 if (qu) {
106 /* We're definitely going to do something with this query now */
107 if (viatcp) LIST_UNLINK(ads->tcpw,qu);
108 else LIST_UNLINK(ads->udpw,qu);
109 }
110 }
111
112 /* If we're going to ignore the packet, we return as soon as we have
113 * failed the query (if any) and printed the warning message (if
114 * any).
115 */
116 switch (rcode) {
117 case rcode_noerror:
118 case rcode_nxdomain:
119 break;
121 adns__warn(ads,serv,qu,"server cannot understand our query (Format Error)");
123 return;
124 case rcode_servfail:
126 else adns__debug(ads,serv,qu,"server failure on unidentifiable query");
127 return;
128 case rcode_notimp:
129 adns__warn(ads,serv,qu,"server claims not to implement our query");
131 return;
132 case rcode_refused:
133 adns__debug(ads,serv,qu,"server refused our query");
135 return;
136 default:
137 adns__warn(ads,serv,qu,"server gave unknown response code %d",rcode);
139 return;
140 }
141
142 if (!qu) {
143 if (!qdcount) {
144 adns__diag(ads,serv,0,"server sent reply without quoting our question");
145 } else if (qdcount>1) {
146 adns__diag(ads,serv,0,"server claimed to answer %d questions with one message",
147 qdcount);
148 } else if (ads->iflags & adns_if_debug) {
149 adns__vbuf_init(&tempvb);
150 adns__debug(ads,serv,0,"reply not found, id %02x, query owner %s",
151 id, adns__diag_domain(ads,serv,0,&tempvb,dgram,dglen,DNS_HDRSIZE));
152 adns__vbuf_free(&tempvb);
153 }
154 return;
155 }
156
157 /* We're definitely going to do something with this packet and this query now. */
158
159 anstart= qu->query_dglen;
160 arstart= -1;
161
162 /* Now, take a look at the answer section, and see if it is complete.
163 * If it has any CNAMEs we stuff them in the answer.
164 */
165 wantedrrs= 0;
166 cbyte= anstart;
167 for (rri= 0; rri<ancount; rri++) {
168 rrstart= cbyte;
169 st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
170 &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
171 &ownermatched);
172 if (st) { adns__query_fail(qu,st); return; }
173 if (rrtype == -1) goto x_truncated;
174
175 if (rrclass != DNS_CLASS_IN) {
176 adns__diag(ads,serv,qu,"ignoring answer RR with wrong class %d (expected IN=%d)",
177 rrclass,DNS_CLASS_IN);
178 continue;
179 }
180 if (!ownermatched) {
181 if (ads->iflags & adns_if_debug) {
182 adns__debug(ads,serv,qu,"ignoring RR with an unexpected owner %s",
183 adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rrstart));
184 }
185 continue;
186 }
187 if (rrtype == adns_r_cname &&
189 if (qu->flags & adns_qf_cname_forbid) {
191 return;
192 } else if (qu->cname_dgram) { /* Ignore second and subsequent CNAME(s) */
193 adns__debug(ads,serv,qu,"allegedly canonical name %s is actually alias for %s",
194 qu->answer->cname,
195 adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
197 return;
198 } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */
199 adns__debug(ads,serv,qu,"ignoring CNAME (to %s) coexisting with RR",
200 adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
201 } else {
202 qu->cname_begin= rdstart;
203 qu->cname_dglen= dglen;
204 st= adns__parse_domain(ads,serv,qu, &qu->vb,
206 dgram,dglen, &rdstart,rdstart+rdlength);
207 if (!qu->vb.used) goto x_truncated;
208 if (st) { adns__query_fail(qu,st); return; }
209 l= strlen((char*)qu->vb.buf)+1;
210 qu->answer->cname= adns__alloc_preserved(qu,(size_t) l);
211 if (!qu->answer->cname) { adns__query_fail(qu,adns_s_nomemory); return; }
212
213 qu->cname_dgram= adns__alloc_mine(qu, (size_t) dglen);
214 memcpy(qu->cname_dgram,dgram,(size_t) dglen);
215
216 memcpy(qu->answer->cname,qu->vb.buf, (size_t) l);
217 cname_here= 1;
219 /* If we find the answer section truncated after this point we restart
220 * the query at the CNAME; if beforehand then we obviously have to use
221 * TCP. If there is no truncation we can use the whole answer if
222 * it contains the relevant info.
223 */
224 }
225 } else if (rrtype == ((INT)qu->typei->type & (INT)adns__rrt_typemask)) {
226 wantedrrs++;
227 } else {
228 adns__debug(ads,serv,qu,"ignoring answer RR with irrelevant type %d",rrtype);
229 }
230 }
231
232 /* We defer handling truncated responses here, in case there was a CNAME
233 * which we could use.
234 */
235 if (flg_tc) goto x_truncated;
236
237 nsstart= cbyte;
238
239 if (!wantedrrs) {
240 /* Oops, NODATA or NXDOMAIN or perhaps a referral (which would be a problem) */
241
242 /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records in authority section */
243 foundsoa= 0; soattl= 0; foundns= 0;
244 for (rri= 0; rri<nscount; rri++) {
245 rrstart= cbyte;
246 st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
247 &rrtype,&rrclass,&ttl, &rdlength,&rdstart, 0);
248 if (st) { adns__query_fail(qu,st); return; }
249 if (rrtype==-1) goto x_truncated;
250 if (rrclass != DNS_CLASS_IN) {
251 adns__diag(ads,serv,qu,
252 "ignoring authority RR with wrong class %d (expected IN=%d)",
253 rrclass,DNS_CLASS_IN);
254 continue;
255 }
256 if (rrtype == adns_r_soa_raw) { foundsoa= 1; soattl= ttl; break; }
257 else if (rrtype == adns_r_ns_raw) { foundns= 1; }
258 }
259
260 if (rcode == rcode_nxdomain) {
261 /* We still wanted to look for the SOA so we could find the TTL. */
262 adns__update_expires(qu,soattl,now);
263
264 if (qu->flags & adns_qf_search) {
266 } else {
268 }
269 return;
270 }
271
272 if (foundsoa || !foundns) {
273 /* Aha ! A NODATA response, good. */
274 adns__update_expires(qu,soattl,now);
276 return;
277 }
278
279 /* Now what ? No relevant answers, no SOA, and at least some NS's.
280 * Looks like a referral. Just one last chance ... if we came across
281 * a CNAME in this datagram then we should probably do our own CNAME
282 * lookup now in the hope that we won't get a referral again.
283 */
284 if (cname_here) goto x_restartquery;
285
286 /* Bloody hell, I thought we asked for recursion ? */
287 if (!flg_ra) {
288 adns__diag(ads,serv,qu,"server is not willing to do recursive lookups for us");
290 } else {
291 if (!flg_rd)
292 adns__diag(ads,serv,qu,"server thinks we didn't ask for recursive lookup");
293 else
294 adns__debug(ads,serv,qu,"server claims to do recursion, but gave us a referral");
296 }
297 return;
298 }
299
300 /* Now, we have some RRs which we wanted. */
301
302 qu->answer->rrs.untyped= adns__alloc_interim(qu,(size_t) qu->typei->rrsz*wantedrrs);
303 if (!qu->answer->rrs.untyped) { adns__query_fail(qu,adns_s_nomemory); return; }
304
305 typei= qu->typei;
306 cbyte= anstart;
307 rrsdata= qu->answer->rrs.bytes;
308
309 pai.ads= qu->ads;
310 pai.qu= qu;
311 pai.serv= serv;
312 pai.dgram= dgram;
313 pai.dglen= dglen;
314 pai.nsstart= nsstart;
315 pai.nscount= nscount;
316 pai.arcount= arcount;
317 pai.now= now;
318
319 for (rri=0, nrrs=0; rri<ancount; rri++) {
320 st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
321 &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
322 &ownermatched);
323 assert(!st); assert(rrtype != -1);
324 if (rrclass != DNS_CLASS_IN ||
325 rrtype != ((INT)qu->typei->type & (INT)adns__rrt_typemask) ||
326 !ownermatched)
327 continue;
329 st= typei->parse(&pai, rdstart,rdstart+rdlength, rrsdata+nrrs*typei->rrsz);
330 if (st) { adns__query_fail(qu,st); return; }
331 if (rdstart==-1) goto x_truncated;
332 nrrs++;
333 }
334 assert(nrrs==wantedrrs);
335 qu->answer->nrrs= nrrs;
336
337 /* This may have generated some child queries ... */
338 if (qu->children.head) {
339 qu->state= query_childw;
340 LIST_LINK_TAIL(ads->childw,qu);
341 return;
342 }
344 return;
345
346 x_truncated:
347
348 if (!flg_tc) {
349 adns__diag(ads,serv,qu,"server sent datagram which points outside itself");
351 return;
352 }
353 qu->flags |= adns_qf_usevc;
354
355 x_restartquery:
356 if (qu->cname_dgram) {
357 st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id,
358 qu->cname_dgram, qu->cname_dglen, qu->cname_begin,
359 qu->typei->type, qu->flags);
360 if (st) { adns__query_fail(qu,st); return; }
361
362 newquery= realloc(qu->query_dgram, (size_t) qu->vb.used);
363 if (!newquery) { adns__query_fail(qu,adns_s_nomemory); return; }
364
365 qu->query_dgram= newquery;
366 qu->query_dglen= qu->vb.used;
367 memcpy(newquery,qu->vb.buf, (size_t) qu->vb.used);
368 }
369
370 if (qu->state == query_tcpw) qu->state= query_tosend;
371 qu->retries= 0;
374}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
int rcode
Definition: adh-main.c:36
@ adns_r_cname
Definition: adns.h:125
@ adns_r_soa_raw
Definition: adns.h:127
@ adns_r_ns_raw
Definition: adns.h:122
@ adns__rrt_typemask
Definition: adns.h:114
@ adns_if_debug
Definition: adns.h:91
@ adns_s_rcodeunknown
Definition: adns.h:239
@ adns_s_prohibitedcname
Definition: adns.h:245
@ adns_s_nodata
Definition: adns.h:261
@ adns_s_norecurse
Definition: adns.h:228
@ adns_s_rcodeservfail
Definition: adns.h:235
@ adns_s_rcodeformaterror
Definition: adns.h:236
@ adns_s_rcoderefused
Definition: adns.h:238
@ adns_s_rcodenotimplemented
Definition: adns.h:237
@ adns_s_nxdomain
Definition: adns.h:260
@ adns_qf_usevc
Definition: adns.h:102
@ adns_qf_quotefail_cname
Definition: adns.h:107
@ adns_qf_search
Definition: adns.h:101
@ adns_qf_cname_forbid
Definition: adns.h:109
#define realloc
Definition: debug_ros.c:6
GLuint id
Definition: glext.h:5910
#define LIST_LINK_TAIL(list, node)
Definition: dlist.h:51
void adns__vbuf_init(vbuf *vb)
Definition: general.c:112
void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:86
void adns__warn(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:94
const char * adns__diag_domain(adns_state ads, int serv, adns_query qu, vbuf *vb, const byte *dgram, int dglen, int cbyte)
Definition: general.c:162
void * adns__alloc_preserved(adns_query qu, size_t sz)
Definition: query.c:352
void * adns__alloc_interim(adns_query qu, size_t sz)
Definition: query.c:342
adns_status adns__findrr(adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r)
Definition: parse.c:227
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
void * adns__alloc_mine(adns_query qu, size_t sz)
Definition: query.c:362
void adns__search_next(adns_state ads, adns_query qu, struct timeval now)
Definition: query.c:151
void adns__reset_preserved(adns_query qu)
Definition: query.c:410
#define DNS_CLASS_IN
Definition: internal.h:78
adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r, const byte *qd_dgram, int qd_dglen, int qd_begin, adns_rrtype type, adns_queryflags flags)
Definition: transmit.c:138
void adns__query_send(adns_query qu, struct timeval now)
Definition: transmit.c:232
void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now)
Definition: query.c:458
void adns__query_done(adns_query qu)
Definition: query.c:503
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
int retries
Definition: internal.h:227
const typeinfo * typei
Definition: internal.h:191
adns_query next
Definition: internal.h:184
unsigned long udpsent
Definition: internal.h:229
struct adns__query::@4228 children
int nrrs
Definition: adns.h:316
union adns_answer::@4225 rrs
unsigned char * bytes
Definition: adns.h:319
char * cname
Definition: adns.h:312
void * untyped
Definition: adns.h:318
int serv
Definition: internal.h:118
const byte * dgram
Definition: internal.h:119
int nsstart
Definition: internal.h:120
adns_state ads
Definition: internal.h:116
int nscount
Definition: internal.h:120
struct timeval now
Definition: internal.h:121
adns_query qu
Definition: internal.h:117
int arcount
Definition: internal.h:120
int dglen
Definition: internal.h:120
adns_status(* parse)(const parseinfo *pai, int cbyte, int max, void *store_r)
Definition: internal.h:141
int rrsz
Definition: internal.h:128
Definition: internal.h:110
int32_t INT
Definition: typedefs.h:58

Referenced by adns_processreadable().

◆ adns__query_done()

void adns__query_done ( adns_query  qu)

Definition at line 503 of file query.c.

503 {
504 adns_answer *ans;
506
507 cancel_children(qu);
508
509 qu->id= -1;
510 ans= qu->answer;
511
512 if (qu->flags & adns_qf_owner && qu->flags & adns_qf_search &&
513 ans->status != adns_s_nomemory) {
514 if (!save_owner(qu, (char*)qu->search_vb.buf, qu->search_vb.used)) {
516 return;
517 }
518 }
519
520 if (ans->nrrs && qu->typei->diff_needswap) {
521 if (!adns__vbuf_ensure(&qu->vb,qu->typei->rrsz)) {
523 return;
524 }
525 adns__isort(ans->rrs.bytes, ans->nrrs, ans->rrsz,
526 qu->vb.buf,
527 (int(*)(void*, const void*, const void*))qu->typei->diff_needswap,
528 qu->ads);
529 }
530
531 ans->expires= qu->expires;
532 parent= qu->parent;
533 if (parent) {
534 LIST_UNLINK_PART(parent->children,qu,siblings.);
535 LIST_UNLINK(qu->ads->childw,parent);
536 qu->ctx.callback(parent,qu);
538 free(qu->answer);
539 free(qu);
540 } else {
541 makefinal_query(qu);
542 LIST_LINK_TAIL(qu->ads->output,qu);
543 qu->state= query_done;
544 }
545}
@ adns_qf_owner
Definition: adns.h:103
r parent
Definition: btrfs.c:3010
#define LIST_UNLINK_PART(list, node, part)
Definition: dlist.h:34
int adns__vbuf_ensure(vbuf *vb, int want)
Definition: general.c:116
void adns__isort(void *array, int nobjs, int sz, void *tempbuf, int(*needswap)(void *context, const void *a, const void *b), void *context)
Definition: general.c:319
static void cancel_children(adns_query qu)
Definition: query.c:401
static int save_owner(adns_query qu, const char *owner, int ol)
Definition: query.c:190
static void makefinal_query(adns_query qu)
Definition: query.c:467
void adns__query_fail(adns_query qu, adns_status stat)
Definition: query.c:547
static void free_query_allocs(adns_query qu)
Definition: query.c:418
adns_query parent
Definition: internal.h:184
time_t expires
Definition: internal.h:231
vbuf search_vb
Definition: internal.h:216
time_t expires
Definition: adns.h:315
int rrsz
Definition: adns.h:316
adns_status status
Definition: adns.h:311
void(* callback)(adns_query parent, adns_query child)
Definition: internal.h:174
int(* diff_needswap)(adns_state ads, const void *datap_a, const void *datap_b)
Definition: internal.h:153

Referenced by adns__procdgram(), adns__query_fail(), icb_hostaddr(), and icb_ptr().

◆ adns__query_fail()

void adns__query_fail ( adns_query  qu,
adns_status  stat 
)

Definition at line 547 of file query.c.

547 {
549 qu->answer->status= stat;
551}
#define stat
Definition: acwin.h:99
void adns__reset_preserved(adns_query qu)
Definition: query.c:410
void adns__query_done(adns_query qu)
Definition: query.c:503

Referenced by adns__procdgram(), adns__query_done(), adns__query_send(), adns__search_next(), adns_globalsystemfailure(), adns_submit(), icb_ptr(), query_simple(), query_submit(), tcp_events(), and timeouts_queue().

◆ adns__query_send()

void adns__query_send ( adns_query  qu,
struct timeval  now 
)

Definition at line 232 of file transmit.c.

232 {
233 struct sockaddr_in servaddr;
234 int serv, r;
236
237 assert(qu->state == query_tosend);
238 if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > DNS_MAXUDP)) {
239 query_usetcp(qu,now);
240 return;
241 }
242
243 if (qu->retries >= UDPMAXRETRIES) {
245 return;
246 }
247
248 serv= qu->udpnextserver;
249 memset(&servaddr,0,sizeof(servaddr));
250
251 ads= qu->ads;
252 servaddr.sin_family= AF_INET;
253 servaddr.sin_addr= ads->servers[serv].addr;
254 servaddr.sin_port= htons(DNS_PORT);
255
257 r= sendto(ads->udpsocket,(char*)qu->query_dgram,qu->query_dglen,0,
258 (const struct sockaddr*)&servaddr,sizeof(servaddr));
260 if (r<0 && errno == EMSGSIZE) { qu->retries= 0; query_usetcp(qu,now); return; }
261 if (r<0 && ((errno != EAGAIN) && (errno != EWOULDBLOCK))) adns__warn(ads,serv,0,"sendto failed: %s (%d)",strerror(errno), errno);
262
263 qu->timeout= now;
265 qu->udpsent |= (1<<serv);
266 qu->udpnextserver= (serv+1)%ads->nservers;
267 qu->retries++;
268 LIST_LINK_TAIL(ads->udpw,qu);
269}
@ adns_s_timeout
Definition: adns.h:226
#define ADNS_CLEAR_ERRNO
Definition: adns_win32.h:108
#define ADNS_CAPTURE_ERRNO
Definition: adns_win32.h:107
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
#define EWOULDBLOCK
Definition: errno.h:42
#define EMSGSIZE
Definition: errno.h:97
#define AF_INET
Definition: tcpip.h:117
#define htons(x)
Definition: module.h:215
#define UDPMAXRETRIES
Definition: internal.h:65
#define DNS_MAXUDP
Definition: internal.h:73
#define DNS_PORT
Definition: internal.h:72
#define UDPRETRYMS
Definition: internal.h:66
static void query_usetcp(adns_query qu, struct timeval now)
Definition: transmit.c:223
#define memset(x, y, z)
Definition: compat.h:39
struct timeval timeout
Definition: internal.h:230
int udpnextserver
Definition: internal.h:228
int nservers
Definition: internal.h:300
struct adns__state::server servers[MAXSERVERS]
static void timevaladd(struct timeval *tv_io, long ms)
Definition: tvarith.h:31

Referenced by adns__procdgram(), query_submit(), and timeouts_queue().

◆ adns__querysend_tcp()

void adns__querysend_tcp ( adns_query  qu,
struct timeval  now 
)

Definition at line 168 of file transmit.c.

168 {
169 byte length[2];
170 struct iovec iov[2];
171 int wr, r;
173
174 if (qu->ads->tcpstate != server_ok) return;
175
176 assert(qu->state == query_tcpw);
177
178 length[0]= (qu->query_dglen&0x0ff00U) >>8;
179 length[1]= (qu->query_dglen&0x0ff);
180
181 ads= qu->ads;
182 if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2)) return;
183
184 qu->retries++;
185
186 /* Reset idle timeout. */
187 ads->tcptimeout.tv_sec= ads->tcptimeout.tv_usec= 0;
188
189 if (ads->tcpsend.used) {
190 wr= 0;
191 } else {
192 iov[0].iov_base= (char*)length;
193 iov[0].iov_len= 2;
194 iov[1].iov_base= (char*)qu->query_dgram;
195 iov[1].iov_len= qu->query_dglen;
197
199 wr= writev(qu->ads->tcpsocket,iov,2);
202 if (wr < 0) {
203 if (!(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ENOSPC ||
204 errno == ENOBUFS || errno == ENOMEM)) {
206 return;
207 }
208 wr= 0;
209 }
210 }
211
212 if (wr<2) {
214 wr= 0;
215 } else {
216 wr-= 2;
217 }
218 if (wr<qu->query_dglen) {
220 }
221}
#define EINTR
Definition: acclib.h:80
#define ENOMEM
Definition: acclib.h:84
#define writev(FileDescriptor, iov, iovCount)
Definition: adns_win32.h:160
#define ENOSPC
Definition: errno.h:34
#define ENOBUFS
Definition: errno.h:116
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
void adns__tcp_broken(adns_state ads, const char *what, const char *why)
Definition: event.c:59
void adns__sigpipe_protect(adns_state ads)
Definition: general.c:340
void adns__sigpipe_unprotect(adns_state ads)
Definition: general.c:360
struct timeval tcptimeout
Definition: internal.h:305
Definition: linux.h:1700

Referenced by query_usetcp(), and tcp_connected().

◆ adns__reset_preserved()

void adns__reset_preserved ( adns_query  qu)

Definition at line 410 of file query.c.

410 {
412 cancel_children(qu);
413 qu->answer->nrrs= 0;
414 qu->answer->rrs.untyped= 0;
416}

Referenced by adns__procdgram(), adns__query_fail(), and makefinal_query().

◆ adns__search_next()

void adns__search_next ( adns_state  ads,
adns_query  qu,
struct timeval  now 
)

Definition at line 151 of file query.c.

151 {
152 const char *nextentry;
154
155 if (qu->search_doneabs<0) {
156 nextentry= 0;
157 qu->search_doneabs= 1;
158 } else {
159 if (qu->search_pos >= ads->nsearchlist) {
160 if (qu->search_doneabs) {
161 stat= adns_s_nxdomain; goto x_fail;
162 return;
163 } else {
164 nextentry= 0;
165 qu->search_doneabs= 1;
166 }
167 } else {
168 nextentry= ads->searchlist[qu->search_pos++];
169 }
170 }
171
173 if (nextentry) {
174 if (!adns__vbuf_append(&qu->search_vb,(byte*)".",1) ||
175 !adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
176 stat= adns_s_nomemory; goto x_fail;
177 }
178 }
179
180 free(qu->query_dgram);
181 qu->query_dgram= 0; qu->query_dglen= 0;
182
183 query_simple(ads,qu, (char*)qu->search_vb.buf, qu->search_vb.used, qu->typei, qu->flags, now);
184 return;
185
186x_fail:
188}
static void query_simple(adns_state ads, adns_query qu, const char *owner, int ol, const typeinfo *typei, adns_queryflags flags, struct timeval now)
Definition: query.c:127
int search_origlen
Definition: internal.h:217
int search_pos
Definition: internal.h:217
int search_doneabs
Definition: internal.h:217
int nsearchlist
Definition: internal.h:300
char ** searchlist
Definition: internal.h:322
Definition: stat.h:55

Referenced by adns__procdgram(), adns_submit(), and query_simple().

◆ adns__setnonblock()

int adns__setnonblock ( adns_state  ads,
ADNS_SOCKET  fd 
)

Definition at line 457 of file setup.c.

457 {
458#ifdef ADNS_JGAA_WIN32
459 unsigned long Val = 1;
460 return (ioctlsocket (fd, FIONBIO, &Val) == 0) ? 0 : -1;
461#else
462 int r;
463
464 r= fcntl(fd,F_GETFL,0); if (r<0) return errno;
465 r |= O_NONBLOCK;
466 r= fcntl(fd,F_SETFL,r); if (r<0) return errno;
467 return 0;
468#endif
469}
#define O_NONBLOCK
Definition: port.h:158
#define ioctlsocket
Definition: ncftp.h:481
#define FIONBIO
Definition: winsock.h:149

Referenced by adns__tcp_tryconnect(), and init_finish().

◆ adns__sigpipe_protect()

void adns__sigpipe_protect ( adns_state  ads)

Definition at line 340 of file general.c.

340 {
341#ifndef ADNS_JGAA_WIN32
342 sigset_t toblock;
343 struct sigaction sa;
344 int r;
345
346 if (ads->iflags & adns_if_nosigpipe) return;
347
348 sigfillset(&toblock);
349 sigdelset(&toblock,SIGPIPE);
350
351 sa.sa_handler= SIG_IGN;
352 sigfillset(&sa.sa_mask);
353 sa.sa_flags= 0;
354
355 r= sigprocmask(SIG_SETMASK,&toblock,&ads->stdsigmask); assert(!r);
356 r= sigaction(SIGPIPE,&sa,&ads->stdsigpipe); assert(!r);
357#endif
358}
@ adns_if_nosigpipe
Definition: adns.h:95
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define SIGPIPE
Definition: signal.h:35
#define SIG_IGN
Definition: signal.h:48
sigset_t stdsigmask
Definition: internal.h:313
struct sigaction stdsigpipe
Definition: internal.h:312

Referenced by adns__querysend_tcp(), and adns_processwriteable().

◆ adns__sigpipe_unprotect()

void adns__sigpipe_unprotect ( adns_state  ads)

Definition at line 360 of file general.c.

360 {
361#ifndef ADNS_JGAA_WIN32
362 int r;
363
364 if (ads->iflags & adns_if_nosigpipe) return;
365
366 r= sigaction(SIGPIPE,&ads->stdsigpipe,0); assert(!r);
367 r= sigprocmask(SIG_SETMASK,&ads->stdsigmask,0); assert(!r);
368#endif
369}

Referenced by adns__querysend_tcp(), and adns_processwriteable().

◆ adns__tcp_broken()

void adns__tcp_broken ( adns_state  ads,
const char what,
const char why 
)

Definition at line 59 of file event.c.

59 {
60 int serv;
61 adns_query qu;
62
63 assert(ads->tcpstate == server_connecting || ads->tcpstate == server_ok);
64 serv= ads->tcpserver;
65 if (what) adns__warn(ads,serv,0,"TCP connection failed: %s: %s",what,why);
66
67 if (ads->tcpstate == server_connecting) {
68 /* Counts as a retry for all the queries waiting for TCP. */
69 for (qu= ads->tcpw.head; qu; qu= qu->next)
70 qu->retries++;
71 }
72
74 ads->tcpstate= server_broken;
75 ads->tcpserver= (serv+1)%ads->nservers;
76}
static void tcp_close(adns_state ads)
Definition: event.c:50
int tcpserver
Definition: internal.h:300

Referenced by adns__querysend_tcp(), adns__tcp_tryconnect(), adns_globalsystemfailure(), adns_processexceptional(), adns_processreadable(), adns_processwriteable(), and tcp_events().

◆ adns__tcp_tryconnect()

void adns__tcp_tryconnect ( adns_state  ads,
struct timeval  now 
)

Definition at line 90 of file event.c.

90 {
91 int r, tries;
93 struct sockaddr_in addr;
94 struct protoent *proto;
95
96 for (tries=0; tries<ads->nservers; tries++) {
97 switch (ads->tcpstate) {
98 case server_connecting:
99 case server_ok:
100 case server_broken:
101 return;
102 case server_disconnected:
103 break;
104 default:
105 abort();
106 }
107
111
112 proto= getprotobyname("tcp");
113 if (!proto) { adns__diag(ads,-1,0,"unable to find protocol no. for TCP !"); return; }
115 fd= socket(AF_INET,SOCK_STREAM,proto->p_proto);
117 if (fd<0) {
118 adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno));
119 return;
120 }
122 if (r) {
123 adns__diag(ads,-1,0,"cannot make TCP socket nonblocking: %s",strerror(r));
125 return;
126 }
127 memset(&addr,0,sizeof(addr));
128 addr.sin_family= AF_INET;
129 addr.sin_port= htons(DNS_PORT);
130 addr.sin_addr= ads->servers[ads->tcpserver].addr;
132 r= connect(fd,(const struct sockaddr*)&addr,sizeof(addr));
134 ads->tcpsocket= fd;
135 ads->tcpstate= server_connecting;
136 if (r==0) { tcp_connected(ads,now); return; }
137 if (errno == EWOULDBLOCK || errno == EINPROGRESS) {
140 return;
141 }
143 ads->tcpstate= server_disconnected;
144 }
145}
#define adns_socket_close(sck)
Definition: adns_win32.h:99
#define EINPROGRESS
Definition: errno.h:126
#define SOCK_STREAM
Definition: tcpip.h:118
LPPROTOENT WSAAPI getprotobyname(IN CONST CHAR FAR *name)
Definition: getproto.c:305
GLenum const GLvoid * addr
Definition: glext.h:9621
static void tcp_connected(adns_state ads, struct timeval now)
Definition: event.c:78
int adns__setnonblock(adns_state ads, ADNS_SOCKET fd)
Definition: setup.c:457
#define TCPCONNMS
Definition: internal.h:68
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
int tcprecv_skip
Definition: internal.h:300
vbuf tcprecv
Definition: internal.h:299

Referenced by query_usetcp(), and tcp_events().

◆ adns__timeouts()

void adns__timeouts ( adns_state  ads,
int  act,
struct timeval **  tv_io,
struct timeval tvbuf,
struct timeval  now 
)

Definition at line 283 of file event.c.

285 {
286 timeouts_queue(ads,act,tv_io,tvbuf,now, &ads->udpw);
287 timeouts_queue(ads,act,tv_io,tvbuf,now, &ads->tcpw);
288 tcp_events(ads,act,tv_io,tvbuf,now);
289}
static void timeouts_queue(adns_state ads, int act, struct timeval **tv_io, struct timeval *tvbuf, struct timeval now, struct query_queue *queue)
Definition: event.c:205
static void tcp_events(adns_state ads, int act, struct timeval **tv_io, struct timeval *tvbuf, struct timeval now)
Definition: event.c:227

Referenced by adns_beforeselect(), adns_firsttimeout(), and adns_processtimeouts().

◆ adns__transfer_interim()

void adns__transfer_interim ( adns_query  from,
adns_query  to,
void block,
size_t  sz 
)

Definition at line 366 of file query.c.

366 {
367 allocnode *an;
368
369 if (!block) return;
370 an= (void*)((byte*)block - MEM_ROUND(sizeof(*an)));
371
373 assert(!from->final_allocspace);
374
375 LIST_UNLINK(from->allocations,an);
377
378 sz= MEM_ROUND(sz);
379 from->interim_allocd -= sz;
380 to->interim_allocd += sz;
381
382 if (to->expires > from->expires) to->expires= from->expires;
383}
CardRegion * from
Definition: spigame.cpp:19
struct adns__query::@4230 allocations
static unsigned int block
Definition: xmlmemory.c:101

Referenced by icb_hostaddr().

◆ adns__update_expires()

void adns__update_expires ( adns_query  qu,
unsigned long  ttl,
struct timeval  now 
)

Definition at line 458 of file query.c.

458 {
459 time_t max;
460
461 assert(ttl <= MAXTTLBELIEVE);
462 max= now.tv_sec + ttl;
463 if (qu->expires < max) return;
464 qu->expires= max;
465}
__kernel_time_t time_t
Definition: linux.h:252

Referenced by adns__procdgram(), and pap_findaddrs().

◆ adns__vbuf_append()

int adns__vbuf_append ( vbuf vb,
const byte data,
int  len 
)

Definition at line 131 of file general.c.

131 {
132 int newlen;
133 void *nb;
134
135 newlen= vb->used+len;
136 if (vb->avail < newlen) {
137 if (newlen<20) newlen= 20;
138 newlen <<= 1;
139 nb= realloc(vb->buf,(size_t) newlen);
140 if (!nb) { newlen= vb->used+len; nb= realloc(vb->buf, (size_t) newlen); }
141 if (!nb) return 0;
142 vb->buf= nb;
143 vb->avail= newlen;
144 }
146 return 1;
147}
GLenum GLsizei len
Definition: glext.h:6722
void adns__vbuf_appendq(vbuf *vb, const byte *data, int len)
Definition: general.c:126
int avail
Definition: internal.h:111

Referenced by adns__diag_domain(), adns__parse_domain_more(), adns__querysend_tcp(), adns__search_next(), adns__vbuf_appendstr(), adns_rr_info(), adns_submit(), csp_qstring(), pap_mailbox822(), and vbuf__append_quoted1035().

◆ adns__vbuf_appendq()

void adns__vbuf_appendq ( vbuf vb,
const byte data,
int  len 
)

Definition at line 126 of file general.c.

126 {
127 memcpy(vb->buf+vb->used,data, (size_t) len);
128 vb->used+= len;
129}

Referenced by adns__vbuf_append(), and pap_mailbox822().

◆ adns__vbuf_appendstr()

int adns__vbuf_appendstr ( vbuf vb,
const char data 
)

Definition at line 149 of file general.c.

149 {
150 int l;
151 l= strlen(data);
152 return adns__vbuf_append(vb,(byte*)data,l);
153}

Referenced by adns__diag_domain(), adns__search_next(), and pap_mailbox822().

◆ adns__vbuf_ensure()

void void void int adns__vbuf_ensure ( vbuf vb,
int  want 
)

Definition at line 116 of file general.c.

116 {
117 void *nb;
118
119 if (vb->avail >= want) return 1;
120 nb= realloc(vb->buf, (size_t) want); if (!nb) return 0;
121 vb->buf= nb;
122 vb->avail= want;
123 return 1;
124}

Referenced by adns__query_done(), adns__querysend_tcp(), adns_processreadable(), adns_processwriteable(), mkquery_header(), pap_findaddrs(), and pap_mailbox822().

◆ adns__vbuf_free()

void adns__vbuf_free ( vbuf vb)

Definition at line 155 of file general.c.

155 {
156 free(vb->buf);
157 adns__vbuf_init(vb);
158}

Referenced by adns__internal_submit(), adns__procdgram(), adns__vdiag(), adns_finish(), adns_rr_info(), and free_query_allocs().

◆ adns__vbuf_init()

void adns__vbuf_init ( vbuf vb)

Definition at line 112 of file general.c.

112 {
113 vb->used= vb->avail= 0; vb->buf= 0;
114}

Referenced by adns__procdgram(), adns__vbuf_free(), adns__vdiag(), adns_rr_info(), init_begin(), query_alloc(), query_simple(), and query_submit().

◆ adns__vdiag()

void adns__vdiag ( adns_state  ads,
const char pfx,
adns_initflags  prevent,
int  serv,
adns_query  qu,
const char fmt,
va_list  al 
)

Definition at line 45 of file general.c.

46 {
47 const char *bef, *aft;
48 vbuf vb;
49
50 if (!ads->diagfile ||
51 (!(ads->iflags & adns_if_debug) && (!prevent || (ads->iflags & prevent))))
52 return;
53
54 if (ads->iflags & adns_if_logpid) {
55 fprintf(ads->diagfile,"adns%s [%ld]: ",pfx,(long)getpid());
56 } else {
57 fprintf(ads->diagfile,"adns%s: ",pfx);
58 }
59
61
62 bef= " (";
63 aft= "\n";
64
65 if (qu && qu->query_dgram) {
66 adns__vbuf_init(&vb);
67 fprintf(ads->diagfile,"%sQNAME=%s, QTYPE=%s",
68 bef,
69 adns__diag_domain(qu->ads,-1,0, &vb,
71 qu->typei ? qu->typei->rrtname : "<unknown>");
72 if (qu->typei && qu->typei->fmtname)
73 fprintf(ads->diagfile,"(%s)",qu->typei->fmtname);
74 bef=", "; aft=")\n";
75 adns__vbuf_free(&vb);
76 }
77
78 if (serv>=0) {
79 fprintf(ads->diagfile,"%sNS=%s",bef,inet_ntoa(ads->servers[serv].addr));
80 bef=", "; aft=")\n";
81 }
82
83 fputs(aft,ads->diagfile);
84}
@ adns_if_logpid
Definition: adns.h:92
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define inet_ntoa(addr)
Definition: inet.h:100
FILE * diagfile
Definition: internal.h:293
Definition: dsound.c:943
const char * rrtname
Definition: internal.h:126
const char * fmtname
Definition: internal.h:127
#define getpid
Definition: wintirpc.h:52

Referenced by adns__debug(), adns__diag(), and adns__warn().

◆ adns__warn()

void void adns__warn ( adns_state  ads,
int  serv,
adns_query  qu,
const char fmt,
  ... 
)

◆ ctype_822special()

static int ctype_822special ( int  c)
inlinestatic

Definition at line 702 of file internal.h.

702{ return strchr("()<>@,;:\\\".[]",c) != 0; }
char * strchr(const char *String, int ch)
Definition: utclib.c:501

Referenced by pap_mailbox822().

◆ ctype_alpha()

static int ctype_alpha ( int  c)
inlinestatic

Definition at line 699 of file internal.h.

699 {
700 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
701}

Referenced by adns__findrr_anychk(), adns__mkquery(), adns__parse_domain_more(), and ctype_domainunquoted().

◆ ctype_digit()

static int ctype_digit ( int  c)
inlinestatic

Definition at line 698 of file internal.h.

698{ return c>='0' && c<='9'; }

Referenced by adns__mkquery(), adns__parse_domain_more(), and ctype_domainunquoted().

◆ ctype_domainunquoted()

static int ctype_domainunquoted ( int  c)
inlinestatic

Definition at line 703 of file internal.h.

703 {
704 return ctype_alpha(c) || ctype_digit(c) || (strchr("-_/+",c) != 0);
705}

Referenced by vbuf__append_quoted1035().

◆ ctype_whitespace()

static int ctype_whitespace ( int  c)
inlinestatic

Definition at line 697 of file internal.h.

697{ return c==' ' || c=='\n' || c=='\t'; }

Referenced by nextword(), and readconfiggeneric().

◆ errno_resources()

static int errno_resources ( int  e)
inlinestatic

Definition at line 707 of file internal.h.

707{ return e==ENOMEM || e==ENOBUFS; }
#define e
Definition: ke_i.h:82

Referenced by adns_processreadable(), and adns_processwriteable().

◆ vbuf__append_quoted1035()

int vbuf__append_quoted1035 ( vbuf vb,
const byte buf,
int  len 
)

Definition at line 34 of file parse.c.

34 {
35 char qbuf[10];
36 int i, ch;
37
38 while (len) {
39 qbuf[0]= 0;
40 for (i=0; i<len; i++) {
41 ch= buf[i];
42 if (ch <= ' ' || ch >= 127) {
43 sprintf(qbuf,"\\%03o",ch);
44 break;
45 } else if (!ctype_domainunquoted(ch)) {
46 sprintf(qbuf,"\\%c",ch);
47 break;
48 }
49 }
50 if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,(byte*)qbuf,(int) strlen(qbuf)))
51 return 0;
52 if (i<len) i++;
53 buf+= i;
54 len-= i;
55 }
56 return 1;
57}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static int ctype_domainunquoted(int c)
Definition: internal.h:703

Referenced by adns__parse_domain_more().