version 1.8, 1999/03/22 19:44:42 |
version 1.18, 2015/09/03 04:05:38 |
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright |
.\" 2. Redistributions in binary form must reproduce the above copyright |
.\" notice, this list of conditions and the following disclaimer in the |
.\" notice, this list of conditions and the following disclaimer in the |
.\" documentation and/or other materials provided with the distribution. |
.\" documentation and/or other materials provided with the distribution. |
.\" 3. All advertising materials mentioning features or use of this software |
.\" 3. Neither the name of the University nor the names of its contributors |
.\" must display the following acknowledgement: |
|
.\" This product includes software developed by the University of |
|
.\" California, Berkeley and its contributors. |
|
.\" 4. Neither the name of the University nor the names of its contributors |
|
.\" may be used to endorse or promote products derived from this software |
.\" may be used to endorse or promote products derived from this software |
.\" without specific prior written permission. |
.\" without specific prior written permission. |
.\" |
.\" |
|
|
.\" |
.\" |
.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93 |
.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93 |
.\" |
.\" |
.Dd June 4, 1993 |
.Dd September 2, 2015 |
.Dt GETHOSTNAME 3 |
.Dt GETHOSTNAME 3 |
.Os |
.Os |
.Sh NAME |
.Sh NAME |
|
|
.Sh LIBRARY |
.Sh LIBRARY |
.Lb libc |
.Lb libc |
.Sh SYNOPSIS |
.Sh SYNOPSIS |
.Fd #include <unistd.h> |
.In unistd.h |
.Ft int |
.Ft int |
.Fn gethostname "char *name" "size_t namelen" |
.Fn gethostname "char *name" "size_t namelen" |
.Ft int |
.Ft int |
.Fn sethostname "const char *name" "size_t namelen" |
.Fn sethostname "const char *name" "size_t namelen" |
.Sh DESCRIPTION |
.Sh DESCRIPTION |
.Fn gethostname |
.Fn gethostname |
returns the standard host name for the current processor, as |
returns the standard host name for the current machine, as |
previously set by |
previously set by |
.Fn sethostname . |
.Fn sethostname . |
The parameter |
The parameter |
.Fa namelen |
.Fa namelen |
specifies the size of the |
specifies the size of the |
.Fa name |
.Fa name |
array. The returned name is null-terminated unless insufficient |
array. |
|
The returned name is null-terminated unless insufficient |
space is provided. |
space is provided. |
.Pp |
.Pp |
.Fn sethostname |
.Fn sethostname |
|
|
This call is restricted to the super-user and |
This call is restricted to the super-user and |
is normally used only when the system is bootstrapped. |
is normally used only when the system is bootstrapped. |
.Sh RETURN VALUES |
.Sh RETURN VALUES |
If the call succeeds a value of 0 is returned. If the call |
If the call succeeds a value of 0 is returned. |
fails, a value of -1 is returned and an error code is |
If the call fails, a value of \-1 is returned and an error code is |
placed in the global location |
placed in the global location |
.Va errno . |
.Va errno . |
.Sh ERRORS |
.Sh ERRORS |
The following errors may be returned by these calls: |
If the |
.Bl -tag -width Er |
.Fn gethostname |
.It Bq Er EFAULT |
|
The |
|
.Fa name |
|
or |
or |
.Fa namelen |
.Fn sethostname |
parameter gave an |
functions fail, |
invalid address. |
they will set |
.It Bq Er EPERM |
.Va errno |
The caller tried to set the hostname and was not the super-user. |
for any of the errors specified for the routine |
.El |
.Xr sysctl 3 . |
.Sh SEE ALSO |
.Sh SEE ALSO |
.Xr sysctl 3 , |
|
.Xr gethostid 3 , |
.Xr gethostid 3 , |
|
.Xr sysctl 3 , |
.Xr sysctl 8 |
.Xr sysctl 8 |
.Sh STANDARDS |
.Sh STANDARDS |
The |
The |
.Fn gethostname |
.Fn gethostname |
function conforms to |
function conforms to |
.St -xpg4.2 . |
.St -xpg4.2 . |
|
.Sh HISTORY |
|
The |
|
.Nm |
|
function call appeared in |
|
.Bx 4.2 . |
.Sh BUGS |
.Sh BUGS |
Host names are limited to |
Host names are limited to |
.Dv MAXHOSTNAMELEN |
.Dv MAXHOSTNAMELEN |
(from |
(from |
.Ao Pa sys/param.h Ac ) |
.Ao Pa sys/param.h Ac ) |
characters including null-termination, currently 256. |
characters including null-termination, currently 256. |
.Sh HISTORY |
|
The |
|
.Nm |
|
function call appeared in |
|
.Bx 4.2 . |
|