1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
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>
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
8 .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
9 .TH gethostid 3 (date) "Linux man-pages (unreleased)"
11 gethostid, sethostid \- get or set the unique identifier of the current host
14 .RI ( libc ", " \-lc )
17 .B #include <unistd.h>
19 .B long gethostid(void);
20 .BI "int sethostid(long " hostid );
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
31 _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
32 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
33 Up to and including glibc 2.19:
34 _BSD_SOURCE || _XOPEN_SOURCE >= 500
35 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
41 .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8
43 In glibc 2.19 and 2.20:
44 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
45 Up to and including glibc 2.19:
46 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
52 respectively get or set a unique 32-bit identifier for the current machine.
53 The 32-bit identifier was intended to be unique among all UNIX systems in
55 This normally resembles the Internet address for the local
56 machine, as returned by
57 .BR gethostbyname (3),
58 and thus usually never needs to be set.
62 call is restricted to the superuser.
65 returns the 32-bit identifier for the current host as set by
70 returns 0; on error, \-1 is returned, and
72 is set to indicate the error.
75 can fail with the following errors:
78 The caller did not have permission to write to the file used
82 The calling process's effective user or group ID is not the same
83 as its corresponding real ID.
85 For an explanation of the terms used in this section, see
93 Interface Attribute Value
97 MT-Safe hostid env locale
102 MT-Unsafe const:hostid
109 4.2BSD; these functions were dropped in 4.4BSD.
115 POSIX.1-2001 and POSIX.1-2008 specify
120 In the glibc implementation, the
122 is stored in the file
124 (In glibc versions before 2.2, the file
127 .\" libc5 used /etc/hostid; libc4 didn't have these functions
129 In the glibc implementation, if
131 cannot open the file containing the host ID,
132 then it obtains the hostname using
134 passes that hostname to
135 .BR gethostbyname_r (3)
136 in order to obtain the host's IPv4 address,
137 and returns a value obtained by bit-twiddling the IPv4 address.
138 (This value may not be unique.)
140 It is impossible to ensure that the identifier is globally unique.
143 .BR gethostbyname (3)