]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/ndb/ipquery.c
ndb/cs, ndb/dns: ignore special commands from users different from the one we run...
[plan9front.git] / sys / src / cmd / ndb / ipquery.c
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ndb.h>
5 #include <ip.h>
6
7 /*
8  *  search the database for matches
9  */
10
11 void
12 usage(void)
13 {
14         fprint(2, "usage: ipquery attr value rattribute\n");
15         exits("usage");
16 }
17
18 void
19 search(Ndb *db, char *attr, char *val, char **rattr, int nrattr)
20 {
21         Ndbtuple *t, *tt;
22
23         tt = ndbipinfo(db, attr, val, rattr, nrattr);
24         for(t = tt; t; t = t->entry)
25                 print("%s=%s ", t->attr, t->val);
26         print("\n");
27         ndbfree(tt);
28 }
29
30 void
31 main(int argc, char **argv)
32 {
33         Ndb *db;
34         char *dbfile = 0;
35
36         ARGBEGIN{
37         case 'f':
38                 dbfile = ARGF();
39                 break;
40         }ARGEND;
41
42         if(argc < 3)
43                 usage();
44
45         db = ndbopen(dbfile);
46         if(db == 0){
47                 fprint(2, "no db files\n");
48                 exits("no db");
49         }
50         search(db, argv[0], argv[1], argv+2, argc-2);
51         ndbclose(db);
52
53         exits(0);
54 }