gtpc1m3rTransmission Control Protocol/Internet Protocol

gethostname -- Return Host Name

The gethostname function returns the host name.

Format

#include  <socket.h>
int       gethostname(char *name,
                      int namelen);

name
Pointer to a buffer.

namelen
Length of the buffer.

Normal Return

Return code 0 indicates that the function was successful.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCNOBUFS
There is not enough buffer space to process this function. This error code is returned only for TCP/IP offload support.

EIBMIUCVERR
An error occurred when the function was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

OFFLOADTIMEOUT
A response was not received from the offload device in a specified time period. This error code is returned only for TCP/IP offload support.

SOCINVAL
The namelen parameter is not a valid length. This error code is returned only for TCP/IP native stack support.

SOCFAULT
Using buf and len results in an attempt to access a protected address space. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

The following example obtains the host Internet Protocol (IP) address.

#include <types.h>
#include <socket.h>

·
·
·
int rc; int server_sock; u_char hostname[50];
·
·
·
rc = gethostname(&hostname,sizeof(hostname)); printf("hostname = %s\n",hostname);

Related Information

gethostid -- Return Identifier of Current Host.