man-pages/man3/gethostid.3.html
2021-03-31 01:06:50 +01:00

227 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETHOSTID</TITLE>
</HEAD><BODY>
<H1>GETHOSTID</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
gethostid, sethostid - get or set the unique identifier of the current host
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<P>
<B>long gethostid(void);</B>
<BR>
<B>int sethostid(long </B><I>hostid</I><B>);</B>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<BR>
<B>gethostid</B>():
<DL COMPACT><DT id="1"><DD>
_BSD_SOURCE || _XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
</DL>
<B>sethostid</B>():
<PRE>
Since glibc 2.21:
_DEFAULT_SOURCE
In glibc 2.19 and 2.20:
_DEFAULT_SOURCE || (_XOPEN_SOURCE &amp;&amp; _XOPEN_SOURCE&nbsp;&lt;&nbsp;500)
Up to and including glibc 2.19:
_BSD_SOURCE || (_XOPEN_SOURCE &amp;&amp; _XOPEN_SOURCE&nbsp;&lt;&nbsp;500)
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>gethostid</B>()
and
<B>sethostid</B>()
respectively get or set a unique 32-bit identifier for the current machine.
The 32-bit identifier is intended to be unique among all UNIX systems in
existence.
This normally resembles the Internet address for the local
machine, as returned by
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3),
and thus usually never needs to be set.
<P>
The
<B>sethostid</B>()
call is restricted to the superuser.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>gethostid</B>()
returns the 32-bit identifier for the current host as set by
<B>sethostid</B>().
<P>
On success,
<B>sethostid</B>()
returns 0; on error, -1 is returned, and
<I>errno</I>
is set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<B>sethostid</B>()
can fail with the following errors:
<DL COMPACT>
<DT id="2"><B>EACCES</B>
<DD>
The caller did not have permission to write to the file used
to store the host ID.
<DT id="3"><B>EPERM</B>
<DD>
The calling process's effective user or group ID is not the same
as its corresponding real ID.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>gethostid</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe hostid env locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>sethostid</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe const:hostid<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
4.2BSD; these functions were dropped in 4.4BSD.
SVr4 includes
<B>gethostid</B>()
but not
<B>sethostid</B>().
<P>
POSIX.1-2001 and POSIX.1-2008 specify
<B>gethostid</B>()
but not
<B>sethostid</B>().
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
In the glibc implementation, the
<I>hostid</I>
is stored in the file
<I>/etc/hostid</I>.
(In glibc versions before 2.2, the file
<I>/var/adm/hostid</I>
was used.)
<P>
In the glibc implementation, if
<B>gethostid</B>()
cannot open the file containing the host ID,
then it obtains the hostname using
<B><A HREF="/cgi-bin/man/man2html?2+gethostname">gethostname</A></B>(2),
passes that hostname to
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname_r">gethostbyname_r</A></B>(3)
in order to obtain the host's IPv4 address,
and returns a value obtained by bit-twiddling the IPv4 address.
(This value may not be unique.)
<A NAME="lbAJ">&nbsp;</A>
<H2>BUGS</H2>
It is impossible to ensure that the identifier is globally unique.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+hostid">hostid</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+gethostbyname">gethostbyname</A></B>(3)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
<DT id="13"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:44 GMT, March 31, 2021
</BODY>
</HTML>