I have used the program which is present in the following link http://www.linuxhowtos.org/manpages/3/getifaddrs.htm .
but it prints all the IP like loopback,eth0,eth1 lo etc
now I need to get only the ip which are active excpet loopback ip
ex
$iffconfig
eth6 Link encap:Ethernet HWaddr 08:00:27:47:99:da
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe47:99da/64 Scope:Link
as the ifconfig gives the active interface and correspoding IPs
what has to be changed in this code to get the above thing working ?
Change
with
and add this line just after the other includes
The added lines just check for “lo” interface name, contained into
ifa->ifa_name, and check the flags of the interfaces. Testing IFF_RUNNING bit ( look atnet/if.hfor further definitions) will return only running interfaces.If you want to check other feature of the interfaces, just check for this flags (taken from
net/if.h)EDIT
if you need to discriminate IPV6 GUA and ULA address use this macros
the parameter must be taken from
((sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;