Friday, 27 September 2013

Iterate through the double linked list of ifaddr

Iterate through the double linked list of ifaddr

struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
struct ifaddrs *addrs,*tmp;
if(getifaddrs(&addrs) != 0) {
perror("getifaddrs");
return 1;
}
for(tmp = addrs; tmp ; tmp = tmp->ifa_next) {
}
I have seen this code of getifaddrs getting the results in ifaddrs. But
the Iteration
for loop is lopping through all the interfaces it can find.
for(tmp = addrs; tmp ; tmp = tmp->ifa_next) {
}
The question is I don't see how tmp->ifa_next pointer incremented or going
to the next link.

No comments:

Post a Comment