cloonacool
cloonacool

Reputation: 37

getnameinfo() can it be used to return multiple hostnames for a single IP address

I have an ip address 5.5.5.5 and there are two hostnames pointing to it.

From the command line

host 5.5.5.5

DNS.in-addr.arpa domain name pointer address1.test.com.

DNS.in-addr.arpa domain name pointer address2.test.com.

nslookup 5.5.5.5

Server: dns.test.com

Address: dns.test.com

Non-authoritative answer:

DNS.in-addr.arpa name = address1.test.com.

DNS.in-addr.arpa name = address2.test.com.

I am trying to implent this type functionality in c/c++. When I use getnameinfo() it only returns address1.test.com or address2.test.com.

My question is there away to get both of these DNS names in one call? how does nslookup and host do this?

Code :

    char host[1024];
    std::string inputAddress = "5.5.5.5";
    struct sockaddr_in socketAddress;
    socketAddress.sin_family = AF_INET;
    inet_pton(AF_INET, inputAddress.c_str(), &(socketAddress.sin_addr));
    getnameinfo((struct sockaddr *)&socketAddress, sizeof(socketAddress), host, 1024, NULL, NULL, 0);
    printf("host=%s \n", host);

Upvotes: 2

Views: 1496

Answers (1)

user149341
user149341

Reputation:

No. The getnameinfo() interface can only return a single name — it has no way of returning multiple results. Its behavior is undefined when multiple PTR records are returned; in practice, most implementations will probably use the first one they see.

Keep in mind that there should only be one PTR record (and, thus, one canonical hostname) for any given IP. While it is possible for more than one A/AAAA name to resolve to a single IP, only one of those names should ever appear in a PTR record.

Upvotes: 4

Related Questions