#include#include #include #include #include #include #include #include #include #include int main(int argc, char **argv){ int i = 0; int sockfd = -1; struct ifconf ifconf; unsigned char buf[512]; struct ifreq *ifreq; ifconf.ifc_len = 512; ifconf.ifc_buf = buf; if((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) return 2; ioctl(sockfd, SIOCGIFCONF, &ifconf); ifreq = (struct ifreq *)buf; for(i = ifconf.ifc_len/sizeof(struct ifreq); i> 0; i--) { printf("name=%s, addr=%s\n", ifreq->ifr_name, inet_ntoa(((struct sockaddr_in *)&(ifreq->ifr_addr))->sin_addr)); ifreq++; } return 0;}