diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libndb/ndbgetipaddr.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libndb/ndbgetipaddr.c')
-rwxr-xr-x | sys/src/libndb/ndbgetipaddr.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sys/src/libndb/ndbgetipaddr.c b/sys/src/libndb/ndbgetipaddr.c new file mode 100755 index 000000000..db3fbb018 --- /dev/null +++ b/sys/src/libndb/ndbgetipaddr.c @@ -0,0 +1,49 @@ +#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); + ndbsetmalloctag(it, getcallerpc(&db)); + 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); + } + } + + ndbsetmalloctag(first, getcallerpc(&db)); + return first; +} |