Volviendo a un artículo anterior donde hallábamos la dirección IP de un dispositivo, he decidido extender un poco la funcionalidad para poder hallar más información acerca de un dispositivo de red.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <sys/types.h> #include <sys/ioctl.h> #include <net/if.h> #include <string.h> #define get_addr(var) (*(struct in_addr *) &var.ifr_addr.sa_data[2]) int getdevinfo(char * ifname) { int sock; struct ifreq ifr; sock=socket(AF_INET, SOCK_DGRAM, 0); if (sock<0) return -1; /* No puedo crear el socket */ ifr. |
Últimos comentarios