The following example shows how the names of all network interfaces can be retrieved using SIOCGIFCONF ioctl. Other ioctls can be used subsequently to retrieve more information like IP address, netmask etc for each interface.

/* ifacelist.c */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>

int get_iface_list(struct ifconf *ifconf)
{
   int sock, rval;

   sock = socket(AF_INET,SOCK_STREAM,0);
   if(sock < 0)
   {
     perror("socket");
     return (-1);
   }

   if((rval = ioctl(sock, SIOCGIFCONF , (char*) ifconf  )) < 0 )
     perror("ioctl(SIOGIFCONF)");

   close(sock);

   return rval;
}

int main()
{
   static struct ifreq ifreqs[20];
   struct ifconf ifconf;
   int  nifaces, i;

   memset(&ifconf,0,sizeof(ifconf));
   ifconf.ifc_buf = (char*) (ifreqs);
   ifconf.ifc_len = sizeof(ifreqs);

   if(get_iface_list(&ifconf) < 0) return -1;

   nifaces =  ifconf.ifc_len/sizeof(struct ifreq);

   printf("Interfaces (count = %d)\n", nifaces);
   for(i = 0; i < nifaces; i++)
   {
     printf("\t%-10s\n", ifreqs[i].ifr_name);
   }
}

Lets us run the above program.

[neo@techpulp ~]$ gcc ifacelist.c -o ifacelist
[neo@techpulp ~]$ ./ifacelist
Interfaces (count = 3):
        lo
        eth0
        eth1
[neo@techpulp ~]$