Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostname to IPv6 address fails on Windows - Unknown host #304

Closed
dschultzca opened this issue Jun 10, 2021 · 29 comments
Closed

hostname to IPv6 address fails on Windows - Unknown host #304

dschultzca opened this issue Jun 10, 2021 · 29 comments

Comments

@dschultzca
Copy link

I'm using net-snmp on Windows Server 2008 R2 and I can not get net-snmp utilities to work when the DNS response for a hostname is an IPv6 address.

To confirm DNS I can ping, for example:

C:\>ping -n 1 myipv6host.mycompany.com
Pinging myipv6host.mycompany.com [fd80:fd80:6:400:c:291f:2ba:a2fb] with 32 bytes of data:
Reply from fd80:fd80:6:400:c:291f:2ba:a2fb: time<1ms
Ping statistics for fd80:fd80:6:400:c:291f:2ba:a2fb:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

If I try using the hostname in the snmp command I get a "Unknown host" response. These are the command variations I've tried:

C:\>snmpget -v2c -cpublic myipv6host.mycompany.com DISMAN-EXPRESSION-MIB::sysUpTimeInstance
snmpget: Unknown host (myipv6host.mycompany.com) (No such file or directory)

C:\>snmpget -v2c -cpublic udp6:myipv6host.mycompany.com DISMAN-EXPRESSION-MIB::sysUpTimeInstance
snmpget: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

C:\>snmpget -v2c -cpublic udp6:[myipv6host.mycompany.com] DISMAN-EXPRESSION-MIB::sysUpTimeInstance
snmpget: Unknown host (udp6:[myipv6host.mycompany.com]) (No such file or directory)

C:\>snmpget -v2c -cpublic udp6:[fd80:fd80:6:400:c:291f:2ba:a2fb] DISMAN-EXPRESSION-MIB::sysUpTimeInstance
DISMAN-EXPRESSION-MIB::sysUpTimeInstance = Timeticks: (318228102) 36 days, 19:58:01.02

As you can see the use of the IPv6 address directly works as expected.

If I add -DALL I can see attempts to resolve the name but they appear to be IPv4 related unless I use the form udp6:myipv6host.mycompany.com.

trace:  ..\..\snmplib\snmp_transport.c, 511:
tdomain: tdomain_transport_full("snmp", "udp6:myipv6host.mycompany.com", 0, "udp", "[NIL]")
trace:  ..\..\snmplib\snmp_transport.c, 463:
tdomain: Found domain "udp6" from specifier "udp6"
trace:  ..\..\snmplib\snmp_service.c, 388:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace:  ..\..\snmplib\snmp_transport.c, 634:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace:  ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 109:
netsnmp_sockaddr_in6: addr 0018F878, peername "myipv6host.mycompany.com", default_target ":161"
trace:  ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 109:
netsnmp_sockaddr_in6: addr 0018F878, peername ":161", default_target "[NIL]"
trace:  ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 277:
netsnmp_sockaddr_in6: hostname(?) with port suffix :161
trace:  ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 300:
netsnmp_sockaddr_in6: empty hostname
trace:  ..\..\snmplib\system.c, 889:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace:  ..\..\snmplib\system.c, 912:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace:  ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 348:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace:  ..\..\snmplib\snmp_api.c, 1563:
_sess_open: couldn't interpret peername
snmpget: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

This seems to apply to any pre-compiled binary I've found for net-snmp version 5.5+.
Running net-snmp commands on a CentOS7 installation works as expected with or without the udp6: qualifier in front of the hostname.

Any help resolving this would be greatly appreciated.
Thanks

@bvanassche
Copy link
Contributor

If this has not yet been tested with Net-SNMP v5.9.1, please retest with that version.

@dschultzca
Copy link
Author

Sure I can do that. Where can I get the Windows binaries for that version?

@bvanassche
Copy link
Contributor

Please build Windows binaries from the Net-SNMP source code. Instructions are available in https://github.com/net-snmp/net-snmp/blob/master/README.win32. The build status is available at https://ci.appveyor.com/project/BVanAssche87257/net-snmp/history.

@dschultzca
Copy link
Author

I'm attempting to build on a Windows 7 - 64bit system and following the readme for ' Microsoft Visual Studio - Configure / nmake - Building'.
I have VS Community 2019 installed, I clone the repo from Github and I launch a Developer command window from within the IDE.
I run "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 to setup the environment and then launch the build script win32\build.bat.
It errors out on the first item to compile.

Net-SNMP build and install options
==================================

1.  OpenSSL support:                disabled
2.  OpenSSL include directory:      C:\OpenSSL-Win64\include
3.  OpenSSL library director:       C:\OpenSSL-Win64\lib\VC
4.  Platform SDK support:           enabled

5.  Install path:                   c:/usr
6.  Install after build:            disabled

7.  Perl modules:                   disabled
8.  Install perl modules:           disabled

9.  Quiet build (logged):           enabled
10. Debug mode:                     disabled

11. IPv6 transports (requires SDK): enabled
12. winExtDLL agent (requires SDK): disabled

13. Link type:                      dynamic

14. Install development files       disabled

F.  Finished - start build
Q.  Quit - abort build

Select option to set / toggle: f

Building...

Creating *.out log files.

Deleting old log files...
Running Configure...
Cleaning...
Building main package...
Build error (see make.out) at build.pl line 199, <> line 5.

Here is the make.out file.

	cd libagent
	nmake /nologo all
	cl.exe /I.. /I..\..\include /I..\..\agent\mibgroup /D NETSNMP_REMOVE_U64 /D VC_EXTRALEAN /D WIN32 /D _CONSOLE /D _CRT_NONSTDC_NO_WARNINGS /D _CRT_SECURE_NO_WARNINGS /D _MBCS /D _WIN32_WINNT=0xffff /D _WINSOCK_DEPRECATED_NO_WARNINGS /D WIN32_LEAN_AND_MEAN /EHsc /FD /FR.\release\ /Fd.\release\libagent.pdb /Fo.\release\ /I C:OpenSSL-Win64include  -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86/build=/usr/src/debug/perl-5.26.3-2 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86/src/perl-5.26.3=/usr/src/debug/perl-5.26.3-2 -fwrapv -fno-strict-aliasing  -I/usr/lib/perl5/5.26/i686-cygwin-threads-64int/CORE  /c /W3 /Zi /nologo /MD  /D NDEBUG /O2 ..\..\agent\agent_handler.c ..\..\agent\agent_index.c ..\..\agent\agent_read_config.c ..\..\agent\agent_registry.c ..\..\agent\agent_sysORTable.c ..\..\agent\agent_trap.c ..\..\agent\kernel.c ..\..\agent\snmp_agent.c ..\..\agent\snmp_vars.c 
cl : Command line error D8021 : invalid numeric argument '/Werror=format-security'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\cl.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x86\nmake.EXE"' : return code '0x2'
Stop.

What am I missing?

@bvanassche
Copy link
Contributor

bvanassche commented Jun 14, 2021

That message may indicate a bug. If the following helps, I will prepare a proper patch:

diff --git a/win32/Configure b/win32/Configure
index b73370ce3a07..7ed8ca2970c7 100755
--- a/win32/Configure
+++ b/win32/Configure
@@ -214,7 +214,6 @@ my %makefile_subs = (
                                "/Fd\$(INTDIR)\\\$(PROGNAME).pdb " .
                                "/Fo\$(INTDIR)\\ " .
                                "$perl_inc " .
-                               "$perl_cflags " .
                                "/c " .
                                "/W3 " .
                                "/Zi " .

@dschultzca
Copy link
Author

Removing that line allowed me to complete the build.

@dschultzca
Copy link
Author

Compiling from the source from this repo I have: NET-SNMP version: 5.10
Even with this version I experience the same DNS hostname resolution failure.

Using: C:\>snmpget -DALL -v2c -cpublic udp6:myipv6host.mycompany.com DISMAN-EXPRESSION-MIB::sysUpTimeInstance
results in:

... 
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 654:
tdomain: tdomain_transport_spec("snmp", "udp6:myipv6host.mycompany.com", 0, "udp,udp6", "[NIL]", "[NIL]")
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 0032F428, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 933:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 956:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpget: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

How do we proceed from here?

@bvanassche
Copy link
Contributor

Please retest with the latest version of the master branch. Multiple changes have been checked in, including the following change: 6024a9e

@dschultzca
Copy link
Author

When running win32/build.bat the numeric toggle options are offset by one. If I wish to toggle 'install after build' is have to select 6, to enable IPv6 I have to select 11. I think this is because the SDK option was removed.

@bvanassche
Copy link
Contributor

That's correct, the SDK option has been removed by the following commit: bbbf866. Is the renumbering of the options causing any issues?

@dschultzca
Copy link
Author

dschultzca commented Jun 17, 2021

Yes it would seem so. Now to toggle an option you need to use the displayed number +1.

@dschultzca
Copy link
Author

I built using master ec3cf02.
Testing with this command: snmpstatus -DALL -v2c -cpublic myipv6host.mycompany.com
It still fails to resolve to the IPv6 address (and we don't use IPv4).

trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 737:
tdomain: Use user specified default domain "udp,udp6"
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp" from specifier "udp"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in3(): ..\..\snmplib\transports\snmpIPv4BaseDomain.c, 98:
netsnmp_sockaddr_in: addr 004CF65C, inpeername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_getaddrinfo(): ..\..\snmplib\system.c, 894:
dns:getaddrinfo: looking up "myipv6host.mycompany.com" with hint ({ ... })
trace: netsnmp_sockaddr_in3(): ..\..\snmplib\transports\snmpIPv4BaseDomain.c, 132:
netsnmp_sockaddr_in: couldn't resolve hostname "myipv6host.mycompany.com"
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 004CF638, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 975:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 998:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpstatus: Unknown host (myipv6host.mycompany.com) (No such file or directory)

bvanassche added a commit to bvanassche/net-snmp that referenced this issue Jun 17, 2021
This patch changes the minimum requirement for snmpd.exe built with MSVC
to Windows 8.1 / Windows Server 2003. See also
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo.

See also net-snmp#304.
bvanassche added a commit to bvanassche/net-snmp that referenced this issue Jun 17, 2021
This patch changes the minimum requirement for snmpd.exe built with MSVC
to Windows 8.1 / Windows Server 2003. See also
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo.

See also net-snmp#304 .
@bvanassche
Copy link
Contributor

Please retest with the latest version of the master branch. Fixes for build.bat and also for IPv6 have been checked in.

@dschultzca
Copy link
Author

dschultzca commented Jun 17, 2021

I built from 9e5370d , just noticed that snmpstatus doesn't exist.

@dschultzca
Copy link
Author

Sorry my mistake. I was in the wrong directory ...

I built from 9e5370d but it still doesn't work.

trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 737:
tdomain: Use user specified default domain "udp,udp6"
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp" from specifier "udp"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in3(): ..\..\snmplib\transports\snmpIPv4BaseDomain.c, 98:
netsnmp_sockaddr_in: addr 0053F624, inpeername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_getaddrinfo(): ..\..\snmplib\system.c, 852:
dns:getaddrinfo: looking up "myipv6host.mycompany.com" with hint ({ ... })
trace: netsnmp_sockaddr_in3(): ..\..\snmplib\transports\snmpIPv4BaseDomain.c, 132:
netsnmp_sockaddr_in: couldn't resolve hostname "myipv6host.mycompany.com"
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 0053F600, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 933:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 956:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpstatus: Unknown host (myipv6host.mycompany.com) (No such file or directory)

I'm building on Win7 and testing on Server 2008, could that be an issue?

Also, even testing against localhost doesn't resolve the IPv6 address.

@bvanassche
Copy link
Contributor

Building on Windows 7 and testing on Windows Server 2008 should be fine.

I see netsnmp_gethostbyname() in the above output. That function shouldn't be used anymore by netsnmp_resolve_v6_hostname() because of the following change in win32/net-snmp/net-snmp-config.h:

 /* Define to 1 if you have the `getaddrinfo' function. */
-/* #undef HAVE_GETADDRINFO */
+#define HAVE_GETADDRINFO 1

Please double check that commit 18ff188 is present in your local copy of the Net-SNMP git repository.

@dschultzca
Copy link
Author

Yes it is.
image

@bvanassche
Copy link
Contributor

Just noticed that netsnmp_getaddrinfo() is present in the above output so we are making progress :-)

Is an IPv6 address associated with the host name myipv6host.mycompany.com in the DNS server contacted by Net-SNMP? I'm asking this because I can't resolve that address via https://lookup.icann.org/lookup ...

@dschultzca
Copy link
Author

It's a private network with its own DNS. You can see the result of the DNS lookup in my first post where I ping the hostname which resolves to an IPv6 address.

@bvanassche
Copy link
Contributor

I think that the following output shows that getaddrinfo() has not been called:

tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 0053F600, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 933:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 956:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com

However, it should have been called. The "failed to parse" message shows that netsnmp_resolve_v6_hostname() has been called. netsnmp_resolve_v6_hostname() calls netsnmp_getaddrinfo() if the HAVE_GETADDRINFO has been defined and has a numerical value != 0.

@dschultzca
Copy link
Author

Are you expecting line

hp = gethostbyname(name);
to provide the result?
Do you need me to do another test?

@dschultzca
Copy link
Author

I think that it's hitting this lookup function.

"hostname (couldn't resolve)\n"));
as HAVE_GETHOSTBYNAME is also !=0
and we are not seeing this message
DEBUGMSGTL(("netsnmp_sockaddr_in6", "Failed to resolve IPv6 hostname\n"));

@bvanassche
Copy link
Contributor

bvanassche commented Jun 18, 2021

If both getaddrinfo() and gethostbyname() are available, getaddrinfo() should be called. The screenshot shows that HAVE_GETADDRINFO == 1 but the logs show that gethostbyname() is called. I'm not sure what's going on.

@dschultzca
Copy link
Author

I don't know if this provides any additional info or not, built from commit bd292ce.

tdomain: tdomain_transport_spec("snmp", "udp6:myipv6host.mycompany.com", 0, "udp,udp6", "[NIL]", "[NIL]")
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 003AF828, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 961:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 984:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpstatus: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

bdolez pushed a commit to zenetys/net-snmp that referenced this issue Jun 21, 2021
This patch changes the minimum requirement for snmpd.exe built with MSVC
to Windows 8.1 / Windows Server 2003. See also
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo.

See also net-snmp#304 .
@bvanassche
Copy link
Contributor

The above output shows again that netsnmp_resolve_v6_hostname() calls netsnmp_gethostbyname() instead of netsnmp_getaddrinfo(). Would it be possible to run snmpstatus inside a debugger and analyze why this happens?

@bvanassche
Copy link
Contributor

If I build the master branch myself on Windows with MSVC or MinGW64, the following output appears:

c:\usr\bin\snmpstatus -DALL -v2c -cpublic udp6:myipv6host.mycompany.com
[ ... ]
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 654:
tdomain: tdomain_transport_spec("snmp", "udp6:myipv6host.mycompany.com", 0, "udp,udp6", "[NIL]", "[NIL]")
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 000000467C4FF400, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_getaddrinfo(): ..\..\snmplib\system.c, 852:
dns:getaddrinfo: looking up "myipv6host.mycompany.com" with hints ({.ai_flags = 0, .ai_family = AF_INET6})
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpstatus: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

As one can see, getaddrinfo() is called.

@dschultzca
Copy link
Author

Would it be possible to run snmpstatus inside a debugger and analyze why this happens?

I'd be willing to try, although I will need some assistance setting that up and guidance on the debugging steps.

Over the past few days I installed the MSYS2/Mingw-w64 software and created a build with it. I had some problems while running ./configure, it consumed all my system memory when configuring. I had to power cycle my computer after the configuration step as the system would not restart normally. I was able to repeat this on two systems, two times each. Both systems are Win7 64-bit. After running configure, power cycling and the running make, the result is no different. This output is from my build using i686-w64-mingw32.

trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 654:
tdomain: tdomain_transport_spec("snmp", "udp6:myipv6host.mycompany.com", 0, "udp,udp6", "[NIL]", "[NIL]")
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 002EF774, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 961:
dns:gethostbyname: looking up myipv6host.mycompany.com
trace: netsnmp_gethostbyname(): ..\..\snmplib\system.c, 984:
dns:gethostbyname: couldn't resolve myipv6host.mycompany.com
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 230:
netsnmp_sockaddr_in6: hostname (couldn't resolve)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 316:
netsnmp_sockaddr_in6: failed to parse myipv6host.mycompany.com
trace: _sess_open(): ..\..\snmplib\snmp_api.c, 1672:
_sess_open: couldn't interpret peername
snmpstatus: Unknown host (udp6:myipv6host.mycompany.com) (No such file or directory)

Would you expect different results if I were to compile for x86_64-w64-mingw32?
I'd also be willing to running your compiled program to see if the lookup result functions correctly.

@dschultzca
Copy link
Author

Success !
I started from scratch. Reset my MSVC environment, deleted my local repo and cloned 1410430. This time I did not open MSCV, Rather I opened the 'x64 Native Tools Command Prompt for VS 2019' window directly. Changed to the net-snmp directory and ran win32\build.bat. Set my options:

Net-SNMP build and install options
==================================

1.  OpenSSL support:                disabled
2.  OpenSSL include directory:      C:\Progra~1\OpenSSL-Win64\include
3.  OpenSSL library director:       C:\Progra~1\OpenSSL-Win64\lib\VC

4.  Install path:                   c:/usr
5.  Install after build:            disabled

6.  Perl modules:                   disabled
7.  Install perl modules:           disabled

8.  Quiet build (logged):           enabled
9.  Debug mode:                     disabled

10. IPv6 transports:                enabled
11. winExtDLL agent:                disabled

12. Link type:                      static

13. Install development files       disabled

F.  Finished - start build
Q.  Quit - abort build

Select option to set / toggle: f

The result was a x64 build that works.

trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 654:
tdomain: tdomain_transport_spec("snmp", "udp6:myipv6host.mycompany.com", 0, "udp,udp6", "[NIL]", "[NIL]")
trace: find_tdomain(): ..\..\snmplib\snmp_transport.c, 600:
tdomain: Found domain "udp6" from specifier "udp6"
trace: netsnmp_lookup_default_target(): ..\..\snmplib\snmp_service.c, 417:
defaults: netsnmp_lookup_default_target("snmp", "udp6") -> ":161"
trace: netsnmp_tdomain_transport_tspec(): ..\..\snmplib\snmp_transport.c, 792:
tdomain: trying domain "udp6" address "myipv6host.mycompany.com" default address ":161"
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 279:
netsnmp_sockaddr_in6: ep 000000000014F2E0, peername "myipv6host.mycompany.com", default_target ":161"
trace: netsnmp_getaddrinfo(): ..\..\snmplib\system.c, 852:
dns:getaddrinfo: looking up "myipv6host.mycompany.com" with hints ({.ai_flags = 0, .ai_family = AF_INET6})
trace: netsnmp_getaddrinfo(): ..\..\snmplib\system.c, 939:
dns:getaddrinfo: answer { AF_INET6, fd80:fd80:6:400:c:291f:2ba:a2fb:0 }
trace: netsnmp_resolve_v6_hostname(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 204:
netsnmp_sockaddr_in6: hostname (resolved okay)
trace: netsnmp_sockaddr_in6_3(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 324:
netsnmp_sockaddr_in6: return { AF_INET6, [fd80:fd80:6:400:c:291f:2ba:a2fb%0]:161 }
trace: netsnmp_ipv6_fmtaddr(): ..\..\snmplib\transports\snmpIPv6BaseDomain.c, 114:
netsnmp_ipv6: fmtaddr: t = 0000000000000000, data = 000000000014F2E0, len = 28
trace: netsnmp_udp6_transport_init(): ..\..\snmplib\transports\snmpUDPIPv6Domain.c, 224:
netsnmp_udp6: open remote UDP/IPv6: [fd80:fd80:6:400:c:291f:2ba:a2fb]:161
trace: netsnmp_udp6_transport_socket(): ..\..\snmplib\transports\snmpUDPIPv6Domain.c, 334:
UDPBase: opened socket 300 as local=0
[UDP/IPv6: [fd80:fd80:6:400:c:291f:2ba:a2fb]:161]=>[Linux myipv6host 3.10.0-862.3.3.el7.x86_64 #1 SMP Fri Jun 15 04:15:27 UTC 2018 x86_64] Up: 49 days, 21:40:57.72
Interfaces: 8, Recv/Trans packets: -1376100016/1318299023 | IP: 20037164/20567769

Next I'd like to build with link = dynamic and with the other modules enabled to replace the current 5.7 x86 version I have installed.

@bvanassche
Copy link
Contributor

That's great news! Thanks for the update.

fenner pushed a commit to fenner/net-snmp that referenced this issue Jun 30, 2021
This patch changes the minimum requirement for snmpd.exe built with MSVC
to Windows XP / Windows Server 2003. See also
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo .

See also net-snmp#304 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants