获得本机IP:struct hostent *h;char host[100];int i;gethostname(host, 100);if ((h = gethostbyname(host)) == NULL) {printf("Error : %s!n", hstrerror(h_errno));return;};printf("Default IP: %sn", inet_ntoa (*((struct in_addr *)h->h_addr)));for (i = 0; i< h->h_length / sizeof(int); i++) {printf("IP %d : %sn", i+1, inet_ntoa (*((struct in_addr *)h->h_addr_list[i])));};