1GETHOSTID(3)               Linux Programmer's Manual              GETHOSTID(3)
2
3
4

NAME

6       gethostid,  sethostid - get or set the unique identifier of the current
7       host
8

SYNOPSIS

10       #include <unistd.h>
11
12       long gethostid(void);
13       int sethostid(long hostid);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       sethostid(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
18

DESCRIPTION

20       gethostid() and sethostid() respectively get or  set  a  unique  32-bit
21       identifier  for the current machine.  The 32-bit identifier is intended
22       to be unique among all Unix systems in existence.  This normally resem‐
23       bles  the  Internet address for the local machine, as returned by geth‐
24       ostbyname(3), and thus usually never needs to be set.
25
26       The sethostid() call is restricted to the superuser.
27

RETURN VALUE

29       gethostid() returns the 32-bit identifier for the current host  as  set
30       by sethostid().
31
32       On  success, sethostid() returns 0; on error, -1 is returned, and errno
33       is set to indicate the error.
34

ERRORS

36       sethostid() can fail with the following errors:
37
38       EACCES The caller did not have permission to write to the file used  to
39              store the host ID.
40
41       EPERM  The calling process's effective user or group ID is not the same
42              as its corresponding real ID.
43

CONFORMING TO

45       4.2BSD; these functions were dropped in 4.4BSD.   SVr4  includes  geth‐
46       ostid()  but  not  sethostid().  POSIX.1-2001 specifies gethostid() but
47       not sethostid().
48

NOTES

50       In  the  glibc  implementation,  the  hostid  is  stored  in  the  file
51       /etc/hostid.   (In  glibc versions before 2.2, the file /var/adm/hostid
52       was used.)
53
54       In the glibc implementation, if gethostid() cannot open the  file  con‐
55       taining the host ID, then it obtains the hostname using gethostname(2),
56       passes that hostname to  gethostbyname_r(3)  in  order  to  obtain  the
57       host's  IPv4 address, and returns a value obtained by bit-twiddling the
58       IPv4 address.  (This value may not be unique.)
59

BUGS

61       It is impossible to ensure that the identifier is globally unique.
62

SEE ALSO

64       hostid(1), gethostbyname(3)
65

COLOPHON

67       This page is part of release 3.25 of the Linux  man-pages  project.   A
68       description  of  the project, and information about reporting bugs, can
69       be found at http://www.kernel.org/doc/man-pages/.
70
71
72
73Linux                             2009-01-13                      GETHOSTID(3)
Impressum