]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/gethostid.3
dist.mk, All pages: .TH: Generate date at 'make dist'
[thirdparty/man-pages.git] / man3 / gethostid.3
CommitLineData
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
11gethostid, sethostid \- get or set the unique identifier of the current host
42009080
AC
12.SH LIBRARY
13Standard 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
24Feature 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 ()
50and
51.BR sethostid ()
52respectively get or set a unique 32-bit identifier for the current machine.
fb033b1e 53The 32-bit identifier was intended to be unique among all UNIX systems in
c13182ef
MK
54existence.
55This normally resembles the Internet address for the local
fea681da
MK
56machine, as returned by
57.BR gethostbyname (3),
58and thus usually never needs to be set.
847e0d88 59.PP
fea681da 60The
e511ffb6 61.BR sethostid ()
fea681da 62call is restricted to the superuser.
47297adb 63.SH RETURN VALUE
e511ffb6 64.BR gethostid ()
fea681da 65returns the 32-bit identifier for the current host as set by
2777b1ca 66.BR sethostid ().
847e0d88 67.PP
04826816
MK
68On success,
69.BR sethostid ()
70returns 0; on error, \-1 is returned, and
71.I errno
72is set to indicate the error.
4c98d120
MK
73.SH ERRORS
74.BR sethostid ()
75can fail with the following errors:
76.TP
77.B EACCES
78The caller did not have permission to write to the file used
79to store the host ID.
80.TP
81.B EPERM
82The calling process's effective user or group ID is not the same
83as its corresponding real ID.
406ff2be
ZL
84.SH ATTRIBUTES
85For 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
90allbox;
b32feea5 91lb lb lbx
406ff2be
ZL
92l l l.
93Interface Attribute Value
94T{
95.BR gethostid ()
b32feea5
MK
96T} Thread safety T{
97MT-Safe hostid env locale
98T}
406ff2be
ZL
99T{
100.BR sethostid ()
b32feea5
MK
101T} Thread safety T{
102MT-Unsafe const:hostid
103T}
406ff2be 104.TE
c466875e
MK
105.hy
106.ad
847e0d88 107.sp 1
3113c7f3 108.SH STANDARDS
97c1eac8 1094.2BSD; these functions were dropped in 4.4BSD.
c13182ef 110SVr4 includes
97c1eac8
MK
111.BR gethostid ()
112but not
113.BR sethostid ().
847e0d88 114.PP
32bb5d33 115POSIX.1-2001 and POSIX.1-2008 specify
e511ffb6 116.BR gethostid ()
fea681da 117but not
e511ffb6 118.BR sethostid ().
53a6b01d 119.SH NOTES
f9d5bb73
MK
120In the glibc implementation, the
121.I hostid
122is stored in the file
123.IR /etc/hostid .
124(In glibc versions before 2.2, the file
125.I /var/adm/hostid
126was used.)
127.\" libc5 used /etc/hostid; libc4 didn't have these functions
847e0d88 128.PP
53a6b01d
MK
129In the glibc implementation, if
130.BR gethostid ()
f9d5bb73 131cannot open the file containing the host ID,
ddaec46d 132then it obtains the hostname using
53a6b01d 133.BR gethostname (2),
ddaec46d 134passes that hostname to
3363301f 135.BR gethostbyname_r (3)
53a6b01d
MK
136in order to obtain the host's IPv4 address,
137and returns a value obtained by bit-twiddling the IPv4 address.
138(This value may not be unique.)
525748e0
MK
139.SH BUGS
140It 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)