2004-11-03 13:51:07 +00:00
|
|
|
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
|
|
.\"
|
|
|
|
.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" Modified 1995-07-22 by Michael Chastain <mec@duracef.shout.net>:
|
|
|
|
.\" 'gethostname' is real system call on Linux/Alpha.
|
|
|
|
.\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
|
|
|
|
.\" Modified 2000-06-04, 2001-12-15 by aeb
|
|
|
|
.\" Modified 2004-06-17 by mtk
|
2008-11-28 19:00:21 +00:00
|
|
|
.\" Modified 2008-11-27 by mtk
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
chdir.2, chmod.2, chown.2, gethostname.2, getsid.2, pread.2, setpgid.2, sigaltstack.2, truncate.2, wait.2, dirfd.3, getsubopt.3, mkdtemp.3, mkstemp.3, siginterrupt.3, strdup.3: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-26 15:43:00 +00:00
|
|
|
.TH GETHOSTNAME 2 2010-09-26 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
2008-06-27 03:37:56 +00:00
|
|
|
gethostname, sethostname \- get/set hostname
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <unistd.h>
|
|
|
|
.sp
|
|
|
|
.BI "int gethostname(char *" name ", size_t " len );
|
|
|
|
.br
|
|
|
|
.BI "int sethostname(const char *" name ", size_t " len );
|
2007-07-08 12:11:40 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
|
|
|
.sp
|
|
|
|
.ad l
|
2010-09-18 19:25:35 +00:00
|
|
|
.PD 0
|
2007-07-08 12:11:40 +00:00
|
|
|
.BR gethostname ():
|
2010-09-18 19:25:35 +00:00
|
|
|
.RS 4
|
|
|
|
Since glibc 2.12:
|
2007-07-08 12:11:40 +00:00
|
|
|
_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
|
chdir.2, chmod.2, chown.2, gethostname.2, getsid.2, pread.2, setpgid.2, sigaltstack.2, stat.2, truncate.2, wait.2, dirfd.3, getsubopt.3, mkdtemp.3, mkstemp.3, siginterrupt.3, strdup.3: Simplify feature test macro requirements
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-26 15:16:57 +00:00
|
|
|
.br
|
|
|
|
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
|
2010-09-18 19:25:35 +00:00
|
|
|
.RE
|
2007-07-08 12:11:40 +00:00
|
|
|
.br
|
|
|
|
.BR sethostname ():
|
2010-09-18 19:25:35 +00:00
|
|
|
.RS 4
|
2007-07-08 12:11:40 +00:00
|
|
|
_BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
|
2010-09-18 19:25:35 +00:00
|
|
|
.RE
|
|
|
|
.PD
|
|
|
|
.ad
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2008-06-27 03:37:56 +00:00
|
|
|
These system calls are used to access or to change the hostname of the
|
2004-11-03 13:51:07 +00:00
|
|
|
current processor.
|
2008-11-28 19:00:21 +00:00
|
|
|
|
|
|
|
.BR sethostname ()
|
|
|
|
sets the hostname to the value given in the character array
|
|
|
|
.IR name .
|
2004-11-03 13:51:07 +00:00
|
|
|
The
|
2008-11-28 19:00:21 +00:00
|
|
|
.I len
|
|
|
|
argument specifies the number of bytes in
|
|
|
|
.IR name .
|
|
|
|
(Thus,
|
|
|
|
.I name
|
|
|
|
does not require a terminating null byte.)
|
|
|
|
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR gethostname ()
|
2008-11-28 19:00:21 +00:00
|
|
|
returns the null-terminated hostname in the character array
|
|
|
|
.IR name ,
|
|
|
|
which has a length of
|
|
|
|
.I len
|
|
|
|
bytes.
|
|
|
|
If the null-terminated hostname is too large to fit,
|
|
|
|
then the name is truncated, and no error is returned (but see NOTES below).
|
|
|
|
POSIX.1-2001 says that if such truncation occurs,
|
|
|
|
then it is unspecified whether the returned buffer
|
|
|
|
includes a terminating null byte.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
2007-04-12 22:42:49 +00:00
|
|
|
On success, zero is returned.
|
|
|
|
On error, \-1 is returned, and
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
|
|
|
is set appropriately.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EFAULT
|
|
|
|
.I name
|
|
|
|
is an invalid address.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I len
|
2008-11-28 19:00:21 +00:00
|
|
|
is negative
|
|
|
|
.\" Can't occur for gethostbyname() wrapper, since 'len' has an
|
|
|
|
.\" unsigned type; can occur for the underlying system call.
|
|
|
|
or, for
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sethostname (),
|
2004-11-03 13:51:07 +00:00
|
|
|
.I len
|
2008-11-28 19:00:21 +00:00
|
|
|
is larger than the maximum allowed size.
|
|
|
|
.TP
|
|
|
|
.B ENAMETOOLONG
|
|
|
|
.RB "(glibc " gethostname ())
|
2004-11-03 13:51:07 +00:00
|
|
|
.I len
|
|
|
|
is smaller than the actual size.
|
2008-11-28 19:00:21 +00:00
|
|
|
(Before version 2.1, glibc uses
|
|
|
|
.BR EINVAL
|
|
|
|
for this case.)
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
For
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sethostname (),
|
2004-11-03 13:51:07 +00:00
|
|
|
the caller did not have the
|
|
|
|
.B CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.SH "CONFORMING TO"
|
2006-12-27 02:36:18 +00:00
|
|
|
SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
|
2006-08-03 13:57:17 +00:00
|
|
|
POSIX.1-2001 specifies
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR gethostname ()
|
2004-11-03 13:51:07 +00:00
|
|
|
but not
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sethostname ().
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2007-12-18 07:47:22 +00:00
|
|
|
SUSv2 guarantees that "Host names are limited to 255 bytes".
|
|
|
|
POSIX.1-2001 guarantees that "Host names (not including
|
2007-06-22 17:16:20 +00:00
|
|
|
the terminating null byte) are limited to
|
2007-09-20 16:26:31 +00:00
|
|
|
.B HOST_NAME_MAX
|
2007-12-18 07:47:22 +00:00
|
|
|
bytes".
|
2008-11-28 20:05:13 +00:00
|
|
|
On Linux,
|
|
|
|
.B HOST_NAME_MAX
|
|
|
|
is defined with the value 64, which has been the limit since Linux 1.0
|
|
|
|
(earlier kernels imposed a limit of 8 bytes).
|
2007-05-18 10:30:02 +00:00
|
|
|
.SS Glibc Notes
|
2008-11-28 19:00:21 +00:00
|
|
|
The GNU C library does not employ the
|
|
|
|
.BR gethostname ()
|
|
|
|
system call; instead, it implements
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR gethostname ()
|
|
|
|
as a library function that calls
|
2006-01-12 21:53:50 +00:00
|
|
|
.BR uname (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
and copies up to
|
2006-01-12 21:53:50 +00:00
|
|
|
.I len
|
2007-04-12 22:42:49 +00:00
|
|
|
bytes from the returned
|
|
|
|
.I nodename
|
2006-01-12 21:53:50 +00:00
|
|
|
field into
|
|
|
|
.IR name .
|
|
|
|
Having performed the copy, the function then checks if the length of the
|
|
|
|
.I nodename
|
|
|
|
was greater than or equal to
|
|
|
|
.IR len ,
|
2007-04-12 22:42:49 +00:00
|
|
|
and if it is, then the function returns \-1 with
|
|
|
|
.I errno
|
2006-01-12 21:53:50 +00:00
|
|
|
set to
|
2008-11-28 19:00:21 +00:00
|
|
|
.BR ENAMETOOLONG ;
|
2010-08-29 07:06:12 +00:00
|
|
|
in this case, a terminating null byte is not included in the returned
|
2008-11-28 19:00:21 +00:00
|
|
|
.IR name .
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
Versions of glibc before 2.2
|
2006-01-12 21:53:50 +00:00
|
|
|
.\" At least glibc 2.0 and 2.1, older versions not checked
|
|
|
|
handle the case where the length of the
|
|
|
|
.I nodename
|
|
|
|
was greater than or equal to
|
2007-09-20 16:26:31 +00:00
|
|
|
.I len
|
2007-04-12 22:42:49 +00:00
|
|
|
differently: nothing is copied into
|
2006-01-12 21:53:50 +00:00
|
|
|
.I name
|
|
|
|
and the function returns \-1 with
|
2007-04-12 22:42:49 +00:00
|
|
|
.I errno
|
2006-01-12 21:53:50 +00:00
|
|
|
set to
|
|
|
|
.BR ENAMETOOLONG .
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR getdomainname (2),
|
|
|
|
.BR setdomainname (2),
|
|
|
|
.BR uname (2)
|