gethostname 环境 -》错
#include "stdafx.h" #include<winsock2.h> #include <stdio.h> #pragma comment(lib, "ws2_32.lib") char m_sznode[32+1] = {0}; int GetComputerName(char *lpBuffer, unsigned long* lpnSize) { if (gethostname(lpBuffer, *lpnSize) != -1) { *lpnSize = strlen(lpBuffer); } return 0; } int _tmain(int argc, _TCHAR* argv[]) { unsigned long ncomputerlong = sizeof(m_sznode)-1; GetComputerName(m_sznode,&ncomputerlong); printf("%s",m_sznode); system("PAUSE"); return 0; }
浙公网安备 33010602011771号