`utsname`的字段`nodename`和`gesostname()`的`name`指向的输出字符串有什么区别?

问题描述 投票:-1回答:1

来自APUE

#include <sys/utsname.h>
int uname(struct utsname *name);

哪里

struct utsname {
char  sysname[]; /* name of the operating system */
char  nodename[]; /* name of this node */
char  release[]; /* current release of operating system */
char  version[]; /* current version of this release */
char  machine[]; /* name of hardware type */
};

此功能来自System V,在较旧的日子里,nodename元素足以引用UUCP网络上的主机。

BSD派生的系统提供了gethostname函数,仅返回主机的名称。如果主机连接到TCP / IP网络,则主机名通常是主机的完全限定域名。

#include <unistd.h>
int gethostname(char *name, int namelen);

我想知道utsname的场nodenamenamegethostname()指出的输出字符串之间有什么区别?

谢谢。

c linux hostname
1个回答
1
投票

既然你标记了这个,我假设我们专门讨论Linux。

Linux手册项目的man 2 gethostname说:

GNU C库不使用gethostname()系统调用;相反,它将gethostname()实现为一个库函数,它调用uname(2)并将返回的nodename字段中的len个字节复制到name中。

因此,在Linux上,两者都是由同一系统调用提供的,并没有区别。

© www.soinside.com 2019 - 2024. All rights reserved.