Simple question on ip address monitoring
Brett Ciphery
brett.ciphery at windriver.com
Fri Jun 15 11:32:47 EDT 2012
[Simple question on ip address monitoring] On 15/06/2012 (Fri 10:05) Manthei, Mark wrote:
> I have a simple use case but I still haven't found how to accomplish this:
>
> I want to loop through all known interface cards and collect information.
> I have figured out how to get basic info (interface name, MAC address) but I am unable to get the IP address.
>
> I thought the following would obtain the IP but appears to get the MAC address:
>
> // now do ip address stuff with address cache
> struct rtnl_link *pAddrLink = rtnl_link_get( pLinkCache, idx );
> if(pAddrLink)
> {
> addr = rtnl_link_get_addr(pAddrLink);
> int addressguess = nl_addr_guess_family(addr);
> std::cout << "addr2 guess: " << addressguess << std::endl;
>
>
>
> nl_addr2str( addr, buf, 128 );
> std::cout << " ipaddress: " << buf << std::endl;
> }
>
>
> Is there an example I'm missing that might shed some light on how to accomplish this?
You could refer to the src/nl-addr-list.c program -- the function you'll
need to make use of is rtnl_addr_get_local().
Perhaps allocate/populate an addr cache, set a filter on the ifindex
matching the interface you're interested in, and then use
nl_cache_foreach_filter to loop over the IP addresses of the interface.
Brett
More information about the libnl
mailing list