OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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 2010-09-20 "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 .RS 4
53 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
54 .RE
55 .ad b
56 .SH DESCRIPTION
57 .BR gethostid ()
58 and
59 .BR sethostid ()
60 respectively get or set a unique 32-bit identifier for the current machine.
61 The 32-bit identifier is intended to be unique among all UNIX systems in
62 existence.
63 This normally resembles the Internet address for the local
64 machine, as returned by
65 .BR gethostbyname (3),
66 and thus usually never needs to be set.
67
68 The
69 .BR sethostid ()
70 call is restricted to the superuser.
71 .SH RETURN VALUE
72 .BR gethostid ()
73 returns the 32-bit identifier for the current host as set by
74 .BR sethostid ().
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.
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.
92 .SH CONFORMING TO
93 4.2BSD; these functions were dropped in 4.4BSD.
94 SVr4 includes
95 .BR gethostid ()
96 but not
97 .BR sethostid ().
98 POSIX.1-2001 specifies
99 .BR gethostid ()
100 but not
101 .BR sethostid ().
102 .SH NOTES
103 In the glibc implementation, the
104 .I hostid
105 is stored in the file
106 .IR /etc/hostid .
107 (In glibc versions before 2.2, the file
108 .I /var/adm/hostid
109 was used.)
110 .\" libc5 used /etc/hostid; libc4 didn't have these functions
111
112 In the glibc implementation, if
113 .BR gethostid ()
114 cannot open the file containing the host ID,
115 then it obtains the hostname using
116 .BR gethostname (2),
117 passes that hostname to
118 .BR gethostbyname_r (3)
119 in order to obtain the host's IPv4 address,
120 and returns a value obtained by bit-twiddling the IPv4 address.
121 (This value may not be unique.)
122 .SH BUGS
123 It is impossible to ensure that the identifier is globally unique.
124 .SH SEE ALSO
125 .BR hostid (1),
126 .BR gethostbyname (3)
127 .SH COLOPHON
128 This page is part of release 3.79 of the Linux
129 .I man-pages
130 project.
131 A description of the project,
132 information about reporting bugs,
133 and the latest version of this page,
134 can be found at
135 \%http://www.kernel.org/doc/man\-pages/.