Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


sethostname() — set name of current host system


#include <unistd.h>

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


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 command (see hostname(1)) in the /sbin/init.d/hostname script. Host names are limited to MAXHOSTNAMELEN characters, as defined in <sys/param.h>.

Security Restrictions

The actions associated with this system call require the PRIV_SYSATTR privilege (SYSATTR). 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.


sethostname() returns the following values:


Successful completion.


Failure. errno is set to indicate the error.


If sethostname() fails, errno is set to one of the following values.


name points to an illegal address. The reliable detection of this error is implementation dependent.


The user does not have appropriate privileges.


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.


sethostname() was developed by the University of California, Berkeley.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.