Alex Rivera | Logout

Get IP address of an interface on Linux

Asked 2010-02-17T18:52:01.880
78

How can I get the IPv4 address of an interface on Linux from C code?

For example, I'd like to get the IP address (if any) assigned to eth0.

Edit
Report

1 Answer

50

In addition to the ioctl() method Filip demonstrated you can use getifaddrs(). There is an example program at the bottom of the man page.

answered 2010-02-17T20:43:29.227

Your Answer