The Windows Sockets getpeername function retrieves the name of the peer to which a socket is connected.
int getpeername (
SOCKET s,
struct sockaddr FAR* name,
int FAR* namelen
);
The getpeername function retrieves the name of the peer connected to the socket s and stores it in the aSOCKADDR structure identified by name. The getpeername function can be used only on a connected socket. For datagram sockets, only the name of a peer specified in a previous connect call will be returned—any name specified by a previous sendto call will not be returned by getpeername.
On call, the namelen argument contains the size of the name buffer, in bytes. On return, the namelen parameter contains the actual size in bytes of the name returned.
If no error occurs, getpeername returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
WSANOTINITIALISED | A successful WSAStartup must occur before using this function. |
WSAENETDOWN | The network subsystem has failed. |
WSAEFAULT | The name or the namelen parameter is not a valid part of the user address space, or the namelen parameter is too small. |
WSAEINPROGRESS | A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. |
WSAENOTCONN | The socket is not connected. |
WSAENOTSOCK | The descriptor is not a socket. |
Windows NT: Yes
Windows CE: Use version 1.0 and later.
Header: Declared in winsock2.h.
Import Library: Link with wsock32.lib.