Subject: Re: changing resolv.conf ?
To: None <itojun@iijlab.net>
From: Assar Westerlund <assar@netbsd.org>
List: tech-net
Date: 07/27/2001 04:04:38
itojun@iijlab.net writes:
> 	yes, I saw it too.  curious to know what kind of command line argument
> 	you were using with mdnsd.  probably with -N (lookup by ping6)?

mdnsd -f -i wi0 <ip-addr>.  We should probably move discussion and
debugging of mdnsd to personal mail.

> 	hmm.  i'm preferring not to change timings for calling res_init(),
> 	as your change would call stat(2) every time we call gethostby*...
> 	maybe having some timer/time offset between stat(2) calls, so that
> 	we won't check it every time?

I don't really think this should be a performance problem.

> 	i guess it nicer if we can add "destination port number" argument,
> 	so that we can talk with multiple local instances of nameserver, like:
> 		nameserver 0.0.0.0 10053	# mdnsd
> 		nameserver 0.0.0.0 53		# normal named

Yes, I think this would be useful.  What about the appended patch?

/assar

Index: lib/libc/net/res_init.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/net/res_init.c,v
retrieving revision 1.36
diff -u -w -r1.36 res_init.c
--- lib/libc/net/res_init.c	2000/08/09 14:41:03	1.36
+++ lib/libc/net/res_init.c	2001/07/27 02:04:10
@@ -308,6 +321,7 @@
 		if (MATCH(buf, "nameserver") && nserv < MAXNS) {
 		    struct addrinfo hints, *res;
 		    char pbuf[NI_MAXSERV];
+		    char *port;
 		    char *q;
 #ifdef INET6
 		    const size_t minsiz = sizeof(_res_ext.nsaddr_list[0]);
@@ -322,17 +336,25 @@
 			continue;
 		    for (q = cp; *q; q++) {
 			if (isspace((u_char) *q)) {
-			    *q = '\0';
+			    *q++ = '\0';
 			    break;
 			}
 		    }
+		    while (*q == ' ' || *q == '\t')
+			q++;
+		    if (*q != '\0' && *q != '\n') {
+			port = q;
+		    } else {
+			snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT);
+			port = pbuf;
+		    }
+		    
 		    memset(&hints, 0, sizeof(hints));
 		    hints.ai_family = PF_UNSPEC;
 		    hints.ai_socktype = SOCK_DGRAM;
 		    hints.ai_flags = AI_NUMERICHOST;
-		    snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT);
 		    res = NULL;
-		    if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
+		    if (getaddrinfo(cp, port, &hints, &res) == 0 &&
 			minsiz >= res->ai_addrlen) {
 			memset(&_res.nsaddr_list[nserv], 0,
 			    sizeof(_res.nsaddr_list[nserv]));
Index: share/man/man5/resolv.conf.5
===================================================================
RCS file: /cvsroot/sharesrc/share/man/man5/resolv.conf.5,v
retrieving revision 1.17
diff -u -w -r1.17 resolv.conf.5
--- share/man/man5/resolv.conf.5	2000/08/09 14:41:07	1.17
+++ share/man/man5/resolv.conf.5	2001/07/27 02:04:10
@@ -70,6 +70,7 @@
 .Xr inet6 4
 for details
 .Pc .
+An optional port number might be included after the address.
 Up to
 .Dv MAXNS
 (currently 3) name servers may be listed,