1GETHOSTID(3) Linux Programmer's Manual GETHOSTID(3)
2
3
4
6 gethostid, sethostid - get or set the unique identifier of the current
7 host
8
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 _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
19 _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
20 sethostid():
21 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
22
24 gethostid() and sethostid() respectively get or set a unique 32-bit
25 identifier for the current machine. The 32-bit identifier is intended
26 to be unique among all UNIX systems in existence. This normally resem‐
27 bles the Internet address for the local machine, as returned by geth‐
28 ostbyname(3), and thus usually never needs to be set.
29
30 The sethostid() call is restricted to the superuser.
31
33 gethostid() returns the 32-bit identifier for the current host as set
34 by sethostid().
35
36 On success, sethostid() returns 0; on error, -1 is returned, and errno
37 is set to indicate the error.
38
40 sethostid() can fail with the following errors:
41
42 EACCES The caller did not have permission to write to the file used to
43 store the host ID.
44
45 EPERM The calling process's effective user or group ID is not the same
46 as its corresponding real ID.
47
49 4.2BSD; these functions were dropped in 4.4BSD. SVr4 includes geth‐
50 ostid() but not sethostid(). POSIX.1-2001 specifies gethostid() but
51 not sethostid().
52
54 In the glibc implementation, the hostid is stored in the file
55 /etc/hostid. (In glibc versions before 2.2, the file /var/adm/hostid
56 was used.)
57
58 In the glibc implementation, if gethostid() cannot open the file con‐
59 taining the host ID, then it obtains the hostname using gethostname(2),
60 passes that hostname to gethostbyname_r(3) in order to obtain the
61 host's IPv4 address, and returns a value obtained by bit-twiddling the
62 IPv4 address. (This value may not be unique.)
63
65 It is impossible to ensure that the identifier is globally unique.
66
68 hostid(1), gethostbyname(3)
69
71 This page is part of release 3.53 of the Linux man-pages project. A
72 description of the project, and information about reporting bugs, can
73 be found at http://www.kernel.org/doc/man-pages/.
74
75
76
77Linux 2010-09-20 GETHOSTID(3)