Welcome back, networkers !
Now, we are able to loop over all network interfaces within a shell script. How about we do it in C ? Let's make a first attempt using syscalls, shall we ? The alert reader already guessed that like all major things, there will be three parts (talking about major things, Google suggests me that there are three little pigs, stooges, musketeers. But Rs beat them all with 3 billion hits, what an ignorant fool I was, to not even know about RRR).
So, whenever it comes to system and kernel stuff, system calls are your friends, and thus we naturally turn to
ioctl and friends, in order to find out more about the network interfaces. A quick "
man ioctl" reveals that there is a manual page that knows them all ioctls. So, let's summon it right away by doing "
man ioctl_list". Now that you have it in front of your eyes in it's full glory, you will just trust me and use
SIOCGIFCONF to know about network interfaces. Because that manual page was rather obscure, wasn't it ?