/* Compiling environment: Visual C ++ */# include <stdio. h >#include <winsock2.h> # pragma comment (Lib, "ws2_32.lib") int doit (INT, char **) {char host_name [255]; // obtain the local host name if (gethostname (host_name, sizeof (host_name) = socket_error) {printf ("error % d when getting local host name. \ n ", wsagetlasterror (); return 1;} printf (" host name is: % s \ n ", host_name ); // obtain the corresponding "host" struct hostent * Phe = gethostbyname (H Ost_name); If (PHE = 0) {printf ("yow! Bad host lookup. "); return 1;} // cyclically obtain all the IP addresses of the Local Machine for (INT I = 0; phe-> h_addr_list [I]! = 0; ++ I) {struct in_addr ADDR; memcpy (& ADDR, Phe-> h_addr_list [I], sizeof (struct in_addr); printf ("address % d: % s \ n ", I, inet_ntoa (ADDR);} return 0;} int main (INT argc, char * argv []) {wsadata; if (wsastartup (makeword (1, 1), & wsadata )! = 0) {return 255;} int retval = doit (argc, argv); wsacleanup (); Return retval ;}