gethostname(3C)


gethostname, sethostname -- get or set name of current host

Synopsis

   #include <unistd.h>
   

int gethostname(char *name, size_t namelen);

int sethostname(char *name, size_t namelen);

Description

The gethostname function returns the standard host name for the current machine. The namelen argument specifies the size of the array pointed to by the name argument. The returned name is null-terminated. If namelen is an insufficient length to hold the host name, then the returned name is truncated to (namelen - 1) characters and null-terminated. Host names are limited to 255 bytes.

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

Return value

On successful completion, 0 is returned. Otherwise, -1 is returned.

Errors

The following errors may be returned by these calls:

EFAULT
The name or namelen parameter gave an invalid address.

EPERM
The caller does not have appropriate privilege to use sethostname.

References

uname(2), gethostid(3C)

Standards conformance

The gethostname routine conforms to X/Open System Interfaces and Headers, Issue 4, Version 2.

The sethostname routine does not conform to any current industry standard.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004