getpeername.2 (2010 09)

g
getpeername(2) getpeername(2)
NAME
getpeername - get address of connected peer
SYNOPSIS
#include <sys/socket.h>
AF_CCITT Only
#include <x25/x25addrstr.h>
int getpeername(int s, void *addr, int *addrlen);
UNIX 03 Only (X/Open Sockets)
int getpeername(
int s,
struct sockaddr *__restrict addr,
socklen_t *__restrict addrlen
);
Obsolescent UNIX 95 Only (X/Open Sockets)
int getpeername(int s, struct sockaddr *addr, size_t *addrlen);
DESCRIPTION
getpeername() returns the address of the peer socket connected to the socket indicated by s, where s
is a socket descriptor. addr points to a socket address structure in which this address is returned.
addrlen points to a variable that should be initialized to indicate the size of the address structure. On
return, the variable contains the actual size of the address returned (in bytes). If addr does not point to
enough space to contain the whole address of the peer, only the first addrlen bytes of the address are
returned.
AF_CCITT Only
The addr struct contains the X.25 addressing information of the remote peer socket connected to socket s.
However, the
x25ifname[] field of the addr struct contains the name of the local X.25 interface
through which the call arrived.
X/Open Sockets Compilation Environment
See xopen_networking(7).
RETURN VALUE
Upon successful completion,
getpeername()
returns 0; otherwise it returns 1 and sets errno to
indicate the error.
ERRORS
getpeername() fails if any of the following conditions are encountered:
[EBADF] s is not a valid file descriptor.
[ENOTSOCK] s is a valid file descriptor, but it is not a socket.
[ENOTCONN] The socket is not connected.
[ENOBUFS] No buffer space is available to perform the operation.
[EFAULT] addr or addrlen are not valid pointers.
[EINVAL] The socket has been shut down.
[EINTR] The operation was interrupted by a signal. Application needs to retry the operation
to get the address of peer socket.
Not all possible
errno values are documented in this manpage due to dependencies from the underlying
protocol modules.
OBSOLESCENCE
Currently, the
socklen_t and size_t types are the same size. This is compatible with the UNIX 95
and UNIX 03 profiles. However, in a future release, socklen_t might be a different size. In that case,
passing a size_t pointer will evoke compile-time warnings, which must be corrected in order for the
application to behave correctly. Applications that use socklen_t now, where appropriate, will avoid
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)