문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top