Linux / C++: Get the IP Address of local computer
- by BlaM
This Question is almost the same as the previously asked Get the IP Address of local computer-Question. However I need to find the IP address(es) of a Linux Machine.
So: How do I - programmatically in C++ - detect the IP addresses of the linux server my application is running on. The servers will have at least two IP addresses and I need a specific one (the one in a given network (the public one)).
I'm sure there is a simple function to do that - but where?
[EDIT]
To make things a bit clearer:
The server will obviously have the "localhost": 127.0.0.1
The server will have an internal (management) IP address: 172.16.x.x
The server will have an external (public) IP address: 80.190.x.x
I need to find the external IP address to bind my application to it. Obviously I can also bind to INADDR_ANY (and actually that's what I do at the moment). I would prefer to detect the public address, though.