GETHOSTNAME(2) BSD GETHOSTNAME(2)
NAME
gethostname, sethostname - get/set name of current host
SYNOPSIS
gethostname(name, namelen)
char *name;
int namelen;
sethostname(name, namelen)
char *name;
int namelen;
DESCRIPTION
gethostname returns the standard host name for the current processor, as
previously set by sethostname. If no host name previously had been set,
gethostname returns the workstation's node name. The parameter namelen
specifies the size of the name array. The returned name is null
terminated unless insufficient space is provided in namelen.
sethostname sets the name of the host machine to be name, which has
length namelen. Use of sethostname is restricted to the super-user. It
is typically used only when the system is booted.
ERRORS
These calls may return the following errors:
[EFAULT] The name or namelen parameter gave an invalid address.
[EPERM] The caller tried to set the host name and was not the
super-user.
SEE ALSO
gethostid(2)
DIAGNOSTICS
A successful call returns 0. A failed call returns -1 and sets errno to
indicate the error.
NOTES
Host names are limited to MAXHOSTNAMELEN (from <sys/param.h>) characters,
currently 64.