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?

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top