xref: /csrg-svn/lib/libc/gen/gethostname.3 (revision 47208)
1*47208Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California.
238053Sbostic.\" All rights reserved.
320227Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520227Smckusick.\"
6*47208Scael.\"     @(#)gethostname.3	6.7 (Berkeley) 03/10/91
738053Sbostic.\"
8*47208Scael.Dd
9*47208Scael.Dt GETHOSTNAME 2
10*47208Scael.Os BSD 4.2
11*47208Scael.Sh NAME
12*47208Scael.Nm gethostname ,
13*47208Scael.Nm sethostname
14*47208Scael.Nd get/set name of current host
15*47208Scael.Sh SYNOPSIS
16*47208Scael.Fd #include <unistd.h>
17*47208Scael.Ft int
18*47208Scael.Fn gethostname "char *name" "int namelen"
19*47208Scael.Ft int
20*47208Scael.Fn sethostname "const char *name" "int namelen"
21*47208Scael.Sh DESCRIPTION
22*47208Scael.Fn Gethostname
2320227Smckusickreturns the standard host name for the current processor, as
2420227Smckusickpreviously set by
25*47208Scael.Fn sethostname .
2620227SmckusickThe parameter
27*47208Scael.Fa namelen
2820227Smckusickspecifies the size of the
29*47208Scael.Fa name
3020227Smckusickarray.  The returned name is null-terminated unless insufficient
3120227Smckusickspace is provided.
32*47208Scael.Pp
33*47208Scael.Fn Sethostname
3420227Smckusicksets the name of the host machine to be
35*47208Scael.Fa name ,
3620227Smckusickwhich has length
37*47208Scael.Fa namelen .
3820227SmckusickThis call is restricted to the super-user and
3920227Smckusickis normally used only when the system is bootstrapped.
40*47208Scael.Sh RETURN VALUES
4120227SmckusickIf the call succeeds a value of 0 is returned.  If the call
42*47208Scaelfails, a value of -1 is returned and an error code is
43*47208Scaelplaced in the global location
44*47208Scael.Va errno .
45*47208Scael.Sh ERRORS
4620227SmckusickThe following errors may be returned by these calls:
47*47208Scael.Bl -tag -width Er
48*47208Scael.It Bq Er EFAULT
49*47208ScaelThe
50*47208Scael.Fa name
51*47208Scaelor
52*47208Scael.Fa namelen
53*47208Scaelparameter gave an
5420227Smckusickinvalid address.
55*47208Scael.It Bq Er EPERM
5624440SmckusickThe caller tried to set the hostname and was not the super-user.
57*47208Scael.El
58*47208Scael.Sh SEE ALSO
59*47208Scael.Xr gethostid 2
60*47208Scael.Sh BUGS
61*47208ScaelHost names are limited to
62*47208Scael.Dv MAXHOSTNAMELEN
63*47208Scael(from
64*47208Scael.Ao Pa sys/param.h Ac )
6528078Skarelscharacters, currently 64.
66*47208Scael.Sh HISTORY
67*47208ScaelThe
68*47208Scael.Nm
69*47208Scaelfunction call appeared in
70*47208Scael.Bx 4.2 .
71