0

getaddrinfo resolves google.com fine but when tries to resolve www.google.com (or any fqdn with more than two levels) it fails: "hostname nor servname provided, or not known".

When getaddrinfo tries to resolve www.google.com (for example), in the DNS server I see this query:

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: 3863 NXDomain 0/1/0 (105)

Any clue of what is going on? Thanks in advance.

Ernesto
  • 1
  • 1
  • 1
    done any debugging, like doing a manual lookup on the dns server using other tools, e.g. `nslookup www.google.com a.b.c.d`? Just because getaddrinfo fails doesn't mean it's that function's fault. you're using external resources. they can screw up too. – Marc B Nov 17 '14 at 14:08
  • 1
    did you check the return value? any hints? – Sourav Ghosh Nov 17 '14 at 14:08
  • When system functions fails, there's usually some reason behind the failure. To find out you have to check e.g. `errno` (or `WSAGetLastError` on Windows) to see what went wrong. Also search for and read a manual/reference page on the function to see what errors you can get. – Some programmer dude Nov 17 '14 at 14:12
  • ping www.google.com works fine. gai_strerror(rc) returns "hostname nor servname provided, or not known". My guess (but don't want to byass any answer) is that root is related on how getaddrinfo and nsswitch are interating (it sees www and then lookup in groups), but I have no clue why this is happening, nor how to fix it. More info: this applications works fine under Linux but I get this issue when running under BSD. – Ernesto Nov 17 '14 at 14:20

1 Answers1

0

There was an ugly an subtle bug in the code itself: getaddrinfo hints structure was wrongly populated. Fixing that the application behaves correctly.

Ernesto
  • 1
  • 1