On Mon, Feb 22, 2010 at 06:16:02PM +0200, Aivar Jaakson wrote: > >Number: 6322 > >Category: system > >Synopsis: dig(1) uses always default DNS port 53 ... > >Description: > dig ignore -p port# option and send request to port 53
The port specified on the command line to dig and interactively to nslookup is being ignored. Patch below to -current, checked out on 2010-04-11 -- # grep nameserver /etc/resolv.conf nameserver [192.168.4.253]:5353 # echo "set port=5454 \nset all \n deepfreeze \n" | nslookup > > Default server: 192.168.4.253 Address: 192.168.4.253#5454 Set options: novc nodebug nod2 search recurse timeout = 0 retry = 3 port = 5454 querytype = A class = IN srchlist = foxall > Server: 192.168.4.253 Address: 192.168.4.253#5353 Name: deepfreeze.foxall Address: 192.168.2.253 > > # dig -p 5454 @192.168.4.253 deepfreeze.foxall ; <<>> DiG 9.4.2-P2 <<>> -p 5454 @192.168.4.253 deepfreeze.foxall ; (1 server found) ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27032 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ... ;; Query time: 3 msec ;; SERVER: 192.168.4.253#53(192.168.4.253) ;; WHEN: Tue Apr 20 11:13:08 2010 ;; MSG SIZE rcvd: 81 # -- Currently the global variable 'port' stores the port value read from the command line. It is initialised to 53. This value is not used when setting up to query the nameserver. Only the port read from resolv.conf is checked. This patch is an attempt to fix the problem by initialising the port global to zero so the value will indicate whether it has been set by the user. If the user specified a port, it uses that for the query, or if a value was configured in resolv.conf it uses that and if neither of those were set, it uses the default port. I am participating in the FOSS Development course at ANU and have made this contribution as part of that course. More information is available here http://cs.anu.edu.au/students/comp8440/ . dighost.c | 21 +++++++++++++++++---- nslookup.c | 9 +++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) Index: dighost.c =================================================================== RCS file: /cvs/src/usr.sbin/bind/bin/dig/dighost.c,v retrieving revision 1.12 diff -u dighost.c --- dighost.c 16 Aug 2009 13:17:44 -0000 1.12 +++ dighost.c 19 Apr 2010 13:48:19 -0000 @@ -118,7 +118,7 @@ showsearch = ISC_FALSE, qr = ISC_FALSE, is_dst_up = ISC_FALSE; -in_port_t port = 53; +in_port_t port = 0; unsigned int timeout = 0; unsigned int extrabytes; isc_mem_t *mctx = NULL; @@ -2191,7 +2191,14 @@ l = query->lookup; query->waiting_connect = ISC_TRUE; query->lookup->current_query = query; - servport = query->servport > 0 ? query->servport : NAMESERVER_PORT; + + if (port != 0) + servport = port; + else if (query->servport != 0) + servport = query->servport; + else + servport = NAMESERVER_PORT; + get_address(query->servname, servport, &query->sockaddr); if (specified_source && @@ -2266,8 +2273,14 @@ if (!query->recv_made) { /* XXX Check the sense of this, need assertion? */ query->waiting_connect = ISC_FALSE; - servport = query->servport > 0 ? - query->servport : NAMESERVER_PORT; + + if (port != 0) + servport = port; + else if (query->servport != 0) + servport = query->servport; + else + servport = NAMESERVER_PORT; + get_address(query->servname, servport, &query->sockaddr); result = isc_socket_create(socketmgr, Index: nslookup.c =================================================================== RCS file: /cvs/src/usr.sbin/bind/bin/dig/nslookup.c,v retrieving revision 1.10 diff -u nslookup.c --- nslookup.c 9 Dec 2007 13:39:42 -0000 1.10 +++ nslookup.c 19 Apr 2010 13:48:19 -0000 @@ -21,6 +21,8 @@ #include <stdlib.h> +#include <arpa/nameser.h> + #include <isc/app.h> #include <isc/buffer.h> #include <isc/commandline.h> @@ -441,13 +443,16 @@ dig_server_t *srv; isc_sockaddr_t sockaddr; dig_searchlist_t *listent; + in_port_t servport = 0; + servport = (port != 0) ? port : NAMESERVER_PORT; + srv = ISC_LIST_HEAD(server_list); while (srv != NULL) { char sockstr[ISC_SOCKADDR_FORMATSIZE]; - get_address(srv->servername, port, &sockaddr); + get_address(srv->servername, servport, &sockaddr); isc_sockaddr_format(&sockaddr, sockstr, sizeof(sockstr)); printf("Default server: %s\nAddress: %s\n", srv->userarg, sockstr); @@ -466,7 +471,7 @@ usesearch ? "search" : "nosearch", recurse ? "recurse" : "norecurse"); printf(" timeout = %d\t\tretry = %d\tport = %d\n", - timeout, tries, port); + timeout, tries, servport); printf(" querytype = %-8s\tclass = %s\n", deftype, defclass); printf(" srchlist = "); for (listent = ISC_LIST_HEAD(search_list);
