19static int doit(stralloc *work,
const char *rule)
23 unsigned int prefixlen;
26 if ((ch !=
'?') && (ch !=
'=') && (ch !=
'*') && (ch !=
'-'))
return 1;
27 colon = str_chr((
char *)rule,
':');
28 if (!rule[colon])
return 1;
30 if (work->len < colon)
return 1;
31 prefixlen = work->len - colon;
32 if ((ch ==
'=') && prefixlen)
return 1;
33 if (case_diffb((
char *)rule,colon,work->s + prefixlen))
return 1;
35 if (byte_chr(work->s,prefixlen,
'.') < prefixlen)
return 1;
36 if (byte_chr(work->s,prefixlen,
'[') < prefixlen)
return 1;
37 if (byte_chr(work->s,prefixlen,
']') < prefixlen)
return 1;
40 work->len = prefixlen;
41 if (ch ==
'-') work->len = 0;
42 return stralloc_cats(work,rule + colon + 1);
55 if (!stralloc_copy(fqdn,(stralloc *)in))
return DNS_MEM;
57 for (j = i = 0; j < rules->len; ++j)
64 plus = byte_chr(fqdn->s,fqdnlen,
'+');
70 j = byte_chr(fqdn->s + i,fqdnlen - i,
'+');
71 byte_copy(fqdn->s + plus,j,fqdn->s + i);
75 if (i >= fqdnlen)
return rc;
85 if (!stralloc_copys(ipout,
""))
return DNS_MEM;
86 if (!stralloc_copys(fqdn,
""))
return DNS_MEM;
90 if (!stralloc_copyb(ipout,(
const char *) V6loopback,16))
return DNS_MEM;
91 if (!stralloc_catb(ipout,(
const char *) V46loopback,16))
return DNS_MEM;
92 if (!stralloc_copys(fqdn,
"localhost.localhost."))
return DNS_MEM;
95 if (!stralloc_copyb(ipout,(
const char *) V46loopback,16))
return DNS_MEM;
96 if (!stralloc_copys(fqdn,
"ip4-loopback.localhost."))
return DNS_MEM;
99 if (!stralloc_copyb(ipout,(
const char *) V6loopback,16))
return DNS_MEM;
100 if (!stralloc_copys(fqdn,
"ip6-loopback.localhost."))
return DNS_MEM;
104 return ipout->len ? ipout->len % 15 : 0;
112 static stralloc rules;
126 unsigned int fqdnlen;
129 if (!stralloc_copy(fqdn,(stralloc *)in))
return DNS_MEM;
131 for (j = i = 0; j < rules->len; ++j)
138 plus = byte_chr(fqdn->s,fqdnlen,
'+');
144 j = byte_chr(fqdn->s + i,fqdnlen - i,
'+');
145 byte_copy(fqdn->s + plus,j,fqdn->s + i);
146 fqdn->len = plus + j;
149 if (i >= fqdnlen)
return rc;
160 static stralloc rules;
175 unsigned int fqdnlen;
179 if (!stralloc_copy(fqdn,(stralloc *)in))
return DNS_MEM;
180 if (!stralloc_copys(ipout,
""))
return DNS_MEM;
182 for (j = i = 0; j < rules->len; ++j)
189 plus = byte_chr(fqdn->s,fqdnlen,
'+');
190 if (plus >= fqdnlen) {
193 for (k = 0; k <
tmp.len; k += 4) {
194 if (!stralloc_catb(ipout,(
const char *) V4mappedprefix,12))
return DNS_MEM;
195 if (!stralloc_catb(ipout,
tmp.s + k,4))
return DNS_MEM;
204 j = byte_chr(fqdn->s + i,fqdnlen - i,
'+');
205 byte_copy(fqdn->s + plus,j,fqdn->s + i);
206 fqdn->len = plus + j;
207 if (!stralloc_copys(ipout,
""))
return DNS_MEM;
209 if (rc)
if (!stralloc_cat(ipout,&
tmp))
return DNS_MEM;
211 for (k = 0; k <
tmp.len; k += 4) {
212 if (!stralloc_catb(ipout,(
const char *) V4mappedprefix,12))
return DNS_MEM;
213 if (!stralloc_catb(ipout,
tmp.s + k,4))
return DNS_MEM;
220 if (i >= fqdnlen)
return rc;
231 static stralloc rules;
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
int dns_ip4(stralloc *out, stralloc *fqdn)
int dns_ip6(stralloc *out, stralloc *fqdn)
int dns_ip4_qualify(stralloc *ipout, stralloc *fqdn, const stralloc *in)
int dns_ip_qualify_localhost(stralloc *ipout, stralloc *fqdn, const stralloc *in)
int dns_ip6_qualify(stralloc *ipout, stralloc *fqdn, const stralloc *in)
int dns_ip4_qualify_rules(stralloc *ipout, stralloc *fqdn, const stralloc *in, const stralloc *rules)
int dns_ip6_qualify_rules(stralloc *ipout, stralloc *fqdn, const stralloc *in, const stralloc *rules)
int dns_ip_qualify(stralloc *ipout, stralloc *fqdn, const stralloc *in)
int dns_ip_qualify_rules(stralloc *ipout, stralloc *fqdn, const stralloc *in, const stralloc *rules)
int dns_resolvconfrewrite(stralloc *out)