使用gethostname()得到主机名
来源:互联网 发布:pptv网络电视机 编辑:程序博客网 时间:2024/05/01 06:15
转自:http://hi.baidu.com/jakisou/blog/item/3e74d611b3573711b8127bd7.html
int gethostname(char *name, size_t len)
这个函数,调用后,会将主机名保存在name里面。而len是name的大小。
windows、linux系统下都适用。
以下是例程,编译后只需要运行就知道自己的主机名字了。知道自己名字后,我再调用了一下gethostbyname()来得到主机的一些其他信息。
#include <netdb.h>
#include <sys/socket.h>
int main(int argc, char **argv)
{
struct hostent *hptr;
char **pptr;
char hostname[32];
char str[32];
if( gethostname(hostname,sizeof(hostname)) )
{
printf("gethostname calling error/n");
return 1;
}
printf("localhost name:%s/n",hostname);
if( (hptr = gethostbyname(hostname)) == NULL)
{
printf("gethostbyname calling error/n");
return 1;
}
pptr=hptr->h_addr_list;
for(;*pptr!=NULL;pptr++)
printf(" address:%s/n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
return 0;
}
- 使用gethostname()得到主机名
- 使用gethostname()得到主机名
- gethostname 得到主机名
- 利用gethostname获取主机名
- 使用uname()得到主机名
- 得到主机名
- gethostname
- gethostname
- 使用Sys(0)得到当前工作的主机名和用户名
- 根据IP得到主机名
- 关于Linux主机Hostname的设置!(gethostname得到localhost)
- 通过主机名得到IP地址
- java中得到主机名与IP,扫描局域网中的主机名
- C#得到MAC,IP,主机名 [原]
- 使用gethostname()和gethostbyname()获取IP地址和计算机名
- 使用InetAddress类的getHostName方法获得域名
- 使用InetAddress类的getHostName方法获得域名
- UNIX环境编程--------编程实例-----Gethostname()函数使用
- C# Speech.Synthesis 语音朗读语调范例
- 条件 CHAIN 语句
- windows窗体高级控件
- 标题还没写完
- zigbee与其它近距离无线通信技术的比较
- 使用gethostname()得到主机名
- c#结构体
- WPF程序设计指南(Applications = Code + Markup)实例源码下载
- 单例(单态)模式(C++描述)
- QQ在线代码、MSN在线代码、Yahoo通在线代码、Skype在线代码
- MTK MCP FLASH 兼容设计思路
- 进程间通信方法
- mtk 黑屏重启问题&解决方法和 memorydump 获取
- pfx keystore 证书互换(转载)