getpeername(SSC)
getpeername --
get address of connected peer
Synopsis
cc [options] file -lsocket -lnsl
#include <sys/types.h>
#include <sys/socket.h>
int getpeername(int socket, struct sockaddr *name, size_t *namelen);
Description
getpeername
returns the address of the peer connected to socket
s.
The
int
pointed to by the
namelen
parameter should be initialized to indicate
the amount of space pointed to by
name.
On return it contains the actual size of the address
returned (in bytes).
The name is truncated if the buffer provided is too small.
If the protocol allows unbound clients to connect, and the peer is not
bound, getpeername sets the value pointed to by
namelen to 0, and puts nothing in the
struct sockaddr pointed to by name.
Files
/usr/lib/locale/locale/LC_MESSAGES/uxns1
Return values
0 is returned if the call succeeds, -1 if it fails.
Errors
The call succeeds unless:
EBADF-
socket is not a valid descriptor.
EINVAL-
The socket has been shut down.
ENOBUFS-
System resources were insufficient to complete the call.
ENOMEM-
There was insufficient user memory for the operation to complete.
ENOSR-
There were insufficient STREAMS
resources available for the operation to complete.
ENOTCONN-
The socket is not connected, or otherwise has not had the peer prespecified.
ENOTSOCK-
socket not a socket.
EOPNOTSUPP-
The operation is not supported for the socket protocol.
References
accept(SSC),
bind(SSC),
getsockname(SSC),
socket(SSC)
RFC 2133
Notices
The type of address structure passed to getpeername
depends on the address family.
UNIX® domain sockets (address family AF_UNIX) require a
sockaddr_un structure as defined in sys/un.h;
Internet domain IPv4 sockets (address family AF_INET)
require a sockaddr_in structure as defined in
netinet/in.h;
Internet domain IPv6 sockets (address family AF_INET6)
require a sockaddr_in6 structure as defined in
netinet/in.h.
Other address families may require other structures.
Use the structure appropriate to the address family; cast the
structure address to a generic struct sockaddr * in the call to
getpeername
and pass the size of the structure in the namelen argument.
The sockaddr structure has been modified from previous releases
to support variable length sockets.
The net result of this modification is that the
family
member has been shortened to 8 bits and a new 8-bit
member inserted before it called len
. For more information on the new
sockaddr structures, see:
unix(ADMP)
and
inet(ADMP).
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005