[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2


gethostname Subroutine

Purpose

Gets the name of the local host.

Library

Standard C Library (libc.a)

Syntax


#include <unistd.h>

int gethostname ( Name NameLength)
char *Name;
size_t NameLength;

Description

The gethostname subroutine retrieves the standard host name of the local host. If excess space is provided, the returned Name parameter is null-terminated. If insufficient space is provided, the returned name is truncated to fit in the given space. System host names are limited to 256 characters.

The gethostname subroutine allows a calling process to determine the internal host name for a machine on a network.

Parameters


Name Specifies the address of an array of bytes where the host name is to be stored.
NameLength Specifies the length of the Name array.

Return Values

Upon successful completion, the system returns a value of 0.

If the gethostname subroutine is unsuccessful, the subroutine handler performs the following functions:

Error Codes

The gethostname subroutine is unsuccessful if the following is true:

EFAULT The Name parameter or NameLength parameter gives an invalid address.

Implementation Specifics

The gethostname subroutine is part of Base Operating System (BOS) Runtime.

All applications containing the gethostname subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Related Information

The gethostid subroutine, sethostid subroutine, sethostname subroutine.

Sockets Overview in AIX 5L Version 5.1 Communications Programming Concepts.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]