Open System Services System Calls Reference Manual (G06.25+, H06.03+)

System Functions (f - i) getpeername(2)
NAME
getpeername - Gets the name of the peer socket
LIBRARY
G-series native OSS processes: /G/system/sysnn/zinetsrl
H-series OSS processes: /G/system/zdllnnn/zinetdll
SYNOPSIS
#include <sys/socket.h>
int getpeername(
int socket,
struct sockaddr *address,
size_t *address_len
);
PARAMETERS
socket Species the open le descriptor of the socket.
address Points to a sockaddr structure, where the address of the peer socket is returned.
If the length of the address is greater than the length of the supplied sockaddr
structure, the address is truncated when stored.
If the protocol permits connection by unbound clients, and if the peer socket is
not bound to an address, then the value stored is unspecied.
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, species the length of the sockaddr
structure pointed to by the address parameter, and, on output, species the length
of the address returned.
DESCRIPTION
The getpeername() function retrieves the peer address of the specied 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 getsockname( ) function to retrieve the locally bound name of a socket.
RETURN VALUES
Upon successful completion, the getpeername() 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 occurs, the getpeername() function sets errno to the
corresponding value:
[EBADF] The socket parameter is not a valid le descriptor.
[ECONNRESET]
One of the following conditions occurred:
The transport-provider process for this socket is no longer available.
The TCP/IP subsystem for this socket is no longer available.
527186-003 Hewlett-Packard Company 341