Solved getaddrinfo not resolving FQDN with more than two levels

Hi,

In a hand-made application getaddrinfo resolves properly any FQDN with two level deep domain, e.g. google.com. But it fails to resolve host www.google.com, or deeper domains like google.co.uk.

gai_strerror(rc) gives
Code:
getaddrinfo error:  hostname nor servname provided, or not known
for FQDNs with more than two-levels deep (both IPv4 and IPv6).

Taking a look at what's going on in the network I see that for the erroneous case this is what I get:

Code:
07:14:35.038219 IP A.B.C.D.13162> W.X.Y.Z.53:3863+ A? group_compat.(30)
07:14:35.038558 IP W.X.Y.Z.53> A.B.C.D.13162:3863NXDomain0/1/0(105)

The query question goes for group_compat, which indicates some nsswitch stuff. Why is it querying that?

I'm running 10.0-RELEASE-p9 without any special modification. The same application runs in Linux but in FreeBSD (which apart from developing I usually use for debugging and catching subtle bugs that usually pass unnoticed) I get this error. In Linux I compile it with gcc and in FreeBSD with clang.

I have no clue where the problem is and any help would be very appreciated.

Thanks in advance and kind regards,
 
I assume you parameterize your call loosely, i.e. using defaults (which looks comfortable but actually is likely to create trouble). Kindly provide both call setup and the call.

Also check some DNS requests using host <any host>.
Reason: getaddrinfo doesn't do miracles; it's just an interface to the system name resolution and it might be helpful to check whether your systems name resolution works properly.
 
It was a very ugly bug in the code for raw sockets. Basically ai_socktype and ai_protocol were wrong.

Thanks and kind regards,
 
Back
Top