Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature-vt/sys/src/libndb/ndbgetipaddr.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <bio.h>
4
#include <ndb.h>
5
#include <ip.h>
6
 
7
/* return list of ip addresses for a name */
8
Ndbtuple*
9
ndbgetipaddr(Ndb *db, char *val)
10
{
11
	char *attr, *p;
12
	Ndbtuple *it, *first, *last, *next;
13
	Ndbs s;
14
 
15
	/* already an IP address? */
16
	attr = ipattr(val);
17
	if(strcmp(attr, "ip") == 0){
18
		it = ndbnew("ip", val);
19
		ndbsetmalloctag(it, getcallerpc(&db));
20
		return it;
21
	}
22
 
23
	/* look it up */
24
	p = ndbgetvalue(db, &s, attr, val, "ip", &it);
25
	if(p == nil)
26
		return nil;
27
	free(p);
28
 
29
	/* remove the non-ip entries */
30
	first = last = nil;
31
	for(; it; it = next){
32
		next = it->entry;
33
		if(strcmp(it->attr, "ip") == 0){
34
			if(first == nil)
35
				first = it;
36
			else
37
				last->entry = it;
38
			it->entry = nil;
39
			it->line = first;
40
			last = it;
41
		} else {
42
			it->entry = nil;
43
			ndbfree(it);
44
		}
45
	}
46
 
47
	ndbsetmalloctag(first, getcallerpc(&db));
48
	return first;
49
}