]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) |
3 | .\" | |
a093807e MK |
4 | .\" Updated with additions from Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk> |
5 | .\" Portions Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk> | |
6 | .\" | |
5fbde956 | 7 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da | 8 | .\" |
fea681da | 9 | .\" Modified Tue Oct 22 00:22:35 EDT 1996 by Eric S. Raymond <esr@thyrsus.com> |
4c1c5274 | 10 | .TH gethostid 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
11 | .SH NAME |
12 | gethostid, sethostid \- get or set the unique identifier of the current host | |
42009080 AC |
13 | .SH LIBRARY |
14 | Standard C library | |
15 | .RI ( libc ", " \-lc ) | |
fea681da | 16 | .SH SYNOPSIS |
4653ec6e | 17 | .nf |
fea681da | 18 | .B #include <unistd.h> |
68e4db0a | 19 | .PP |
fea681da | 20 | .B long gethostid(void); |
fea681da | 21 | .BI "int sethostid(long " hostid ); |
4653ec6e | 22 | .fi |
68e4db0a | 23 | .PP |
d39ad78f | 24 | .RS -4 |
cc4615cc MK |
25 | Feature Test Macro Requirements for glibc (see |
26 | .BR feature_test_macros (7)): | |
d39ad78f | 27 | .RE |
68e4db0a | 28 | .PP |
ed8f1a27 | 29 | .BR gethostid (): |
49b843f5 MK |
30 | .nf |
31 | Since glibc 2.20: | |
5c10d2c5 MK |
32 | _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500 |
33 | .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED | |
49b843f5 | 34 | Up to and including glibc 2.19: |
5c10d2c5 MK |
35 | _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
36 | .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED | |
49b843f5 | 37 | .fi |
38c1dbe9 | 38 | .PP |
cc4615cc | 39 | .BR sethostid (): |
2c767761 | 40 | .nf |
d0544534 MK |
41 | Since glibc 2.21: |
42 | .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8 | |
43 | _DEFAULT_SOURCE | |
44 | In glibc 2.19 and 2.20: | |
5c10d2c5 | 45 | _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 46 | Up to and including glibc 2.19: |
5c10d2c5 | 47 | _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 48 | .fi |
fea681da | 49 | .SH DESCRIPTION |
9caf8256 MK |
50 | .BR gethostid () |
51 | and | |
52 | .BR sethostid () | |
53 | respectively get or set a unique 32-bit identifier for the current machine. | |
fb033b1e | 54 | The 32-bit identifier was intended to be unique among all UNIX systems in |
c13182ef MK |
55 | existence. |
56 | This normally resembles the Internet address for the local | |
fea681da MK |
57 | machine, as returned by |
58 | .BR gethostbyname (3), | |
59 | and thus usually never needs to be set. | |
847e0d88 | 60 | .PP |
fea681da | 61 | The |
e511ffb6 | 62 | .BR sethostid () |
fea681da | 63 | call is restricted to the superuser. |
47297adb | 64 | .SH RETURN VALUE |
e511ffb6 | 65 | .BR gethostid () |
fea681da | 66 | returns the 32-bit identifier for the current host as set by |
2777b1ca | 67 | .BR sethostid (). |
847e0d88 | 68 | .PP |
04826816 MK |
69 | On success, |
70 | .BR sethostid () | |
71 | returns 0; on error, \-1 is returned, and | |
72 | .I errno | |
73 | is set to indicate the error. | |
4c98d120 MK |
74 | .SH ERRORS |
75 | .BR sethostid () | |
76 | can fail with the following errors: | |
77 | .TP | |
78 | .B EACCES | |
79 | The caller did not have permission to write to the file used | |
80 | to store the host ID. | |
81 | .TP | |
82 | .B EPERM | |
83 | The calling process's effective user or group ID is not the same | |
84 | as its corresponding real ID. | |
406ff2be ZL |
85 | .SH ATTRIBUTES |
86 | For an explanation of the terms used in this section, see | |
87 | .BR attributes (7). | |
88 | .TS | |
89 | allbox; | |
b32feea5 | 90 | lb lb lbx |
406ff2be ZL |
91 | l l l. |
92 | Interface Attribute Value | |
93 | T{ | |
9e54434e BR |
94 | .na |
95 | .nh | |
406ff2be | 96 | .BR gethostid () |
b32feea5 | 97 | T} Thread safety T{ |
9e54434e BR |
98 | .na |
99 | .nh | |
b32feea5 MK |
100 | MT-Safe hostid env locale |
101 | T} | |
406ff2be | 102 | T{ |
9e54434e BR |
103 | .na |
104 | .nh | |
406ff2be | 105 | .BR sethostid () |
b32feea5 | 106 | T} Thread safety T{ |
9e54434e BR |
107 | .na |
108 | .nh | |
b32feea5 MK |
109 | MT-Unsafe const:hostid |
110 | T} | |
406ff2be | 111 | .TE |
847e0d88 | 112 | .sp 1 |
4131356c | 113 | .SH VERSIONS |
f9d5bb73 MK |
114 | In the glibc implementation, the |
115 | .I hostid | |
116 | is stored in the file | |
117 | .IR /etc/hostid . | |
b324e17d | 118 | (Before glibc 2.2, the file |
f9d5bb73 MK |
119 | .I /var/adm/hostid |
120 | was used.) | |
121 | .\" libc5 used /etc/hostid; libc4 didn't have these functions | |
847e0d88 | 122 | .PP |
53a6b01d MK |
123 | In the glibc implementation, if |
124 | .BR gethostid () | |
f9d5bb73 | 125 | cannot open the file containing the host ID, |
ddaec46d | 126 | then it obtains the hostname using |
53a6b01d | 127 | .BR gethostname (2), |
ddaec46d | 128 | passes that hostname to |
3363301f | 129 | .BR gethostbyname_r (3) |
53a6b01d MK |
130 | in order to obtain the host's IPv4 address, |
131 | and returns a value obtained by bit-twiddling the IPv4 address. | |
132 | (This value may not be unique.) | |
4131356c AC |
133 | .SH STANDARDS |
134 | .TP | |
135 | .BR gethostid () | |
136 | POSIX.1-2008. | |
137 | .TP | |
138 | .BR sethostid () | |
139 | None. | |
140 | .SH HISTORY | |
141 | 4.2BSD; dropped in 4.4BSD. | |
142 | SVr4 and POSIX.1-2001 include | |
143 | .BR gethostid () | |
144 | but not | |
145 | .BR sethostid (). | |
525748e0 MK |
146 | .SH BUGS |
147 | It is impossible to ensure that the identifier is globally unique. | |
47297adb | 148 | .SH SEE ALSO |
fea681da MK |
149 | .BR hostid (1), |
150 | .BR gethostbyname (3) |