21 static char data[100 + IP6_FMT];
23 static int doit(
char *q,
char qtype[2])
37 struct uint128_t ipnum6;
41 stralloc ipstring = {0};
44 flaga = byte_equal(qtype,2,
DNS_T_A);
47 if (byte_equal(qtype,2,
DNS_T_ANY)) flaga = flaga4 = flagtxt = 1;
48 if (!(flaga || flaga4) && !flagtxt)
goto REFUSE;
50 if (flaga || flagtxt) {
53 if (r != 4)
goto REFUSE;
54 uint32_unpack(reverseip4,&ipnum4);
55 uint32_pack_big(
ip4,ipnum4);
56 if (ip4_bytestring(&ipstring,
ip4,32))
return 0;
58 for (i = 32; i > 0; --i) {
59 if (!stralloc_copys(&
tmp,
""))
return 0;
60 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
61 r = cdb_find(&c,
tmp.s,i);
62 if (r == -1)
return 0;
70 if (flaga4 || flagtxt) {
72 if (
dd6(q,
base,reverseip6) != 16)
goto REFUSE;
74 uint128_unpack(reverseip6,&ipnum6);
75 uint128_pack_big(
ip6,ipnum6);
76 if (ip6_bytestring(&ipstring,
ip6,128))
return 0;
77 if (!stralloc_copys(&
tmp,
"^"))
return 0;
78 if (!stralloc_catb(&
tmp,ipstring.s,128))
return 0;
79 r = cdb_find(&c,
tmp.s,129);
82 uint64_unpack(reverseip6+8,&ipnum5);
83 uint64_pack_big(ip5,ipnum5);
84 if (ip6_bytestring(&ipstring,ip5,64))
return 0;
86 for (i = 64; i > 0; --i) {
87 if (!stralloc_copys(&
tmp,
"^"))
return 0;
88 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
89 r = cdb_find(&c,
tmp.s,i);
90 if (r == -1)
return 0;
98 r = cdb_find(&c,
"",0);
99 if (r == -1)
return 0;
100 if (r && ((
dlen = cdb_datalen(&c)) >= 4)) {
102 if (cdb_read(&c,
data,
dlen,cdb_datapos(&c)) == -1)
return 0;
106 byte_copy(
data,
dlen,
"\177\0\0\2Listed $");
150 fd = open_read(
"data.cdb");
151 if (
fd == -1)
return 0;
153 result =
doit(q,qtype);
167 logmsg(
WHO,111,ERROR,
"$BASE not set");
169 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 **, const char *, unsigned int)
int respond(char *q, char qtype[2], char ip[16])
int response_addbytes(const char *buf, unsigned int len)
void response_rfinish(int x)
void response_nxdomain(void)
int response_rstart(const char *d, const char type[2], uint32 ttl)