libndb: apply eriks dnsquery() ipv6 reverse lookup patch
This commit is contained in:
parent
64cb1dd5b4
commit
4971432577
1 changed files with 16 additions and 37 deletions
|
@ -3,8 +3,8 @@
|
||||||
#include <bio.h>
|
#include <bio.h>
|
||||||
#include <ndb.h>
|
#include <ndb.h>
|
||||||
#include <ndbhf.h>
|
#include <ndbhf.h>
|
||||||
|
#include <ip.h>
|
||||||
|
|
||||||
static void nstrcpy(char*, char*, int);
|
|
||||||
static void mkptrname(char*, char*, int);
|
static void mkptrname(char*, char*, int);
|
||||||
static Ndbtuple *doquery(int, char *dn, char *type);
|
static Ndbtuple *doquery(int, char *dn, char *type);
|
||||||
|
|
||||||
|
@ -77,45 +77,24 @@ dnsquery(char *net, char *val, char *type)
|
||||||
static void
|
static void
|
||||||
mkptrname(char *ip, char *rip, int rlen)
|
mkptrname(char *ip, char *rip, int rlen)
|
||||||
{
|
{
|
||||||
char buf[128];
|
uchar a[IPaddrlen];
|
||||||
char *p, *np;
|
char *p, *e;
|
||||||
int len;
|
int i;
|
||||||
|
|
||||||
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa")){
|
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
|
||||||
nstrcpy(rip, ip, rlen);
|
snprint(rip, rlen, "%s", ip);
|
||||||
return;
|
else if(isv4(a))
|
||||||
}
|
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
|
||||||
nstrcpy(buf, ip, sizeof buf);
|
a[15], a[14], a[13], a[12]);
|
||||||
|
else{
|
||||||
/* truncate if result wont fit in rip[rlen] */
|
p = rip;
|
||||||
assert(rlen > 14);
|
e = rip + rlen;
|
||||||
if((rlen-14) < sizeof(buf))
|
for(i = 15; i >= 0; i--){
|
||||||
buf[rlen-14] = 0;
|
p = seprint(p, e, "%ux.", a[i]&0xf);
|
||||||
|
p = seprint(p, e, "%ux.", a[i]>>4);
|
||||||
for(p = buf; *p; p++)
|
|
||||||
;
|
|
||||||
*p = '.';
|
|
||||||
np = rip;
|
|
||||||
len = 0;
|
|
||||||
while(p >= buf){
|
|
||||||
len++;
|
|
||||||
p--;
|
|
||||||
if(*p == '.'){
|
|
||||||
memmove(np, p+1, len);
|
|
||||||
np += len;
|
|
||||||
len = 0;
|
|
||||||
}
|
}
|
||||||
|
seprint(p, e, "ip6.arpa");
|
||||||
}
|
}
|
||||||
memmove(np, p+1, len);
|
|
||||||
np += len;
|
|
||||||
strcpy(np, "in-addr.arpa");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nstrcpy(char *to, char *from, int len)
|
|
||||||
{
|
|
||||||
strncpy(to, from, len);
|
|
||||||
to[len-1] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ndbtuple*
|
static Ndbtuple*
|
||||||
|
|
Loading…
Reference in a new issue