]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/gethostid.3
brk.2, chdir.2, chmod.2, chown.2, chroot.2, getpagesize.2, getsid.2, killpg.2, mknod...
[thirdparty/man-pages.git] / man3 / gethostid.3
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 2015-08-08 "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 .B #include <unistd.h>
34 .sp
35 .B long gethostid(void);
36 .br
37 .BI "int sethostid(long " hostid );
38 .sp
39 .in -4n
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
42 .in
43 .sp
44 .ad l
45 .br
46 .BR gethostid ():
47 .RS 4
48 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
49 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
50 .RE
51 .BR sethostid ():
52 .nf
53 Since glibc 2.21:
54 .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8
55 _DEFAULT_SOURCE
56 In glibc 2.19 and 2.20:
57 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
58 Up to and including glibc 2.19:
59 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
60 .fi
61 .ad b
62 .SH DESCRIPTION
63 .BR gethostid ()
64 and
65 .BR sethostid ()
66 respectively get or set a unique 32-bit identifier for the current machine.
67 The 32-bit identifier is intended to be unique among all UNIX systems in
68 existence.
69 This normally resembles the Internet address for the local
70 machine, as returned by
71 .BR gethostbyname (3),
72 and thus usually never needs to be set.
73
74 The
75 .BR sethostid ()
76 call is restricted to the superuser.
77 .SH RETURN VALUE
78 .BR gethostid ()
79 returns the 32-bit identifier for the current host as set by
80 .BR sethostid ().
81
82 On success,
83 .BR sethostid ()
84 returns 0; on error, \-1 is returned, and
85 .I errno
86 is set to indicate the error.
87 .SH ERRORS
88 .BR sethostid ()
89 can fail with the following errors:
90 .TP
91 .B EACCES
92 The caller did not have permission to write to the file used
93 to store the host ID.
94 .TP
95 .B EPERM
96 The calling process's effective user or group ID is not the same
97 as its corresponding real ID.
98 .SH ATTRIBUTES
99 For an explanation of the terms used in this section, see
100 .BR attributes (7).
101 .TS
102 allbox;
103 lb lb lbw25
104 l l l.
105 Interface Attribute Value
106 T{
107 .BR gethostid ()
108 T} Thread safety MT-Safe hostid env locale
109 T{
110 .BR sethostid ()
111 T} Thread safety MT-Unsafe const:hostid
112 .TE
113
114 .SH CONFORMING TO
115 4.2BSD; these functions were dropped in 4.4BSD.
116 SVr4 includes
117 .BR gethostid ()
118 but not
119 .BR sethostid ().
120
121 POSIX.1-2001 and POSIX.1-2008 specify
122 .BR gethostid ()
123 but not
124 .BR sethostid ().
125 .SH NOTES
126 In the glibc implementation, the
127 .I hostid
128 is stored in the file
129 .IR /etc/hostid .
130 (In glibc versions before 2.2, the file
131 .I /var/adm/hostid
132 was used.)
133 .\" libc5 used /etc/hostid; libc4 didn't have these functions
134
135 In the glibc implementation, if
136 .BR gethostid ()
137 cannot open the file containing the host ID,
138 then it obtains the hostname using
139 .BR gethostname (2),
140 passes that hostname to
141 .BR gethostbyname_r (3)
142 in order to obtain the host's IPv4 address,
143 and returns a value obtained by bit-twiddling the IPv4 address.
144 (This value may not be unique.)
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)