获取主机名,IP

//get hostname
char hostname[20];
gethostname(hostname,20);

//get ipv4 address.
hostent *pHost=::gethostbyname(hostname);
in_addr addr;
char *p=pHost->h_addr_list[0];
memcpy(&addr.S_un.S_addr,p,pHost->h_length);
CString v4IP=::inet_ntoa(addr); 

你可能感兴趣的:(list)