Reputation: 41
I want to get the list of aliases for a hostname in C++. This input is a IP. Currently we call gethostbyaddr()
, which returns a hostent struct. This struct has a field for list of aliases.
struct hostent {
char FAR * h_name; /* official name of host */
char FAR * FAR * h_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */
char FAR * FAR * h_addr_list; /* list of addresses */
};
gethostbyaddr() API is legacy, and also we wanted to support IPv6 inputs. So we replaced gethostbyaddr() with getnameinfo()
as recommended in msdn. But after this changes, there is no way to get the list of aliases for a hostname. getnameinfo() simply returns the hostname as a string, and there is no alias list returned by it. Can somebody help me to get the alias list in this case?
Upvotes: 4
Views: 1273
Reputation: 5651
I don't think that's possible. The DNS stores:
So you can query the addresses associated to a name (getaddrinfo
), or the canonical name associated to an address (getaddrinfo
), but there's no way to query the set of names that map to a given address.
Upvotes: 1