get address of connected peer
cc [options] file -lsocket -lnsl
int getpeername(int socket, struct sockaddr *name, size_t *namelen);
returns the address of the peer connected to socket
pointed to by the
parameter should be initialized to indicate
the amount of space pointed to by
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.
0 is returned if the call succeeds, -1 if it fails.
The call succeeds unless:
socket is not a valid descriptor.
The socket has been shut down.
System resources were insufficient to complete the call.
There was insufficient user memory for the operation to complete.
There were insufficient STREAMS
resources available for the operation to complete.
The socket is not connected, or otherwise has not had the peer prespecified.
socket not a socket.
The operation is not supported for the socket protocol.
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
Internet domain IPv6 sockets (address family AF_INET6)
require a sockaddr_in6 structure as defined in
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
and pass the size of the structure in the namelen argument.
In UnixWare 7 the sockaddr structure has been modified
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:
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004