]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) |
2 | .\" | |
a093807e MK |
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 | .\" | |
93015253 | 6 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 15 | .\" |
fea681da MK |
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. | |
c13182ef | 23 | .\" |
fea681da MK |
24 | .\" Formatted or processed versions of this manual, if unaccompanied by |
25 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 26 | .\" %%%LICENSE_END |
fea681da | 27 | .\" |
fea681da | 28 | .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com> |
460495ca | 29 | .TH GETHOSTID 3 2015-08-08 "Linux" "Linux Programmer's Manual" |
fea681da MK |
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 ); | |
cc4615cc MK |
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 | |
2161c132 | 45 | .br |
ed8f1a27 | 46 | .BR gethostid (): |
2161c132 | 47 | .RS 4 |
98dbe7af MK |
48 | _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || |
49 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED | |
2161c132 | 50 | .RE |
cc4615cc | 51 | .BR sethostid (): |
2161c132 | 52 | .RS 4 |
cc4615cc | 53 | _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500) |
2161c132 | 54 | .RE |
cc4615cc | 55 | .ad b |
fea681da | 56 | .SH DESCRIPTION |
9caf8256 MK |
57 | .BR gethostid () |
58 | and | |
59 | .BR sethostid () | |
60 | respectively get or set a unique 32-bit identifier for the current machine. | |
008f1ecc | 61 | The 32-bit identifier is intended to be unique among all UNIX systems in |
c13182ef MK |
62 | existence. |
63 | This normally resembles the Internet address for the local | |
fea681da MK |
64 | machine, as returned by |
65 | .BR gethostbyname (3), | |
66 | and thus usually never needs to be set. | |
67 | ||
68 | The | |
e511ffb6 | 69 | .BR sethostid () |
fea681da | 70 | call is restricted to the superuser. |
47297adb | 71 | .SH RETURN VALUE |
e511ffb6 | 72 | .BR gethostid () |
fea681da | 73 | returns the 32-bit identifier for the current host as set by |
2777b1ca | 74 | .BR sethostid (). |
04826816 MK |
75 | |
76 | On success, | |
77 | .BR sethostid () | |
78 | returns 0; on error, \-1 is returned, and | |
79 | .I errno | |
80 | is set to indicate the error. | |
4c98d120 MK |
81 | .SH ERRORS |
82 | .BR sethostid () | |
83 | can fail with the following errors: | |
84 | .TP | |
85 | .B EACCES | |
86 | The caller did not have permission to write to the file used | |
87 | to store the host ID. | |
88 | .TP | |
89 | .B EPERM | |
90 | The calling process's effective user or group ID is not the same | |
91 | as its corresponding real ID. | |
406ff2be ZL |
92 | .SH ATTRIBUTES |
93 | For an explanation of the terms used in this section, see | |
94 | .BR attributes (7). | |
95 | .TS | |
96 | allbox; | |
97 | lb lb lbw25 | |
98 | l l l. | |
99 | Interface Attribute Value | |
100 | T{ | |
101 | .BR gethostid () | |
102 | T} Thread safety MT-Safe hostid env locale | |
103 | T{ | |
104 | .BR sethostid () | |
105 | T} Thread safety MT-Unsafe const:hostid | |
106 | .TE | |
107 | ||
47297adb | 108 | .SH CONFORMING TO |
97c1eac8 | 109 | 4.2BSD; these functions were dropped in 4.4BSD. |
c13182ef | 110 | SVr4 includes |
97c1eac8 MK |
111 | .BR gethostid () |
112 | but not | |
113 | .BR sethostid (). | |
32bb5d33 MK |
114 | |
115 | POSIX.1-2001 and POSIX.1-2008 specify | |
e511ffb6 | 116 | .BR gethostid () |
fea681da | 117 | but not |
e511ffb6 | 118 | .BR sethostid (). |
53a6b01d | 119 | .SH NOTES |
f9d5bb73 MK |
120 | In the glibc implementation, the |
121 | .I hostid | |
122 | is stored in the file | |
123 | .IR /etc/hostid . | |
124 | (In glibc versions before 2.2, the file | |
125 | .I /var/adm/hostid | |
126 | was used.) | |
127 | .\" libc5 used /etc/hostid; libc4 didn't have these functions | |
128 | ||
53a6b01d MK |
129 | In the glibc implementation, if |
130 | .BR gethostid () | |
f9d5bb73 | 131 | cannot open the file containing the host ID, |
ddaec46d | 132 | then it obtains the hostname using |
53a6b01d | 133 | .BR gethostname (2), |
ddaec46d | 134 | passes that hostname to |
3363301f | 135 | .BR gethostbyname_r (3) |
53a6b01d MK |
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.) | |
525748e0 MK |
139 | .SH BUGS |
140 | It is impossible to ensure that the identifier is globally unique. | |
47297adb | 141 | .SH SEE ALSO |
fea681da MK |
142 | .BR hostid (1), |
143 | .BR gethostbyname (3) |