[Previous] [Contents] [Index] [Next]

sethostname()

Set the name of the current host

Synopsis:

#include <unistd.h>

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

Library:

libc

Description:

The sethostname() function sets the name of the host machine to be name. The length of name is set by namelen. Restricted to the superuser, this call is normally used only at boot time.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EFAULT
Either name or namelen gave an invalid address.
EPERM
Although the caller wasn't the superuser, it tried to set the hostname.

Classification:

Unix

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

Caveats:

This function is restricted to the superuser, and is normally used only at boot time.

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

See also:

gethostname()


[Previous] [Contents] [Index] [Next]