Documentato l'uso di {{{SIOCGIFCONF}}} con tanto di programma di
[gapil.git] / sources / iflist.c
index 6020b5282b97f8f3e40918f3ee0f481797f9c4ce..371714f1684173be5816e024556d3a250558747f 100644 (file)
@@ -85,19 +85,21 @@ int main(int argc, char *argv[])
        printf("Wrong number of arguments %d\n", argc - optind);
         usage();
     }
-    iflist.ifc_len = sizeof(buffer);
-    iflist.ifc_buf = buffer;
-    
+    /* create a socket for the operation */
     sock = socket(PF_INET, SOCK_STREAM, 0);
     if (sock < 0) {
         perror("Socket creation error");
         return 1;
     }
+    /* init values for the ifcon structure and do SIOCGIFCONF */
+    iflist.ifc_len = sizeof(buffer);
+    iflist.ifc_buf = buffer;
     ret = ioctl(sock, SIOCGIFCONF, &iflist);
     if (ret < 0) {
        perror("ioctl failed");
         return 1;
     }
+    /* check that we have all data */
     if (iflist.ifc_len == sizeof(buffer)) {
        printf("Probable overflow, too many interfaces, cannot read\n");
        return 1;
@@ -105,6 +107,7 @@ int main(int argc, char *argv[])
        num = iflist.ifc_len/sizeof(struct ifreq);
        printf("Found %i interfaces \n", num);
     }
+    /* loop on interface to write data */
     for (i=0; i < num; i++) {
        address = (struct sockaddr_in *) &iflist.ifc_req[i].ifr_addr;
        printf("Interface %s, address %s\n", iflist.ifc_req[i].ifr_name,