Search code examples
cnetwork-programminggethostbyname

h_addr_list order


I want to understand in which order are the elements of h_addr_list sorted when I get the hostent from gethostbyname.

Basically, I'm working on a very old function that gets a hostent struct from gethostbyname, and returnes h_addr to the caller. I'm trying to figure out which address will be returned in case of multiple active interfaces.

Google and source-code browsing could not help me here. Is there documentation or some information on the order of h_addr_list?

P.S. I'm working on code for both Windows and Linux.


Solution

  • What makes you think that there is "an order" in the first place? What would make any particular address more worthy of being listed first?

    In other words, I don't think there is a well-defined order for the addresses. You simply get all the addresses that are available to the lookup system.