Determine which of the addrinfo structures returned by getaddrinfo belongs to the current machine

StackOverflow https://stackoverflow.com/questions/11125921

Question

I call getaddrinfo. It returns a list of matching addresses. One of them belongs to the machine from which the call was made. How do I determine which one it is?

If there is no way to do so, is there anything else I can do to reliably and portably determine the IP address of a particular network interface on the current machine?

If there is no portable way, what is the Linux-specific way?

Était-ce utile?

La solution

Found a function that allows one to enumerate all the network interfaces and get information about them, including IP address. The function is getifaddrs, however note that it does not seem to be portable. Anyway, this solves my problem for now.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top