The getpeername() function retrieves the peer address of the specified socket, stores this address in the sockaddr structure pointed to by the address argument, and stores the length of this address in the object pointed to by the address_len argument.
int getpeername(int socket, struct sockaddr *address,socklen_t *address_len);
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.
http://pubs.opengroup.org/onlinepubs/7908799/xns/getpeername.html