gtpc1m3vTransmission Control Protocol/Internet Protocol

getsockname -- Return the Name of the Local Socket

The getsockname returns the name of the local socket.

Normal Return

#include  <socket.h>
int       getsockname(int s,
                      struct sockaddr *name,
                      int *namelen);

s
The socket descriptor.

name
Address of a sockaddr buffer into which getsockname copies the local address of the socket.

namelen
Must initially point to an integer that contains the size, in bytes, of the storage pointed to by name. On return, that integer contains the size of the data returned in the storage pointed to by name.

Format

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

SOCFAULT
Using name and namelen would result in an attempt to access a protected address space. This error code is returned only for TCP/IP offload support.

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

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

EIBMIUCVERR
An error occurred while the function call 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. This error code is returned only for TCP/IP offload support.

OFFLOADTIMEOUT
The offload device did not respond to the function call in a specified time period. This error code is returned only for TCP/IP offload support.

SOCNOTCONN
The socket is not bound to an IP address. This error code is returned only for TCP/IP native stack support.

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

Programming Considerations

Examples

The following example obtains its socket address information.

#include <socket.h>

·
·
·
int addrlen; int rc; int server_sock; struct sockaddr_in server_addr;
·
·
·
addrlen = sizeof(server_addr); rc = getsockname(server_sock,(struct sockaddr *)&server_addr, &addrlen);

Related Information