1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)gethostname.3 6.9 (Berkeley) 04/04/93 7.\" 8.Dd 9.Dt GETHOSTNAME 3 10.Os BSD 4.2 11.Sh NAME 12.Nm gethostname , 13.Nm sethostname 14.Nd get/set name of current host 15.Sh SYNOPSIS 16.Fd #include <unistd.h> 17.Ft int 18.Fn gethostname "char *name" "int namelen" 19.Ft int 20.Fn sethostname "const char *name" "int namelen" 21.Sh DESCRIPTION 22.Fn Gethostname 23returns the standard host name for the current processor, as 24previously set by 25.Fn sethostname . 26The parameter 27.Fa namelen 28specifies the size of the 29.Fa name 30array. The returned name is null-terminated unless insufficient 31space is provided. 32.Pp 33.Fn Sethostname 34sets the name of the host machine to be 35.Fa name , 36which has length 37.Fa namelen . 38This call is restricted to the super-user and 39is normally used only when the system is bootstrapped. 40.Sh RETURN VALUES 41If the call succeeds a value of 0 is returned. If the call 42fails, a value of -1 is returned and an error code is 43placed in the global location 44.Va errno . 45.Sh ERRORS 46The following errors may be returned by these calls: 47.Bl -tag -width Er 48.It Bq Er EFAULT 49The 50.Fa name 51or 52.Fa namelen 53parameter gave an 54invalid address. 55.It Bq Er EPERM 56The caller tried to set the hostname and was not the super-user. 57.El 58.Sh SEE ALSO 59.Xr sysctl 2 60.Xr gethostid 3 61.Sh BUGS 62Host names are limited to 63.Dv MAXHOSTNAMELEN 64(from 65.Ao Pa sys/param.h Ac ) 66characters, currently 256. 67.Sh HISTORY 68The 69.Nm 70function call appeared in 71.Bx 4.2 . 72