1*61111Sbostic.\" Copyright (c) 1983, 1991, 1993 2*61111Sbostic.\" The Regents of the University of California. All rights reserved. 320227Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520227Smckusick.\" 6*61111Sbostic.\" @(#)gethostname.3 8.1 (Berkeley) 06/04/93 738053Sbostic.\" 847208Scael.Dd 958954Smckusick.Dt GETHOSTNAME 3 1047208Scael.Os BSD 4.2 1147208Scael.Sh NAME 1247208Scael.Nm gethostname , 1347208Scael.Nm sethostname 1447208Scael.Nd get/set name of current host 1547208Scael.Sh SYNOPSIS 1647208Scael.Fd #include <unistd.h> 1747208Scael.Ft int 1847208Scael.Fn gethostname "char *name" "int namelen" 1947208Scael.Ft int 2047208Scael.Fn sethostname "const char *name" "int namelen" 2147208Scael.Sh DESCRIPTION 2247208Scael.Fn Gethostname 2320227Smckusickreturns the standard host name for the current processor, as 2420227Smckusickpreviously set by 2547208Scael.Fn sethostname . 2620227SmckusickThe parameter 2747208Scael.Fa namelen 2820227Smckusickspecifies the size of the 2947208Scael.Fa name 3020227Smckusickarray. The returned name is null-terminated unless insufficient 3120227Smckusickspace is provided. 3247208Scael.Pp 3347208Scael.Fn Sethostname 3420227Smckusicksets the name of the host machine to be 3547208Scael.Fa name , 3620227Smckusickwhich has length 3747208Scael.Fa namelen . 3820227SmckusickThis call is restricted to the super-user and 3920227Smckusickis normally used only when the system is bootstrapped. 4047208Scael.Sh RETURN VALUES 4120227SmckusickIf the call succeeds a value of 0 is returned. If the call 4247208Scaelfails, a value of -1 is returned and an error code is 4347208Scaelplaced in the global location 4447208Scael.Va errno . 4547208Scael.Sh ERRORS 4620227SmckusickThe following errors may be returned by these calls: 4747208Scael.Bl -tag -width Er 4847208Scael.It Bq Er EFAULT 4947208ScaelThe 5047208Scael.Fa name 5147208Scaelor 5247208Scael.Fa namelen 5347208Scaelparameter gave an 5420227Smckusickinvalid address. 5547208Scael.It Bq Er EPERM 5624440SmckusickThe caller tried to set the hostname and was not the super-user. 5747208Scael.El 5847208Scael.Sh SEE ALSO 5958954Smckusick.Xr sysctl 2 6058954Smckusick.Xr gethostid 3 6147208Scael.Sh BUGS 6247208ScaelHost names are limited to 6347208Scael.Dv MAXHOSTNAMELEN 6447208Scael(from 6547208Scael.Ao Pa sys/param.h Ac ) 6654336Scaelcharacters, currently 256. 6747208Scael.Sh HISTORY 6847208ScaelThe 6947208Scael.Nm 7047208Scaelfunction call appeared in 7147208Scael.Bx 4.2 . 72