I have an ip address 220.127.116.11 and there are two hostnames pointing to it.
From the command line
DNS.in-addr.arpa domain name pointer address1.test.com.
DNS.in-addr.arpa domain name pointer address2.test.com.
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?
std::string inputAddress = "18.104.22.168";
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);
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.