4 struct sockaddr_in * address;
6 /* create a socket for the operation */
7 sock = socket(PF_INET, SOCK_STREAM, 0);
9 perror("Socket creation error");
12 /* init values for the ifcon structure and do SIOCGIFCONF */
13 iflist.ifc_len = sizeof(buffer);
14 iflist.ifc_buf = buffer;
15 ret = ioctl(sock, SIOCGIFCONF, &iflist);
17 perror("ioctl failed");
20 /* check that we have all data */
21 if (iflist.ifc_len == sizeof(buffer)) {
22 printf("Probable overflow, too many interfaces, cannot read\n");
25 num = iflist.ifc_len/sizeof(struct ifreq);
26 printf("Found %i interfaces \n", num);
28 /* loop on interface to write data */
29 for (i=0; i < num; i++) {
30 address = (struct sockaddr_in *) &iflist.ifc_req[i].ifr_addr;
31 printf("Interface %s, address %s\n", iflist.ifc_req[i].ifr_name,
32 inet_ntoa(address->sin_addr));