libndb: move mkptrname() into libndb to avoid duplication
This commit is contained in:
parent
2d56837b2f
commit
2899b719ae
7 changed files with 55 additions and 81 deletions
|
@ -128,6 +128,7 @@ char* csgetvalue(char*, char*, char*, char*, Ndbtuple**);
|
|||
Ndbtuple* csipinfo(char*, char*, char*, char**, int);
|
||||
Ndbtuple* dnsquery(char*, char*, char*);
|
||||
char* ipattr(char*);
|
||||
void mkptrname(char *ip, char *rip, int rlen);
|
||||
Ndb* ndbcat(Ndb*, Ndb*);
|
||||
int ndbchanged(Ndb*);
|
||||
void ndbclose(Ndb*);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.TH NDB 2
|
||||
.SH NAME
|
||||
ndbopen, ndbcat, ndbchanged, ndbclose, ndbreopen, ndbsearch, ndbsnext, ndbgetvalue, ndbfree, ipattr, ndbgetipaddr, ndbipinfo, csipinfo, ndbhash, ndbparse, csgetvalue, ndbfindattr, dnsquery, ndbdiscard, ndbconcatenate, ndbreorder, ndbsubstitute, ndbdedup \- network database
|
||||
ndbopen, ndbcat, ndbchanged, ndbclose, ndbreopen, ndbsearch, ndbsnext, ndbgetvalue, ndbfree, ipattr, mkptrname, ndbgetipaddr, ndbipinfo, csipinfo, ndbhash, ndbparse, csgetvalue, ndbfindattr, dnsquery, ndbdiscard, ndbconcatenate, ndbreorder, ndbsubstitute, ndbdedup \- network database
|
||||
.SH SYNOPSIS
|
||||
.B #include <u.h>
|
||||
.br
|
||||
|
@ -47,6 +47,9 @@ char* csgetvalue(char *netroot, char *attr, char *val,
|
|||
char* ipattr(char *name)
|
||||
.PP
|
||||
.B
|
||||
void mkptrname(char *ip, char *rip, int rlen);
|
||||
.PP
|
||||
.B
|
||||
Ndbtuple* ndbgetipaddr(Ndb *db, char *sys);
|
||||
.PP
|
||||
.B
|
||||
|
@ -236,6 +239,26 @@ Internet number
|
|||
system name
|
||||
.RE
|
||||
.PP
|
||||
.I Mkptrname
|
||||
converts the address string
|
||||
.I ip
|
||||
to a reverse lookup domain-name, returned in
|
||||
.IR rip .
|
||||
The
|
||||
.I rlen
|
||||
argument gives the maximum size of the
|
||||
.I rip
|
||||
buffer including the NUL-terminator.
|
||||
If
|
||||
.I ip
|
||||
already is a reverse lookup domain-name
|
||||
or has invalid ip address syntax,
|
||||
then
|
||||
.I ip
|
||||
is copied into
|
||||
.I rip
|
||||
verbatim.
|
||||
.PP
|
||||
.I Ndbgetipaddr
|
||||
looks in
|
||||
.I db
|
||||
|
|
|
@ -129,32 +129,6 @@ longtime(long t)
|
|||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
* convert address into a reverse lookup address
|
||||
*/
|
||||
static void
|
||||
mkptrname(char *ip, char *rip, int rlen)
|
||||
{
|
||||
uchar a[IPaddrlen];
|
||||
char *p, *e;
|
||||
int i;
|
||||
|
||||
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
|
||||
snprint(rip, rlen, "%s", ip);
|
||||
else if(isv4(a))
|
||||
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
|
||||
a[15], a[14], a[13], a[12]);
|
||||
else{
|
||||
p = rip;
|
||||
e = rip + rlen;
|
||||
for(i = 15; i >= 0; i--){
|
||||
p = seprint(p, e, "%ux.", a[i]&0xf);
|
||||
p = seprint(p, e, "%ux.", a[i]>>4);
|
||||
}
|
||||
seprint(p, e, "ip6.arpa");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
prettyrrfmt(Fmt *f)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <ctype.h>
|
||||
#include <ndb.h>
|
||||
#include "dns.h"
|
||||
#include "ip.h"
|
||||
|
||||
static void
|
||||
querydns(int fd, char *line, int n)
|
||||
|
@ -23,32 +22,6 @@ querydns(int fd, char *line, int n)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* convert address into a reverse lookup address
|
||||
*/
|
||||
static void
|
||||
mkptrname(char *ip, char *rip, int rlen)
|
||||
{
|
||||
uchar a[IPaddrlen];
|
||||
char *p, *e;
|
||||
int i;
|
||||
|
||||
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
|
||||
snprint(rip, rlen, "%s", ip);
|
||||
else if(isv4(a))
|
||||
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
|
||||
a[15], a[14], a[13], a[12]);
|
||||
else{
|
||||
p = rip;
|
||||
e = rip + rlen;
|
||||
for(i = 15; i >= 0; i--){
|
||||
p = seprint(p, e, "%ux.", a[i]&0xf);
|
||||
p = seprint(p, e, "%ux.", a[i]>>4);
|
||||
}
|
||||
seprint(p, e, "ip6.arpa");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
query(int fd)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <ndbhf.h>
|
||||
#include <ip.h>
|
||||
|
||||
static void mkptrname(char*, char*, int);
|
||||
static Ndbtuple *doquery(int, char *dn, char *type);
|
||||
|
||||
/*
|
||||
|
@ -51,32 +50,6 @@ dnsquery(char *net, char *val, char *type)
|
|||
return t;
|
||||
}
|
||||
|
||||
/*
|
||||
* convert address into a reverse lookup address
|
||||
*/
|
||||
static void
|
||||
mkptrname(char *ip, char *rip, int rlen)
|
||||
{
|
||||
uchar a[IPaddrlen];
|
||||
char *p, *e;
|
||||
int i;
|
||||
|
||||
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
|
||||
snprint(rip, rlen, "%s", ip);
|
||||
else if(isv4(a))
|
||||
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
|
||||
a[15], a[14], a[13], a[12]);
|
||||
else{
|
||||
p = rip;
|
||||
e = rip + rlen;
|
||||
for(i = 15; i >= 0; i--){
|
||||
p = seprint(p, e, "%ux.", a[i]&0xf);
|
||||
p = seprint(p, e, "%ux.", a[i]>>4);
|
||||
}
|
||||
seprint(p, e, "ip6.arpa");
|
||||
}
|
||||
}
|
||||
|
||||
static Ndbtuple*
|
||||
doquery(int fd, char *dn, char *type)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ OFILES=\
|
|||
csipinfo.$O\
|
||||
dnsquery.$O\
|
||||
ipattr.$O\
|
||||
mkptrname.$O\
|
||||
ndbaux.$O\
|
||||
ndbcache.$O\
|
||||
ndbcat.$O\
|
||||
|
|
29
sys/src/libndb/mkptrname.c
Normal file
29
sys/src/libndb/mkptrname.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <ip.h>
|
||||
|
||||
/*
|
||||
* convert address into a reverse lookup address
|
||||
*/
|
||||
void
|
||||
mkptrname(char *ip, char *rip, int rlen)
|
||||
{
|
||||
uchar a[IPaddrlen];
|
||||
char *p, *e;
|
||||
int i;
|
||||
|
||||
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
|
||||
snprint(rip, rlen, "%s", ip);
|
||||
else if(isv4(a))
|
||||
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
|
||||
a[15], a[14], a[13], a[12]);
|
||||
else{
|
||||
p = rip;
|
||||
e = rip + rlen;
|
||||
for(i = 15; i >= 0; i--){
|
||||
p = seprint(p, e, "%ux.", a[i]&0xf);
|
||||
p = seprint(p, e, "%ux.", a[i]>>4);
|
||||
}
|
||||
seprint(p, e, "ip6.arpa");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue