0

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"?

Community
  • 1
  • 1
Switch
  • 5,126
  • 12
  • 34
  • 40

1 Answers1

0

getifaddrs() will do the job.

alk
  • 69,737
  • 10
  • 105
  • 255