The getpeername() socket call gets the name of the peer connected to socket.
Syntax
#include <types.h> #include <sys\socket.h> int getpeername(s, name, namelen) int s; struct sockaddr *name; int *namelen;
Parameters
s
Description
This call returns the name of the peer connected to socket s. The namelen parameter must be initialized to indicate the size of the space pointed to by name. On return, namelen is set to the size of the peer name copied. If the buffer is too small, the peer name is truncated.
The getpeername() call operates only on connected sockets. If the connection is through a SOCKS server, the address returned will be that of the SOCKS server.
A process can use the getsockname() call to retrieve the local address of a socket.
Return Values
The value 0 indicates success; the value -1 indicates an error. You can get the specific error code by calling sock_errno() or psock_errno().
Error Code
Related Calls