使用uname()得到主机名
来源:互联网 发布:数据库的类型包括 编辑:程序博客网 时间:2024/06/10 16:29
以下是例程。编译后只需要调用就可以了。程序很简单,看一下就知道uname()如何使用了。其中,涉及到一个utsname的结构。先解释一下:
struct utsname{
char sysname[_UTS_NAMESIZE]; /* name of this operating system */
char nodename[_UTS_NODESIZE]; /* name of this node */
char release[_UTS_NAMESIZE]; /* O.S release level */
char version[_UTS_NAMESIZE]; /* O.S version level */
char machine[_UTS_NAMESIZE]; /* hardware type */
};
#include <sys/utsname.h>
#include <netdb.h>
#include <sys/socket.h>
int main(int argc, char **argv)
{
struct hostent *hptr;
struct utsname myname;
char **pptr;
char str[32];
if(uname(&myname)<0)
{
printf("uname calling error/n");
return 1;
}
printf("localhost name:%s/n",myname.nodename);
if( (hptr = gethostbyname(myname.nodename)) == 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;
}
- 使用uname()得到主机名
- 使用gethostname()得到主机名
- 使用gethostname()得到主机名
- 得到主机名
- 使用Sys(0)得到当前工作的主机名和用户名
- 根据IP得到主机名
- gethostname 得到主机名
- uname命令的使用
- uname
- uname
- uname
- uname
- uname()
- uname
- Uname
- uname
- uname
- uname
- 如何在MSN Space 中添加Windows Media Player 播放模块
- ofs其他地方无法访问数据库
- C/C++中的日期和时间
- 使用gethostbyaddr,通过ip地址,得到该ip地址的主机的信息
- 使用gethostname()得到主机名
- 使用uname()得到主机名
- HiveMind初探
- IDF
- 共享bolg
- 新的开始,面临巨大挑战的我该如何来学习呢?-新手的开始一
- 剖析人民币升值问题
- c++资源之不完全导引(全文)
- asp调用存储过程
- 如何定时运行ASP文件