Debian Codegraph @

upstream/debian-unstable/man3/gethostid.3

raw
1 '\" t
2 .\" Copyright 1993, Rickard E. Faith <[email protected]>
3 .\" Copyright 1993, Mitchum DSouza <[email protected]>
4 .\" Copyright, the authors of the Linux man-pages project
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH gethostid 3 2026-02-08 "Linux man-pages 6.18"
9 .SH NAME
10 gethostid, sethostid \- get or set the unique identifier of the current host
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <unistd.h>
17 .P
18 .B long gethostid(void);
19 .BI "int sethostid(long " hostid );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR gethostid ():
28 .nf
29 Since glibc 2.20:
30 _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
31 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
32 Up to and including glibc 2.19:
33 _BSD_SOURCE || _XOPEN_SOURCE >= 500
34 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
35 .fi
36 .P
37 .BR sethostid ():
38 .nf
39 Since glibc 2.21:
40 .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8
41 _DEFAULT_SOURCE
42 In glibc 2.19 and 2.20:
43 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
44 Up to and including glibc 2.19:
45 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
46 .fi
47 .SH DESCRIPTION
48 .BR gethostid ()
49 and
50 .BR sethostid ()
51 respectively get or set a unique 32-bit identifier for the current machine.
52 The 32-bit identifier was intended to be unique among all UNIX systems in
53 existence.
54 This normally resembles the Internet address for the local
55 machine, as returned by
56 .BR gethostbyname (3),
57 and thus usually never needs to be set.
58 .P
59 The
60 .BR sethostid ()
61 call is restricted to the superuser.
62 .SH RETURN VALUE
63 .BR gethostid ()
64 returns the 32-bit identifier for the current host as set by
65 .BR sethostid ().
66 .P
67 On success,
68 .BR sethostid ()
69 returns 0;
70 on error, \-1 is returned, and
71 .I errno
72 is set to indicate the error.
73 .SH ERRORS
74 .BR sethostid ()
75 can fail with the following errors:
76 .TP
77 .B EACCES
78 The caller did not have permission to write to the file used
79 to store the host ID.
80 .TP
81 .B EPERM
82 The calling process's effective user or group ID is not the same
83 as its corresponding real ID.
84 .SH ATTRIBUTES
85 For an explanation of the terms used in this section, see
86 .BR attributes (7).
87 .TS
88 allbox;
89 lb lb lbx
90 l l l.
91 Interface Attribute Value
92 T{
93 .na
94 .nh
95 .BR gethostid ()
96 T} Thread safety T{
97 .na
98 .nh
99 MT-Safe hostid env locale
100 T}
101 T{
102 .na
103 .nh
104 .BR sethostid ()
105 T} Thread safety T{
106 .na
107 .nh
108 MT-Unsafe const:hostid
109 T}
110 .TE
111 .SH VERSIONS
112 In the glibc implementation, the
113 .I hostid
114 is stored in the file
115 .IR /etc/hostid .
116 (Before glibc 2.2, the file
117 .I /var/adm/hostid
118 was used.)
119 .\" libc5 used /etc/hostid; libc4 didn't have these functions
120 .P
121 In the glibc implementation, if
122 .BR gethostid ()
123 cannot open the file containing the host ID,
124 then it obtains the hostname using
125 .BR gethostname (2),
126 passes that hostname to
127 .BR gethostbyname_r (3)
128 in order to obtain the host's IPv4 address,
129 and returns a value obtained by bit-twiddling the IPv4 address.
130 (This value may not be unique.)
131 .SH STANDARDS
132 .TP
133 .BR gethostid ()
134 POSIX.1-2008.
135 .TP
136 .BR sethostid ()
137 None.
138 .SH HISTORY
139 4.2BSD;
140 dropped in 4.4BSD.
141 SVr4 and POSIX.1-2001 include
142 .BR gethostid ()
143 but not
144 .BR sethostid ().
145 .SH BUGS
146 It is impossible to ensure that the identifier is globally unique.
147 .SH SEE ALSO
148 .BR hostid (1),
149 .BR gethostbyname (3)