gethostname() in windows
gethostname() in windows
我发现gethostname()函数返回本地计算机的标准主机名,但我对术语"主机名"有点困惑,它是调用该函数的计算机的名称还是计算机在网络中连接的服务器的名称…
char szPath[128] = "";
gethostname(szPath, sizeof(szPath));
如果我想找出本地主机的ip地址,我应该怎么做…
gethostname:返回本地计算机名。
获取IP地址,使用:
struct hostent *ent = gethostbyname(hostname);
struct in_addr ip_addr = *(struct in_addr *)(ent->h_addr);
printf("Hostname: %s, was resolved to: %sn",
hostname, inet_ntoa(ip_addr));
来自文档:
gethostname
函数检索本地计算机的标准主机名。
相关文章:
- std::async from std::async in windows xp
- 如何在 google test in windows 中管理断言
- 在Windows Visual Studio中实现<netinet/in.h>
- C++ - 程序接收信号SIGSEGV,分段错误.In msvcrt!memcpy () (C:\Windows\S
- 使用 new in C++(在 Windows 上)分配大于 2GB 的单个对象
- pthread_cond_timedwait() in Windows
- TLS with http_listener in Microsoft cpprestsdk on Windows
- Windows 10 环境中的"This version of XAudio2 is available only in Windows 8"错误
- QT c++ "Windows.h no such a file or dictionary in main.ccp"
- QB,如何在Windows上配置.h.in文件
- No FileIO in Windows Phone?
- 包含 Windows.h 和 wingdi.h 时出现"GradientFill was not declared in this scope"错误
- COM in the non-Windows world?
- OLEUnInitialize() in windows 7
- Sleep() in Windows 消息循环
- 未解析的包含:<stdio.h> in Eclipse helios(Windows 7 64bit)
- Performance Windows Socket in C++ with Matlab
- Cython in Windows 64 with GSL
- Handling Multiple windows in Symbian using Qt
- 如何可靠地检测 Mac OS X、iOS、Linux、Windows in C 预处理器