[Previous] [Contents] [Next]

gethostname()

Get the name of the current host

Synopsis:

#include <unistd.h>

int gethostname( char * name,
                 size_t namelen );

Library:

libc

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 isn't set).

Classification:

Standard Unix, POSIX 1003.1g (draft)

Safety:
Cancellation point Yes
Interrupt handler Yes
Signal handler Yes
Thread Yes

Caveats:

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

See also:

sethostname()


[Previous] [Contents] [Next]