Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

System Functions (f - i) getsockname(2)
NAME
getsockname - Gets the locally bound name of a socket
LIBRARY
G-series native OSS processes: system library
H-series and J-series OSS processes: implicit libraries
SYNOPSIS
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/socket.h>
int getsockname(
int socket,
struct sockaddr *address,
socklen_t *address_len);
PARAMETERS
socket Specifies the file descriptor of the socket.
address Points to a sockaddr structure, where the locally bound address of the specified
socket is returned.
If the length of the socket address is greater than the length of the supplied
sockaddr structure, the address is truncated when stored.
If the socket has not been bound to a local address, the value stored is
unspecified.
The length and format of the address depend on the address family of the socket.
For AF_INET sockets, a pointer to the address structure sockaddr_in can be
cast as a struct sockaddr.ForAF_INET6 sockets, a pointer to the address
structure sockaddr_in6 can be cast as a struct sockaddr.ForAF_UNIX sock-
ets, a pointer to the address structure sockaddr_un must be cast as a struct
sockaddr.
address_len Points to a socklen_t data item, which, on input, specifies the length of the
sockaddr structure pointed to by the address parameter, and, on output, specifies
the length of the address returned.
DESCRIPTION
The getsockname() function retrieves the locally-bound address of the specified socket, stores
this address in the sockaddr structure pointed to by the address parameter, and stores the length
of this address in the object pointed to by the address_len parameter.
NOTES
This function requires that the feature-test macro _XOPEN_SOURCE_EXTENDED be specified
when you compile the module.
A process can use the getpeername() function to retrieve the name of a peer socket in a socket
connection.
After a successful call to bind(), if the underlying le is unlinked or renamed, the behavior of
getsockname() depends on the mode of the socket:
For AF_UNIX Release 1 sockets and AF_UNIX Release 2 sockets in compatibility
mode, getsockname() fails and errno is set to [ENOENT].
For AF_UNIX Release 2 sockets in portability mode, the fully-qualified name of the file
is returned.
527186-023 Hewlett-Packard Company 385