1GETHOSTID(3)               Linux Programmer's Manual              GETHOSTID(3)
2
3
4

NAME

6       gethostid,  sethostid - get or set the unique identifier of the current
7       host
8

SYNOPSIS

10       #include <unistd.h>
11
12       long gethostid(void);
13       int sethostid(long hostid);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       gethostid():
18           Since glibc 2.20:
19               _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
20           Up to and including glibc 2.19:
21               _BSD_SOURCE || _XOPEN_SOURCE >= 500
22
23       sethostid():
24           Since glibc 2.21:
25               _DEFAULT_SOURCE
26           In glibc 2.19 and 2.20:
27               _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
28           Up to and including glibc 2.19:
29               _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
30

DESCRIPTION

32       gethostid() and sethostid() respectively get or  set  a  unique  32-bit
33       identifier for the current machine.  The 32-bit identifier was intended
34       to be unique among all UNIX systems in existence.  This normally resem‐
35       bles  the  Internet address for the local machine, as returned by geth‐
36       ostbyname(3), and thus usually never needs to be set.
37
38       The sethostid() call is restricted to the superuser.
39

RETURN VALUE

41       gethostid() returns the 32-bit identifier for the current host  as  set
42       by sethostid().
43
44       On  success, sethostid() returns 0; on error, -1 is returned, and errno
45       is set to indicate the error.
46

ERRORS

48       sethostid() can fail with the following errors:
49
50       EACCES The caller did not have permission to write to the file used  to
51              store the host ID.
52
53       EPERM  The calling process's effective user or group ID is not the same
54              as its corresponding real ID.
55

ATTRIBUTES

57       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
58       tributes(7).
59
60       ┌────────────┬───────────────┬─────────────────────────────────────────┐
61Interface   Attribute     Value                                   
62       ├────────────┼───────────────┼─────────────────────────────────────────┤
63gethostid() │ Thread safety │ MT-Safe hostid env locale               │
64       ├────────────┼───────────────┼─────────────────────────────────────────┤
65sethostid() │ Thread safety │ MT-Unsafe const:hostid                  │
66       └────────────┴───────────────┴─────────────────────────────────────────┘
67

CONFORMING TO

69       4.2BSD;  these  functions  were dropped in 4.4BSD.  SVr4 includes geth‐
70       ostid() but not sethostid().
71
72       POSIX.1-2001 and POSIX.1-2008 specify gethostid() but not sethostid().
73

NOTES

75       In  the  glibc  implementation,  the  hostid  is  stored  in  the  file
76       /etc/hostid.   (In  glibc versions before 2.2, the file /var/adm/hostid
77       was used.)
78
79       In the glibc implementation, if gethostid() cannot open the  file  con‐
80       taining the host ID, then it obtains the hostname using gethostname(2),
81       passes that hostname to  gethostbyname_r(3)  in  order  to  obtain  the
82       host's  IPv4 address, and returns a value obtained by bit-twiddling the
83       IPv4 address.  (This value may not be unique.)
84

BUGS

86       It is impossible to ensure that the identifier is globally unique.
87

SEE ALSO

89       hostid(1), gethostbyname(3)
90

COLOPHON

92       This page is part of release 5.12 of the Linux  man-pages  project.   A
93       description  of  the project, information about reporting bugs, and the
94       latest    version    of    this    page,    can     be     found     at
95       https://www.kernel.org/doc/man-pages/.
96
97
98
99Linux                             2021-03-22                      GETHOSTID(3)
Impressum