gethostname 得到主机名
来源:互联网 发布:java dom解析xml 编辑:程序博客网 时间:2024/05/14 18:50
int gethostname(char *name, size_t len)
这个函数,调用后,会将主机名保存在name里面。而len是name的大小。
以下是例程,编译后只需要运行就知道自己的主机名字了。知道自己名字后,我再调用了一下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;
}
from http://blog.csdn.net/szwpc/article/details/518360
- 使用gethostname()得到主机名
- 使用gethostname()得到主机名
- gethostname 得到主机名
- 利用gethostname获取主机名
- 得到主机名
- gethostname
- gethostname
- 使用uname()得到主机名
- 根据IP得到主机名
- 关于Linux主机Hostname的设置!(gethostname得到localhost)
- 通过主机名得到IP地址
- java中得到主机名与IP,扫描局域网中的主机名
- C#得到MAC,IP,主机名 [原]
- gethostname()函数
- C#中如何得到主机名与IP地址
- 使用Sys(0)得到当前工作的主机名和用户名
- C#中如何得到主机名与IP地址
- C#中如何得到主机名与IP地址
- 人工智能:人类潜在的毁灭者吗
- 使用gethostbyaddr,通过ip地址,得到该ip地址的主机的信息
- [ javascript ] 关于jquey ajax请求导致文档加载问题!
- Weblogic的配置和在MyEclipse中的使用
- php中url传递中文字符,特殊危险字符的解决方法
- gethostname 得到主机名
- 硬盘寻址
- 三星下月发布智能手表Galaxy Gear
- 获取当前月份第一天的完整日期
- PHP mysql与mysqli事务使用说明 分享
- 给一个不多于5位的正整数,要求:求它是几位数并且逆序打印出各位数字。
- 网页制作中的一些注意事项,待续
- C# 操作数据库简介
- php与html的混合写法