22static char data[100 + IP6_FMT];
24static int doit(
char *q,
char qtype[2])
38 struct uint128_t ipnum6;
42 stralloc ipstring = {0};
45 flaga = byte_equal(qtype,2,
DNS_T_A);
48 if (byte_equal(qtype,2,
DNS_T_ANY)) flaga = flaga4 = flagtxt = 1;
49 if (!(flaga || flaga4) && !flagtxt)
goto REFUSE;
51 if (flaga || flagtxt) {
54 if (r != 4)
goto REFUSE;
55 uint32_unpack(reverseip4,&ipnum4);
56 uint32_pack_big(
ip4,ipnum4);
57 if (ip4_bytestring(&ipstring,
ip4,32))
return 0;
59 for (i = 32; i > 0; --i) {
60 if (!stralloc_copys(&
tmp,
""))
return 0;
61 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
62 r = cdb_find(&c,
tmp.s,i);
63 if (r == -1)
return 0;
71 if (flaga4 || flagtxt) {
73 if (
dd6(q,
base,reverseip6) != 16)
goto REFUSE;
75 uint128_unpack(reverseip6,&ipnum6);
76 uint128_pack_big(
ip6,ipnum6);
77 if (ip6_bytestring(&ipstring,
ip6,128))
return 0;
78 if (!stralloc_copys(&
tmp,
"^"))
return 0;
79 if (!stralloc_catb(&
tmp,ipstring.s,128))
return 0;
80 r = cdb_find(&c,
tmp.s,129);
83 uint64_unpack(reverseip6+8,&ipnum5);
84 uint64_pack_big(ip5,ipnum5);
85 if (ip6_bytestring(&ipstring,ip5,64))
return 0;
87 for (i = 64; i > 0; --i) {
88 if (!stralloc_copys(&
tmp,
"^"))
return 0;
89 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
90 r = cdb_find(&c,
tmp.s,i);
91 if (r == -1)
return 0;
99 r = cdb_find(&c,
"",0);
100 if (r == -1)
return 0;
101 if (r && ((
dlen = cdb_datalen(&c)) >= 4)) {
103 if (cdb_read(&c,
data,
dlen,cdb_datapos(&c)) == -1)
return 0;
107 byte_copy(
data,
dlen,
"\177\0\0\2Listed $");
151 fd = open_read(
"data.cdb");
152 if (
fd == -1)
return 0;
154 result =
doit(q,qtype);
168 logmsg(
WHO,111,ERROR,
"$BASE not set");
170 logmsg(
WHO,111,FATAL,
"unable to parse $BASE");
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
int dd6(const char *q, const char *base, char ip[16])
int dd4(const char *q, const char *base, char ip[4])
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
int respond(char *q, char qtype[2], char ip[16])
void response_rfinish(int)
int response_addbytes(const char *, unsigned int)
int response_rstart(const char *, const char *, uint32)
void response_nxdomain(void)