This commit is contained in:
rsc
2005-02-11 19:41:16 +00:00
parent ad017cfbf5
commit d957951b75
27 changed files with 2521 additions and 0 deletions

47
src/libndb/ndbgetipaddr.c Normal file
View File

@@ -0,0 +1,47 @@
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ndb.h>
#include <ip.h>
/* return list of ip addresses for a name */
Ndbtuple*
ndbgetipaddr(Ndb *db, char *val)
{
char *attr, *p;
Ndbtuple *it, *first, *last, *next;
Ndbs s;
/* already an IP address? */
attr = ipattr(val);
if(strcmp(attr, "ip") == 0){
it = ndbnew("ip", val);
return it;
}
/* look it up */
p = ndbgetvalue(db, &s, attr, val, "ip", &it);
if(p == nil)
return nil;
free(p);
/* remove the non-ip entries */
first = last = nil;
for(; it; it = next){
next = it->entry;
if(strcmp(it->attr, "ip") == 0){
if(first == nil)
first = it;
else
last->entry = it;
it->entry = nil;
it->line = first;
last = it;
} else {
it->entry = nil;
ndbfree(it);
}
}
return first;
}