X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Fiflist.c;h=3cdc0f3773eb81594f0cc2714d61650296b87525;hp=6020b5282b97f8f3e40918f3ee0f481797f9c4ce;hb=fa15a3f1ecd64efd8440e46d398fd9976abc3d25;hpb=20d2dafe03f5ab376e6f5a5e8168d7016ccb55aa diff --git a/sources/iflist.c b/sources/iflist.c index 6020b52..3cdc0f3 100644 --- a/sources/iflist.c +++ b/sources/iflist.c @@ -23,16 +23,15 @@ * Author: S. Piccardi Sep. 2006 * *****************************************************************************/ -#include -#include -#include /* C standard library */ -#include /* I/O standard library */ -#include -#include -#include -#include -#include -#include +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* C standard library */ +#include /* standard I/O library */ +#include /* unix standard library */ +#include /* socket constants, types and functions */ +#include /* IP addresses conversion utilities */ +#include /* ioctl syscall and constants */ +#include /* network interfaces constants and types */ /* * Program iflist @@ -85,19 +84,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 +106,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,