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).
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +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)
|