The getpeername() call returns the name of the peer connected
to socket descriptor s. For AF_IUCV, namelen must be initialized to reflect the size
of the space pointed to by name; it is set
to the number of bytes copied into the space before the call returns.
For AF_INET, the input value in the contents of namelen is ignored, but is set before the call returns. The size
of the peer name is returned in bytes. If the buffer of the local
host is too small to receive the entire peer name, the name is truncated.
#include <manifest.h>
#include <bsdtypes.h>
#include <socket.h>
int getpeername(int s, struct sockaddr *name, int *namelen)
- Parameter
- Description
- s
- The socket descriptor.
- name
- Points to a structure containing the internet address of the connected
socket that is specified by getpeername() before
it returns. The exact format of name is determined by the domain in which communication
occurs.
- namelen
- Points to a fullword containing the size of the address structure
pointed to by name in bytes.
Return values
The value 0 indicates success;
the value -1 indicates an error. Errno identifies the specific error.
- Errno
- Description
- EBADF
- The s parameter is not a valid socket
descriptor.
- EFAULT
- Using the name and namelen parameters as specified would result in an attempt to access
storage outside of the caller address space.
- ENOTCONN
- The socket is not in the connected state.
Related calls
accept(), connect(), getsockname(),
socket()