GETHOSTNAME(2)

NAME
gethostname, sethostname - get/set name of current host

SYNOPSIS
int gethostname(name, namelen)
char *name;
int namelen;

int sethostname(name, namelen)
char *name;
int namelen;

DESCRIPTION

gethostname() returns the standard host name for the current processor, as previously set by sethostname(). The parameter namelen specifies the size of the array pointed to by name. The returned name is null-terminated unless insufficient space is provided.

sethostname() sets the name of the host machine to be name, which has length namelen. This call is restricted to the super-user and is normally used only when the system is bootstrapped.

RETURN VALUES

gethostname() and sethostname() return:

0   on success.

-1  on failure and set errno to indicate the error.

ERRORS

EFAULT
    The name or namelen parameter gave an invalid address.

In addition to the above, sethostname() may set errno to:

EPERM
    The caller was not the super-user.

SEE ALSO
gethostid(2)

NOTES

Host names are limited to MAXHOSTNAMELEN (from <sys/param.h>) characters, currently 64.