char hostname[256];
int iRet = 0;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,1),&wsaData)) //调用Windows Sockets DLL
{
printf("Winsock无法初始化!\n");
WSACleanup();
return 0;
}
memset(hostname, 0, 256);
iRet = gethostname(hostname, sizeof(hostname));
if(iRet != 0 )
{
printf( "get hostname error:%d\n", iRet);
}
printf("%s\n", hostname);