16#define WHO "dnsfilter"
20 logmsg(
WHO,111,FATAL,
"out of memory");
38static stralloc partial;
61 for (j = 0; j <
x[i].
middle.len; ++j)
66int main(
int argc,
char **argv)
76 while ((opt = getoptb(argc,argv,
"c:l:")) != opteof)
79 scan_ulong(optarg,&
u);
81 if (
u > 1000)
u = 1000;
85 scan_ulong(optarg,&
u);
87 if (
u > 1000000)
u = 1000000;
91 logmsg(
WHO,100,USAGE,
"dnsfilter [ -c concurrency ] [ -l lines ]");
98 io = (iopause_fd *) alloc((
xmax + 1) *
sizeof(iopause_fd));
101 if (!stralloc_copys(&partial,
""))
nomem();
106 taia_uint(&deadline,120);
107 taia_add(&deadline,&deadline,&stamp);
115 inio->events = IOPAUSE_READ;
118 for (i = 0; i <
xnum; ++i)
124 iopause(
io,
iolen,&deadline,&stamp);
136 for (i = 0; i <
xnum; ++i)
156 buffer_put(buffer_1,
x[0].
left.s,
x[0].
left.len);
159 buffer_flush(buffer_1);
162 for (i = 0;i <
xnum;++i)
x[i] =
x[i + 1];
177 if (!stralloc_catb(&partial,
inbuf,i))
nomem();
182 i = byte_chr(partial.s,partial.len,
'\n');
183 i = byte_chr(partial.s,i,
'\t');
184 i = byte_chr(partial.s,i,
' ');
188 if (!stralloc_copyb(&
x[
xnum].
right,partial.s + i,partial.len - i))
nomem();
192 if (!stralloc_0(&partial))
nomem();
193 if (str_chr(partial.s,
':') == partial.len - 1) {
200 logmsg(
WHO,111,FATAL,
"unable to read /etc/resolv.conf");
int dns_name_packet(stralloc *out, const char *buf, unsigned int len)
int dns_name4_domain(char name[DNS_NAME4_DOMAIN], const char ip[4])
int dns_name6_domain(char name[DNS_NAME6_DOMAIN], const char ip[16])
int dns_resolvconfip(char s[QUERY_MAXIPLEN], uint32 scope[QUERY_MAXNS])
void dns_transmit_io(struct dns_transmit *d, iopause_fd *x, struct taia *deadline)
int dns_transmit_start6(struct dns_transmit *d, const char servers[QUERY_MAXIPLEN], int flagrecursive, const char *q, const char qtype[2], const char localip[16], const uint32 scopes[QUERY_MAXNS])
int dns_transmit_get(struct dns_transmit *d, const iopause_fd *x, const struct taia *when)
char servers[QUERY_MAXIPLEN]
uint32 scopes[QUERY_MAXNS]
char name[DNS_NAME6_DOMAIN]