3

My C++ application has to lookup a DNS SRV record pointing to an IPv6 address. From what I researched so far, the res_search() family of functions is the way to go.

Does anyone have an example how to prepare such a query and how to extract the IPv6 result ?

Gene Vincent
  • 5,237
  • 9
  • 50
  • 86

1 Answers1

7

res_search() (or req_query) is probably the way to go to obtain the initial SRV record.

However the SRV record can only contain a hostname, not a literal IPv6 address.

You should feed the hostname contents of that record into the getaddrinfo() function which can then look up both IPv4 and IPv6 addresses at the same time.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • 1
    +1 - `SRV` records include a resource name. It is the user's responsibility to resolve the name to an IP address or whatever using additional queries (e.g., `A` or `AAAA`) or other system calls. – D.Shawley Oct 18 '11 at 13:32
  • @D.Shawley: Although, I believe its possible for the DNS server to push the lookup as an extra record in the results. – Zan Lynx Oct 18 '11 at 14:35
  • @ZanLynx It's possible, but certainly not required. – Alnitak Oct 18 '11 at 14:45
  • @Alnitak: Right. But its worth looking for the record in the DNS response before making a new request. – Zan Lynx Oct 18 '11 at 15:09
  • 1
    @ZanLynx no, not really, IMHO. The original answer might only include an `A` record even though both `A` and `AAAA` exist. – Alnitak Oct 18 '11 at 15:44
  • @Alnitak: And it might contain a `AAAA` record too. Why not? – Zan Lynx Oct 18 '11 at 16:32
  • @ZanLynx that's my point - until you've explicitly asked you don't actually know for certain. Extra information supplied by the recursive resolve in the _Additional Section_ should not be relied on, and may be incomplete. – Alnitak Oct 18 '11 at 16:40