Open System Services System Calls Reference Manual (G06.25+, H06.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 OSS processes: implicit libraries
SYNOPSIS
#include <sys/socket.h>
int getsockname(
int socket,
struct sockaddr *address,
size_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.
address_len Points to a size_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
A process can use the getpeername() function to retrieve the name of a peer socket in a socket
connection.
RETURN VALUES
Upon successful completion, the getsockname( ) function returns the value 0 (zero). Otherwise,
the value -1 is returned and errno is set to indicate the error.
ERRORS
If any of the following conditions occur, the getsockname() function sets errno to the
corresponding value:
[EBADF] The socket parameter is not a valid file descriptor.
527186-003 Hewlett-Packard Company 3−49