Possible Duplicate:
Get IP address of an interface on linux
I have code such as the following:
const char* interface = "10.123.123.123";
struct ip_mreq mc_req;
mc_req.imr_interface.s_addr = inet_addr(interface);
where interface is the inet address of the interface I want to use.
How can I refer to the interface by name instead?
For example, I want to write something like:
const char* interface = "eth0";
struct ip_mreq mc_req;
mc_req.imr_interface.s_addr = inet_addr(interface); // ???
But that doesn't work. Is there a function similar to inet_addr where I can lookup the inet address refering to "eth0"?