gtpc1m3r | Transmission Control Protocol/Internet Protocol |
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
- The output of gethostname is either X or Y, where X is the
complex name suffixed with the CPU identifier of the TPF host and Y is the
host name of the first active and connected offload device. To
determine the output of gethostname, consider the following:
- If TCP/IP native stack support is defined and TCP/IP offload support is
not defined, the output of gethostname is X.
- If TCP/IP offload support is defined and TCP/IP native stack support is
not defined, the output of gethostname is Y.
- If both TCP/IP native stack support and TCP/IP offload support are
defined, and the last time that this entry control block (ECB) called USOK it
picked TCP/IP native stack support, the output of gethostname is
X.
- If both TCP/IP native stack support and TCP/IP offload support are
defined, and the last time that this ECB called USOK it picked TCP/IP offload
support, the output of gethostname is Y.
- When TCP/IP native stack support is defined, the length of the buffer must
be a minimum of 10 bytes.
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.