getpeername()

get name of peer connected to socket 

Function


SYNOPSIS

#include <sys/socket.h>

int getpeername(int s, struct sockaddr *name, socklen_t *namelen);


DESCRIPTION

The getpeername() routine gets the name of the peer connected to the socket s and stores it in the struct sockaddr, pointed to by name. It is used on a connected datagram or stream socket.

Upon return, the namelen parameter contains the actual size of the name returned in bytes.


PARAMETERS

s 

Is a descriptor that identifies a connected socket.

name 

Points to the structure that is to receive the name of the peer.

namelen 

Indicates, initially, the amount of space pointed to by name. Upon return, it contains the actual size, in bytes, of the returned name.


RETURN VALUES

If successful, getpeername() returns a value of zero. On failure, it returns a value of -1 and sets errno to one of the following values:

EFAULT 

name is an invalid pointer or namelen parameter is not large enough.

ENETDOWN 

The network subsystem failed.

ENOTCONN 

The socket is not connected.

ENOTSOCK 

The descriptor is not a socket.

EBADF 

s is not a valid descriptor.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
accept(), bind(), getsockname(), socket()


PTC MKS Toolkit 10.4 Documentation Build 39.