2 #include <sys/socket.h> 14 static int serverwantstcp(
const char *
buf,
unsigned int len)
19 if (out[2] & 2)
return 1;
23 static int serverfailed(
const char *
buf,
unsigned int len)
31 if (rcode && (rcode != 3)) { errno =
error_again;
return 1; }
35 static int irrelevant(
const struct dns_transmit *d,
const char *
buf,
unsigned int len)
43 if (out[4] != 0)
return 1;
44 if (out[5] != 1)
return 1;
67 if (!d->
query)
return;
90 for (j = 0;j < 10;++j)
98 static const int timeouts[4] = { 1, 3, 11, 45 };
209 if (!d->
query)
return -1;
212 byte_copy(d->
query + 2,12,flagrecursive ?
"\0\0\1\0\0\1\0\0\0\0\0\0" :
"\0\0\0\0\0\1\0\0\0\0\0\0gcc-bug-workaround");
221 d->
udploop = flagrecursive ? 1 : 0;
223 if (len + 16 >
UDPSIZE)
return firsttcp(d);
232 case 0:
case 3:
case 4:
case 5:
233 x->events = IOPAUSE_READ;
236 x->events = IOPAUSE_WRITE;
257 if (d->
tcpstate == 0)
return nextudp(d);
266 r = recv(fd,udpbuf,
sizeof udpbuf,0);
271 if (r + 1 >
sizeof udpbuf)
return 0;
273 if (irrelevant(d,udpbuf,r))
return 0;
274 if (serverwantstcp(udpbuf,r))
return firsttcp(d);
275 if (serverfailed(udpbuf,r)) {
306 if (r <= 0)
return nexttcp(d);
324 if (r <= 0)
return nexttcp(d);
337 if (r <= 0)
return nexttcp(d);
355 if (r <= 0)
return nexttcp(d);
char * alloc(unsigned int n)
const unsigned char V6any[16]
void byte_copy(void *, unsigned int, const void *)
void dns_transmit_free(struct dns_transmit *d)
int socket_connect6(int s, const char *ip, uint16 port, uint32 scope_id)
void uint16_pack_big(char *, uint16)
int byte_diff(const void *, unsigned int n, const void *)
int socket_bind6(int s, const char *ip, uint16 port, uint32 scope_id)
int dns_transmit_start(struct dns_transmit *d, const char servers[256], int flagrecursive, const char *q, const char qtype[2], const unsigned char localip[16])
int dns_transmit_get(struct dns_transmit *d, const iopause_fd *x, const struct taia *when)
int taia_now(struct taia *)
int taia_less(const struct taia *, const struct taia *)
void dns_transmit_io(struct dns_transmit *d, iopause_fd *x, struct taia *deadline)
unsigned int dns_random(unsigned int)
int dns_domain_equal(const char *, const char *)
void taia_add(struct taia *, const struct taia *, const struct taia *)
void taia_uint(struct taia *, unsigned int)
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, char *, unsigned int)
unsigned int dns_domain_length(const char *)
int socket_connected(int)
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)