Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 2533
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: rt-cpan [...] triv.org
Requestors: jand [...] ActiveState.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.34
Fixed in: (no value)



Subject: [PATCH] DHCP nameserver not found on Win2K server
On my Win2K Server box, Net::DNS::Resolver doesn't pick up the nameservers. The attached patch makes it look at the DhcpNameServer field in addition to just the NameServer field in the registry. This patch is probably only relevant for Win2K and WinXP.
--- .backup~/Resolver.pm~ Tue Feb 18 13:22:33 2003 +++ Resolver.pm Wed May 07 16:05:41 2003 @@ -248,6 +248,8 @@ my $type; $regiface->QueryValueEx("NameServer", $type, $ns); $nameservers .= " $ns" if $ns; + $regiface->QueryValueEx("DhcpNameServer", $type, $ns); + $nameservers .= " $ns" if $ns; } } }
From: jdb
[JDB - Wed May 7 19:24:46 2003]: Show quoted text
> On my Win2K Server box, Net::DNS::Resolver doesn't pick up the > nameservers. The attached patch makes it look at the > DhcpNameServer field in addition to just the NameServer field in > the registry. This patch is probably only relevant for Win2K and > WinXP.
From: jdb
[JDB - Wed May 7 19:24:46 2003]: Show quoted text
> On my Win2K Server box, Net::DNS::Resolver doesn't pick up the > nameservers. The attached patch makes it look at the > DhcpNameServer field in addition to just the NameServer field in > the registry. This patch is probably only relevant for Win2K and > WinXP.
[Sorry for the empty comment; RT was acting up on me.] Please don't apply the patch just yet; I'll try to enhance it to address the issues of bug #2465 (https://rt.cpan.org/NoAuth/Bug.html? id=2465) as well.
From: JDB
[JDB - Wed May 7 20:26:19 2003]: Show quoted text
> Please don't apply the patch just yet; I'll try to enhance it to > address the issues of bug #2465 (https://rt.cpan.org/NoAuth/Bug.html? > id=2465) as well.
Ok, the (attached) updated patch should solve bug #2465 and enable Net::DNS to find the nameservers on Windows 95/98/Me (later part is untested, but I did verify that SYSTEM\CurrentControlSet\Services\VxD\MSTCP exists and contains the relevant information on 95 and Me). This patch correctly decodes the DNSServerAddresses value of the DNSRegisteredAdapters key. It now also enumerates *all* interfaces, instead of just the ones that are also listed under DNSRegisteredAdapters. That change should fix bug @2465. This patch includes my earlier one.
--- Resolver.orig Tue Feb 18 13:22:33 2003 +++ Resolver.pm Wed May 07 18:22:54 2003 @@ -196,21 +196,14 @@ sub res_init_microsoft { my ($resobj, %keys); - - # This will *not* work on win95/98/ME...OTOH, who cares? - # Ok, so some do...simplest is probably to parse output - # of: (these are best guesses - no such systems to test on) - # (on 95) 'winipcfg /all /batch' - # (on 98 & ME) 'ipconfig /all /batch' - # There might be the required data resident under .../VxD/MSTCP in - # the registry on those machines but this is hearsay - # Actually, the trick of parsing 'ipconfig' could be applied - # to NT/W2K/XP too for some insulation... - - my $root = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'; - $main::HKEY_LOCAL_MACHINE->Open($root, $resobj) - or Carp::croak "can't read registry: $!"; + my $root = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'; + unless ($main::HKEY_LOCAL_MACHINE->Open($root, $resobj)) { + # Didn't work, maybe we are on 95/98/Me? + $root = 'SYSTEM\CurrentControlSet\Services\VxD\MSTCP'; + $main::HKEY_LOCAL_MACHINE->Open($root, $resobj) + or Carp::croak "can't read registry: $!"; + } $resobj->GetValues(\%keys) or Carp::croak "can't read registry values: $!"; @@ -234,12 +227,29 @@ # opt to silently fail if something isn't ok (maybe we're on NT4) # drop any duplicates later my $dnsadapters; - my $interfaces; $resobj->Open("DNSRegisteredAdapters", $dnsadapters); + if ($dnsadapters) { + my @adapters; + $dnsadapters->GetKeys(\@adapters); + foreach my $adapter (@adapters) { + my $regadapter; + $dnsadapters->Open($adapter, $regadapter); + if ($regadapter) { + my($type,$ns); + $regadapter->QueryValueEx("DNSServerAddresses", $type, $ns); + while (length($ns) >= 4) { + my $addr = join('.', unpack("C4", substr($ns,0,4,""))); + $nameservers .= " $addr"; + } + } + } + } + + my $interfaces; $resobj->Open("Interfaces", $interfaces); - if ($dnsadapters and $interfaces) { + if ($interfaces) { my @ifacelist; - $dnsadapters->GetKeys(\@ifacelist); + $interfaces->GetKeys(\@ifacelist); foreach my $iface (@ifacelist) { my $regiface; $interfaces->Open($iface, $regiface); @@ -247,6 +257,8 @@ my $ns; my $type; $regiface->QueryValueEx("NameServer", $type, $ns); + $nameservers .= " $ns" if $ns; + $regiface->QueryValueEx("DhcpNameServer", $type, $ns); $nameservers .= " $ns" if $ns; } }
[JDB - Wed May 7 21:35:13 2003]: Show quoted text
> Ok, the (attached) updated patch should solve bug #2465 and enable > Net::DNS to find the nameservers on Windows 95/98/Me (later part is > untested, but I did verify that > SYSTEM\CurrentControlSet\Services\VxD\MSTCP exists and contains the > relevant information on 95 and Me). > > This patch correctly decodes the DNSServerAddresses value of the > DNSRegisteredAdapters key. It now also enumerates *all* interfaces, > instead of just the ones that are also listed under > DNSRegisteredAdapters. That change should fix bug @2465. > > This patch includes my earlier one.
Thanks, applied. -- Chris Reinhardt ctriv@dyndns.org Systems Architect Dynamic DNS Network Services http://www.dyndns.org/