futex.2: Rework the description of FUTEX_LOCK_PI2
[man-pages.git] / man3 / gethostid.3
blob849a16b5a23e6f0f9d9d5322c736fa468c43ee2d
1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\"
3 .\" Updated with additions from Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
4 .\" Portions Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
5 .\"
6 .\" %%%LICENSE_START(VERBATIM)
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" %%%LICENSE_END
27 .\"
28 .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
29 .TH GETHOSTID 3 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 gethostid, sethostid \- get or set the unique identifier of the current host
32 .SH SYNOPSIS
33 .nf
34 .B #include <unistd.h>
35 .PP
36 .B long gethostid(void);
37 .BI "int sethostid(long " hostid );
38 .fi
39 .PP
40 .RS -4
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .RE
44 .PP
45 .BR gethostid ():
46 .nf
47     Since glibc 2.20:
48         _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
49 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
50     Up to and including glibc 2.19:
51         _BSD_SOURCE || _XOPEN_SOURCE >= 500
52 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
53 .fi
54 .PP
55 .BR sethostid ():
56 .nf
57     Since glibc 2.21:
58 .\"             commit 266865c0e7b79d4196e2cc393693463f03c90bd8
59         _DEFAULT_SOURCE
60     In glibc 2.19 and 2.20:
61         _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
62     Up to and including glibc 2.19:
63         _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
64 .fi
65 .SH DESCRIPTION
66 .BR gethostid ()
67 and
68 .BR sethostid ()
69 respectively get or set a unique 32-bit identifier for the current machine.
70 The 32-bit identifier was intended to be unique among all UNIX systems in
71 existence.
72 This normally resembles the Internet address for the local
73 machine, as returned by
74 .BR gethostbyname (3),
75 and thus usually never needs to be set.
76 .PP
77 The
78 .BR sethostid ()
79 call is restricted to the superuser.
80 .SH RETURN VALUE
81 .BR gethostid ()
82 returns the 32-bit identifier for the current host as set by
83 .BR sethostid ().
84 .PP
85 On success,
86 .BR sethostid ()
87 returns 0; on error, \-1 is returned, and
88 .I errno
89 is set to indicate the error.
90 .SH ERRORS
91 .BR sethostid ()
92 can fail with the following errors:
93 .TP
94 .B EACCES
95 The caller did not have permission to write to the file used
96 to store the host ID.
97 .TP
98 .B EPERM
99 The calling process's effective user or group ID is not the same
100 as its corresponding real ID.
101 .SH ATTRIBUTES
102 For an explanation of the terms used in this section, see
103 .BR attributes (7).
104 .ad l
107 allbox;
108 lb lb lbx
109 l l l.
110 Interface       Attribute       Value
112 .BR gethostid ()
113 T}      Thread safety   T{
114 MT-Safe hostid env locale
117 .BR sethostid ()
118 T}      Thread safety   T{
119 MT-Unsafe const:hostid
124 .sp 1
125 .SH CONFORMING TO
126 4.2BSD; these functions were dropped in 4.4BSD.
127 SVr4 includes
128 .BR gethostid ()
129 but not
130 .BR sethostid ().
132 POSIX.1-2001 and POSIX.1-2008 specify
133 .BR gethostid ()
134 but not
135 .BR sethostid ().
136 .SH NOTES
137 In the glibc implementation, the
138 .I hostid
139 is stored in the file
140 .IR /etc/hostid .
141 (In glibc versions before 2.2, the file
142 .I /var/adm/hostid
143 was used.)
144 .\" libc5 used /etc/hostid; libc4 didn't have these functions
146 In the glibc implementation, if
147 .BR gethostid ()
148 cannot open the file containing the host ID,
149 then it obtains the hostname using
150 .BR gethostname (2),
151 passes that hostname to
152 .BR gethostbyname_r (3)
153 in order to obtain the host's IPv4 address,
154 and returns a value obtained by bit-twiddling the IPv4 address.
155 (This value may not be unique.)
156 .SH BUGS
157 It is impossible to ensure that the identifier is globally unique.
158 .SH SEE ALSO
159 .BR hostid (1),
160 .BR gethostbyname (3)