]>
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 | .\" | |
5fbde956 | 6 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da | 7 | .\" |
fea681da | 8 | .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com> |
ab47278f | 9 | .TH GETHOSTID 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
10 | .SH NAME |
11 | gethostid, sethostid \- get or set the unique identifier of the current host | |
42009080 AC |
12 | .SH LIBRARY |
13 | Standard C library | |
14 | .RI ( libc ", " \-lc ) | |
fea681da | 15 | .SH SYNOPSIS |
4653ec6e | 16 | .nf |
fea681da | 17 | .B #include <unistd.h> |
68e4db0a | 18 | .PP |
fea681da | 19 | .B long gethostid(void); |
fea681da | 20 | .BI "int sethostid(long " hostid ); |
4653ec6e | 21 | .fi |
68e4db0a | 22 | .PP |
d39ad78f | 23 | .RS -4 |
cc4615cc MK |
24 | Feature Test Macro Requirements for glibc (see |
25 | .BR feature_test_macros (7)): | |
d39ad78f | 26 | .RE |
68e4db0a | 27 | .PP |
ed8f1a27 | 28 | .BR gethostid (): |
49b843f5 MK |
29 | .nf |
30 | Since glibc 2.20: | |
5c10d2c5 MK |
31 | _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500 |
32 | .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED | |
49b843f5 | 33 | Up to and including glibc 2.19: |
5c10d2c5 MK |
34 | _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
35 | .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED | |
49b843f5 | 36 | .fi |
38c1dbe9 | 37 | .PP |
cc4615cc | 38 | .BR sethostid (): |
2c767761 | 39 | .nf |
d0544534 MK |
40 | Since glibc 2.21: |
41 | .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8 | |
42 | _DEFAULT_SOURCE | |
43 | In glibc 2.19 and 2.20: | |
5c10d2c5 | 44 | _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 45 | Up to and including glibc 2.19: |
5c10d2c5 | 46 | _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 47 | .fi |
fea681da | 48 | .SH DESCRIPTION |
9caf8256 MK |
49 | .BR gethostid () |
50 | and | |
51 | .BR sethostid () | |
52 | respectively get or set a unique 32-bit identifier for the current machine. | |
fb033b1e | 53 | The 32-bit identifier was intended to be unique among all UNIX systems in |
c13182ef MK |
54 | existence. |
55 | This normally resembles the Internet address for the local | |
fea681da MK |
56 | machine, as returned by |
57 | .BR gethostbyname (3), | |
58 | and thus usually never needs to be set. | |
847e0d88 | 59 | .PP |
fea681da | 60 | The |
e511ffb6 | 61 | .BR sethostid () |
fea681da | 62 | call is restricted to the superuser. |
47297adb | 63 | .SH RETURN VALUE |
e511ffb6 | 64 | .BR gethostid () |
fea681da | 65 | returns the 32-bit identifier for the current host as set by |
2777b1ca | 66 | .BR sethostid (). |
847e0d88 | 67 | .PP |
04826816 MK |
68 | On success, |
69 | .BR sethostid () | |
70 | returns 0; on error, \-1 is returned, and | |
71 | .I errno | |
72 | is set to indicate the error. | |
4c98d120 MK |
73 | .SH ERRORS |
74 | .BR sethostid () | |
75 | can fail with the following errors: | |
76 | .TP | |
77 | .B EACCES | |
78 | The caller did not have permission to write to the file used | |
79 | to store the host ID. | |
80 | .TP | |
81 | .B EPERM | |
82 | The calling process's effective user or group ID is not the same | |
83 | as its corresponding real ID. | |
406ff2be ZL |
84 | .SH ATTRIBUTES |
85 | For an explanation of the terms used in this section, see | |
86 | .BR attributes (7). | |
c466875e MK |
87 | .ad l |
88 | .nh | |
406ff2be ZL |
89 | .TS |
90 | allbox; | |
b32feea5 | 91 | lb lb lbx |
406ff2be ZL |
92 | l l l. |
93 | Interface Attribute Value | |
94 | T{ | |
95 | .BR gethostid () | |
b32feea5 MK |
96 | T} Thread safety T{ |
97 | MT-Safe hostid env locale | |
98 | T} | |
406ff2be ZL |
99 | T{ |
100 | .BR sethostid () | |
b32feea5 MK |
101 | T} Thread safety T{ |
102 | MT-Unsafe const:hostid | |
103 | T} | |
406ff2be | 104 | .TE |
c466875e MK |
105 | .hy |
106 | .ad | |
847e0d88 | 107 | .sp 1 |
3113c7f3 | 108 | .SH STANDARDS |
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 (). | |
847e0d88 | 114 | .PP |
32bb5d33 | 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 | |
847e0d88 | 128 | .PP |
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) |