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           _BSD_SOURCE || _XOPEN_SOURCE >= 500
19       sethostid():
20           Since glibc 2.21:
21               _DEFAULT_SOURCE
22           In glibc 2.19 and 2.20:
23               _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
24           Up to and including glibc 2.19:
25               _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
26

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

CONFORMING TO

65       4.2BSD;  these  functions  were dropped in 4.4BSD.  SVr4 includes geth‐
66       ostid() but not sethostid().
67
68       POSIX.1-2001 and POSIX.1-2008 specify gethostid() but not sethostid().
69

NOTES

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

BUGS

82       It is impossible to ensure that the identifier is globally unique.
83

SEE ALSO

85       hostid(1), gethostbyname(3)
86

COLOPHON

88       This page is part of release 4.16 of the Linux  man-pages  project.   A
89       description  of  the project, information about reporting bugs, and the
90       latest    version    of    this    page,    can     be     found     at
91       https://www.kernel.org/doc/man-pages/.
92
93
94
95Linux                             2017-09-15                      GETHOSTID(3)
Impressum