10 static char *mtpt, *dns, *srv;
13 setup(int argc, char **argv)
22 fd = open(dns, ORDWR);
25 sysfatal("can't open %s: %r", dns);
26 fd = open(srv, ORDWR);
28 sysfatal("can't open %s: %r", srv);
29 if(mount(fd, -1, mtpt, MBEFORE, "") < 0)
30 sysfatal("can't mount(%s, %s): %r", srv, mtpt);
31 fd = open(dns, ORDWR);
33 sysfatal("can't open %s: %r", dns);
39 querydns(int fd, char *line, int n)
44 if(write(fd, line, n) != n) {
50 while((n = read(fd, buf, sizeof(buf))) > 0){
61 char buf[1024], line[1024];
65 for(print("> "); lp = Brdline(&in, '\n'); print("> ")){
78 /* default to an "ip" request if alpha, "ptr" if numeric */
79 if(strchr(line, ' ') == nil)
80 if(strcmp(ipattr(line), "ip") == 0) {
88 /* inverse queries may need to be permuted */
89 if(n > 4 && strcmp(" ptr", &line[n-4]) == 0 &&
90 cistrstr(line, ".arpa") == nil){
91 /* TODO: reversing v6 addrs is harder */
92 for(p = line; *p; p++)
103 memmove(np, p+1, len);
108 memmove(np, p+1, len);
110 strcpy(np, "in-addr.arpa ptr"); /* TODO: ip6.arpa for v6 */
115 querydns(fd, line, n);
121 main(int argc, char *argv[])
130 dns = "/net.alt/dns";
131 srv = "/srv/dns_net.alt";
134 fprint(2, "usage: %s [-x] [dns-mount-point]\n", argv0);
138 query(setup(argc, argv));