aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ndb
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-02-20 19:38:29 +0000
committerrsc <devnull@localhost>2006-02-20 19:38:29 +0000
commit49a1496cbbb871bc623cfd0925566628e246c9ba (patch)
tree4eea59915e34dcba169e8adabc19e58676205457 /src/cmd/ndb
parent772b39cd98587a1ac72a4876bb5aac9e7a498f36 (diff)
downloadplan9port-49a1496cbbb871bc623cfd0925566628e246c9ba.tar.gz
plan9port-49a1496cbbb871bc623cfd0925566628e246c9ba.tar.bz2
plan9port-49a1496cbbb871bc623cfd0925566628e246c9ba.zip
dns changes
Diffstat (limited to 'src/cmd/ndb')
-rwxr-xr-xsrc/cmd/ndb/dn.c2
-rwxr-xr-xsrc/cmd/ndb/dnresolve.c35
-rwxr-xr-xsrc/cmd/ndb/dns.c39
-rwxr-xr-xsrc/cmd/ndb/dns.h6
-rwxr-xr-xsrc/cmd/ndb/dnsdebug.c12
-rwxr-xr-xsrc/cmd/ndb/dnsquery.c2
-rwxr-xr-xsrc/cmd/ndb/dnstcp.c3
-rw-r--r--src/cmd/ndb/dntcpserver.c6
-rwxr-xr-xsrc/cmd/ndb/dnudpserver.c4
9 files changed, 61 insertions, 48 deletions
diff --git a/src/cmd/ndb/dn.c b/src/cmd/ndb/dn.c
index b24a5ff4..d1bfcaed 100755
--- a/src/cmd/ndb/dn.c
+++ b/src/cmd/ndb/dn.c
@@ -1183,8 +1183,8 @@ warning(char *fmt, ...)
void
dncheck(void *p, int dolock)
{
- int i;
DN *dp;
+ int i;
RR *rp;
if(p != nil){
diff --git a/src/cmd/ndb/dnresolve.c b/src/cmd/ndb/dnresolve.c
index 7ba17c0c..cc6aec3d 100755
--- a/src/cmd/ndb/dnresolve.c
+++ b/src/cmd/ndb/dnresolve.c
@@ -278,17 +278,6 @@ mkreq(DN *dp, int type, uchar *buf, int flags, ushort reqno)
return len;
}
-/* for alarms in readreply */
-static void
-ding(void *x, char *msg)
-{
- USED(x);
- if(strcmp(msg, "alarm") == 0)
- noted(NCONT);
- else
- noted(NDFLT);
-}
-
static void
freeanswers(DNSmsg *mp)
{
@@ -301,6 +290,7 @@ freeanswers(DNSmsg *mp)
/*
* read replies to a request. ignore any of the wrong type. wait at most 5 seconds.
*/
+static int udpreadtimeout(int, Udphdr*, void*, int, int);
static int
readreply(int fd, DN *dp, int type, ushort req,
uchar *ibuf, DNSmsg *mp, ulong endtime, Request *reqp)
@@ -310,17 +300,13 @@ readreply(int fd, DN *dp, int type, ushort req,
ulong now;
RR *rp;
- notify(ding);
-
for(; ; freeanswers(mp)){
now = time(0);
if(now >= endtime)
return -1; /* timed out */
/* timed read */
- alarm((endtime - now) * 1000);
- len = udpread(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin);
- alarm(0);
+ len = udpreadtimeout(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin, (endtime-now)*1000);
if(len < 0)
return -1; /* timed out */
@@ -365,6 +351,23 @@ readreply(int fd, DN *dp, int type, ushort req,
return 0; /* never reached */
}
+static int
+udpreadtimeout(int fd, Udphdr *h, void *data, int n, int ms)
+{
+ fd_set rd;
+ struct timeval tv;
+
+ FD_ZERO(&rd);
+ FD_SET(fd, &rd);
+
+ tv.tv_sec = ms/1000;
+ tv.tv_usec = (ms%1000)*1000;
+
+ if(select(fd+1, &rd, 0, 0, &tv) != 1)
+ return -1;
+ return udpread(fd, h, data, n);
+}
+
/*
* return non-0 if first list includes second list
*/
diff --git a/src/cmd/ndb/dns.c b/src/cmd/ndb/dns.c
index 90a1a193..901b7acb 100755
--- a/src/cmd/ndb/dns.c
+++ b/src/cmd/ndb/dns.c
@@ -96,7 +96,8 @@ Job* newjob(void);
void freejob(Job*);
void setext(char*, int, char*);
-char *portname = "domain";
+char *tcpaddr = "tcp!*!dns";
+char *udpaddr = "udp!*!dns";
char *logfile = "dns";
char *dbfile;
char mntpt[Maxpath];
@@ -105,11 +106,22 @@ char *LOG;
void
usage(void)
{
- fprint(2, "usage: dns [-dnrstT] [-a maxage] [-f ndb-file] [-p port] [-x service] [-z zoneprog]\n");
+ fprint(2, "usage: dns [-dnrst] [-a maxage] [-f ndb-file] [-p port] [-T tcpaddr] [-U udpaddr] [-x service] [-z zoneprog]\n");
threadexitsall("usage");
}
void
+checkaddress(void)
+{
+ char *u, *t;
+
+ u = strchr(udpaddr, '!');
+ t = strchr(tcpaddr, '!');
+ if(u && t && strcmp(u, t) != 0)
+ fprint(2, "warning: announce mismatch %s %s\n", udpaddr, tcpaddr);
+}
+
+void
threadmain(int argc, char *argv[])
{
int serveudp, servetcp;
@@ -136,28 +148,33 @@ threadmain(int argc, char *argv[])
serveudp = 1;
cachedb = 1;
break;
- case 'T':
+ case 't':
servetcp = 1;
cachedb = 1;
break;
case 'a':
maxage = atoi(EARGF(usage()));
break;
- case 't':
- testing = 1;
- break;
case 'z':
zonerefreshprogram = EARGF(usage());
break;
- case 'p':
- portname = EARGF(usage());
- break;
case 'n':
sendnotifies = 1;
break;
+ case 'U':
+ udpaddr = estrdup(netmkaddr(EARGF(usage()), "udp", "dns"));
+ break;
+ case 'T':
+ tcpaddr = estrdup(netmkaddr(EARGF(usage()), "tcp", "dns"));
+ break;
+ default:
+ usage();
}ARGEND
- USED(argc);
- USED(argv);
+
+ if(argc)
+ usage();
+ if(serveudp && servetcp)
+ checkaddress();
rfork(RFNOTEG);
diff --git a/src/cmd/ndb/dns.h b/src/cmd/ndb/dns.h
index 1d19db7e..e08f1b5e 100755
--- a/src/cmd/ndb/dns.h
+++ b/src/cmd/ndb/dns.h
@@ -402,8 +402,10 @@ extern ulong now; /* time base */
extern Area *owned;
extern Area *delegated;
-extern char *portname;
+extern char *udpaddr;
+extern char *tcpaddr;
+#ifdef VARARGCK
#pragma varargck type "R" RR*
#pragma varargck type "Q" RR*
-
+#endif
diff --git a/src/cmd/ndb/dnsdebug.c b/src/cmd/ndb/dnsdebug.c
index 6e3a49f7..82109c18 100755
--- a/src/cmd/ndb/dnsdebug.c
+++ b/src/cmd/ndb/dnsdebug.c
@@ -33,7 +33,8 @@ char *logfile = "dns";
char *dbfile;
char mntpt[Maxpath];
char *zonerefreshprogram;
-char *portname = "domain";
+char *tcpaddr;
+char *udpaddr;
int prettyrrfmt(Fmt*);
void preloadserveraddrs(void);
@@ -45,7 +46,7 @@ void docmd(int, char**);
void
usage(void)
{
- fprint(2, "usage: dnsdebug -rxf [-p port] [query ...]\n");
+ fprint(2, "usage: dnsdebug [-fr] [query ...]\n");
threadexitsall("usage");
}
@@ -63,16 +64,9 @@ threadmain(int argc, char *argv[])
case 'r':
resolver = 1;
break;
- case 'x':
- dbfile = "/lib/ndb/external";
- strcpy(mntpt, "/net.alt");
- break;
case 'f':
dbfile = EARGF(usage());
break;
- case 'p':
- portname = EARGF(usage());
- break;
default:
usage();
}ARGEND
diff --git a/src/cmd/ndb/dnsquery.c b/src/cmd/ndb/dnsquery.c
index ca52010b..dc7ae06b 100755
--- a/src/cmd/ndb/dnsquery.c
+++ b/src/cmd/ndb/dnsquery.c
@@ -10,7 +10,7 @@
void
usage(void)
{
- fprint(2, "usage: dnsquery [-x dns]\n");
+ fprint(2, "usage: dnsquery [-x service]\n");
threadexitsall("usage");
}
diff --git a/src/cmd/ndb/dnstcp.c b/src/cmd/ndb/dnstcp.c
index e3f7eae5..75beda8b 100755
--- a/src/cmd/ndb/dnstcp.c
+++ b/src/cmd/ndb/dnstcp.c
@@ -25,7 +25,8 @@ int maxage;
uchar ipaddr[IPaddrlen]; /* my ip address */
char *LOG;
char *zonerefreshprogram;
-char *portname = "domain";
+char *tcpaddr;
+char *udpaddr;
void
usage(void)
diff --git a/src/cmd/ndb/dntcpserver.c b/src/cmd/ndb/dntcpserver.c
index 38e3ce7c..59d0e04b 100644
--- a/src/cmd/ndb/dntcpserver.c
+++ b/src/cmd/ndb/dntcpserver.c
@@ -269,12 +269,10 @@ static int
tcpannounce(char *mntpt)
{
int fd;
- char an[40];
USED(mntpt);
- snprint(an, sizeof an, "tcp!*!%s", portname);
- if((fd=announce(an, adir)) < 0)
- warning("announce %s: %r", an);
+ if((fd=announce(tcpaddr, adir)) < 0)
+ warning("announce %s: %r", tcpaddr);
return fd;
}
diff --git a/src/cmd/ndb/dnudpserver.c b/src/cmd/ndb/dnudpserver.c
index 54d29705..9f84125c 100755
--- a/src/cmd/ndb/dnudpserver.c
+++ b/src/cmd/ndb/dnudpserver.c
@@ -160,11 +160,9 @@ udpannounce(char *mntpt)
{
int fd;
char buf[40];
-
USED(mntpt);
- snprint(buf, sizeof buf, "udp!*!%s", portname);
- if((fd=announce(buf, buf)) < 0)
+ if((fd=announce(udpaddr, buf)) < 0)
warning("announce %s: %r", buf);
return fd;
}