sethostname.2 (2011 09)

s
sethostname(2) sethostname(2)
NAME
sethostname() - set name of current host system
SYNOPSIS
#include <unistd.h>
int sethostname(const char *name, size_t namelen);
DESCRIPTION
The sethostname()
system call sets the name of the current system to name, which has a length of
namelen characters. At system boot time
sethostname()
is normally executed by the hostname
com-
mand (see hostname (1)) in the
/sbin/init.d/hostname
script. Host names are limited to MAX-
HOSTNAMELEN characters, as defined in <sys/param.h>
.
Security Restrictions
Prior to ContainmentExt B.11.31.03, the actions associated with this system call require the
PRIV_SYSATTR privilege (SYSATTR). If ContainmentExt B.11.31.03 or a later version of HP-UX Con-
tainment product is installed on the system, either the
PRIV_SYSATTR privilege (SYSATTR) or the
PRIV_HOSTATTR
privilege (HOSTATTR) is required. Processes owned by the superuser have this
privilege. Processes owned by other users may have this privilege, depending on system configuration.
See privileges (5) for more information about privileged access on systems that support fine-grained
privileges.
RETURN VALUE
sethostname returns the following values:
0 Successful completion.
-1 Failure. errno is set to indicate the error.
ERRORS
If
sethostname() fails, errno is set to one of the following values.
[EFAULT] name points to an illegal address. The reliable detection of this error is implemen-
tation dependent.
[EPERM] The user does not have appropriate privileges.
WARNINGS
Setting a hostname of more than 64 bytes with
sethostname()
is possible only with the appropriate
configuration options enabled (see nodehostnamesize(5)). It is strongly recommended that all related
documentation be completely understood before setting a larger hostname. A hostname larger than 64
bytes can cause anomalous behavior or failure in applications which use the
hostname command or the
gethostname() system function to obtain the name.
AUTHOR
sethostname() was developed by the University of California, Berkeley.
SEE ALSO
hostname(1), uname(1), gethostname(2), uname(2), nodehostnamesize(5), privileges(5).
HP-UX 11i Version 3: September 2011 1 Hewlett-Packard Company 1

Summary of content (2 pages)