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 .\" %%%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.
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.
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
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
29 .TH GETHOSTID 3 2017-09-15 "Linux" "Linux Programmer's Manual"
31 gethostid, sethostid \- get or set the unique identifier of the current host
34 .B #include <unistd.h>
36 .B long gethostid(void);
37 .BI "int sethostid(long " hostid );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
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
58 .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8
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)
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
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.
79 call is restricted to the superuser.
82 returns the 32-bit identifier for the current host as set by
87 returns 0; on error, \-1 is returned, and
89 is set to indicate the error.
92 can fail with the following errors:
95 The caller did not have permission to write to the file used
99 The calling process's effective user or group ID is not the same
100 as its corresponding real ID.
102 For an explanation of the terms used in this section, see
110 Interface Attribute Value
114 MT-Safe hostid env locale
119 MT-Unsafe const:hostid
126 4.2BSD; these functions were dropped in 4.4BSD.
132 POSIX.1-2001 and POSIX.1-2008 specify
137 In the glibc implementation, the
139 is stored in the file
141 (In glibc versions before 2.2, the file
144 .\" libc5 used /etc/hostid; libc4 didn't have these functions
146 In the glibc implementation, if
148 cannot open the file containing the host ID,
149 then it obtains the hostname using
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.)
157 It is impossible to ensure that the identifier is globally unique.
160 .BR gethostbyname (3)