sethostname()--Set Host Name


Syntax
#include <sys/types.h>
#include <sys/socket.h>

int sethostname(char *name,
                int length)


Threadsafe: Yes

The sethostname() function is used to set the name of the host for a system.

Parameters

name
(Input) The pointer to a character array where the host name is stored.

length
(Input) The length of the name parameter.

Return Value

sethostname() returns an integer. Possible values are:

Error Conditions

When sethostname() fails, errno can be set to one of the following:

[EFAULT]
Bad address.

The system detected an address which was not valid while attempting to access the name parameter.

[EINVAL]
Parameter not valid.

This error code indicates one of the following:

[EPERM]
Operation not permitted.

The process does not have the appropriate privileges to use sethostname().

[EIO]
Input/output error.
[EUNKNOWN]
Unknown system state.

Error Messages

CPE3418 E
Possible APAR condition or hardware failure.
CPF9872 E
Program or service program &1 in library &2 ended. Reason code &3.
CPFA081 E
Unable to set return value or error code.

Usage Notes

  1. A process must have the *IOSYSCFG special authority to use the sethostname().

  2. Maximum length of host names is defined by [MAXHOSTNAMELEN] (defined in <sys/param.h>).

  3. The host name can be set in the following two ways (and users should be aware of the implications of the way they choose):

  4. The name of the host is set to NULL when the pointer to the host name (pointed to by the name parameter) is set to NULL.

  5. The host name is assumed to be in the default coded character set identifier (CCSID) currently in effect for the job. In addition, the host name must adhere to the following conventions.

Related Information
gethostname()--Retrieve Host Name


Top | Sockets APIs | APIs by category


[Information Center Home Page | Feedback ] [Legal | AS/400 Glossary]