gethostname()

get the name of the current host

Synopsis:

#include <unix.h>

int gethostname( char *name, 
                 int namelen );

Description:

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

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

If an error occurred, errno could contain one of the following:

EFAULT
Either name or namelen gave an invalid address.

Classification:

POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

Hostnames are limited to MAXHOSTNAMELEN characters (defined in <sys/param.h>).

See also:

sethostname()