DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getpeername(3sock)


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(3sock), bind(3sock), getsockname(3sock), socket(3sock)

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.

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: unix(7sock) and inet(7tcp).


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004