diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-09-16 12:39:47 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-09-16 12:39:47 +0200 |
commit | a4e444f430b874661f2793d8f9d1daeab60a89b1 (patch) | |
tree | 33ed9966cf0619211b4a0cff84ebd3a9097f78ab /sys/src/libndb/ndbgetipaddr.c | |
parent | 08385e66816940b999a5c433a1feef303cea67e4 (diff) |
libndb: make ndbipinfo() walk ipnet for all matching entries, concatenate and dedup result
Diffstat (limited to 'sys/src/libndb/ndbgetipaddr.c')
-rw-r--r-- | sys/src/libndb/ndbgetipaddr.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/sys/src/libndb/ndbgetipaddr.c b/sys/src/libndb/ndbgetipaddr.c index db3fbb018..f34df6b22 100644 --- a/sys/src/libndb/ndbgetipaddr.c +++ b/sys/src/libndb/ndbgetipaddr.c @@ -16,6 +16,7 @@ ndbgetipaddr(Ndb *db, char *val) attr = ipattr(val); if(strcmp(attr, "ip") == 0){ it = ndbnew("ip", val); + it->line = it; ndbsetmalloctag(it, getcallerpc(&db)); return it; } @@ -25,24 +26,29 @@ ndbgetipaddr(Ndb *db, char *val) 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); + do { + /* remove the non-ip entries */ + for(; it != nil; it = next){ + next = it->entry; + if(strcmp(it->attr, "ip") == 0){ + if(first == nil) + first = it; + else { + last->entry = it; + last->line = it; + } + it->entry = nil; + it->line = first; + last = it; + } else { + it->entry = nil; + ndbfree(it); + } } - } + } while((it = ndbsnext(&s, attr, val)) != nil); + + first = ndbdedup(first); ndbsetmalloctag(first, getcallerpc(&db)); return first; |