#include <sys.socket.h>
#include <netinet.in.h> /* nur bei AF_INET und AF_INET6 */
#include <iso.h> /* nur bei AF_ISO */
Kernighan-Ritchie-C:
int getpeername(s, name, namelen);
int s;
int *namelen;
struct sockaddr_in *name; /* only for AF_INET */
struct sockaddr_in6 *name; /* only for AF_INET6 */
struct sockaddr_iso *name; /* only for AF_ISO */
ANSI-C:
int getpeername(int s, struct sockaddr* name, int* namelen);
Description
The getpeername() function returns the name of the communications partner connected to socket s in the name parameter.
name points to a memory area. After getpeername() has been executed successfully, *name contains the name (address) of the communications partner.
The integer variable to which the namelen parameter points must be assigned the maximum possible address length (in bytes) before getpeername() is called. After the function returns, *namelen contains the current size of the returned name in bytes.
Return value
0:
If successful.
-1:
If errors occur. errno is set to indicate the error.
Errors indicated by errno
EBADF
The s parameter is not a valid descriptor.
EFAULT
The length of the area for accepting the address is too small.
ENOBUFS
There is not enough storage space in the buffer.
ENOTCONN
The socket has no connection.
EOPNOTSUPP
Socket s is not of type SOCK_STREAM, and the operation is not supported for the socket type of s.
See also
accept(), bind(), getsockname(), socket()