#include <winsock2.h>
#pragma comment(lib,"WS2_32.lib")
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData;
if (WSAStartup(wVersionRequested, &wsaData)) {
MessageBox("WSAStartup failed %s/n"/*, WSAGetLastError()*/);
}
//
// 获得主机名.
//
char hostname[256];
int res = gethostname(hostname, sizeof(hostname));
if (res != 0) {
MessageBox("GetHostName Error: %u/n"/*, WSAGetLastError()*/);
}
//printf("hostname=%s/n", hostname);
// 根据主机名获取主机信息.
//
hostent* pHostent = gethostbyname(hostname);
if (pHostent==NULL) {
MessageBox("GetHostByName Error: %u/n"/*, WSAGetLastError()*/);
}