getpeername

Returns the address of a connected peer.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <sys/socket.h> 
     
  int getpeername (
     int                s,
     struct sockaddr   *addr,
     size_t            *len);
  

Parameters

s

(IN) Specifies the socket file handle connected to the peer for which the addr argument is to be returned.

addr

(OUT) Points to the location of the address for the peer connected to the socket. For IPv4, addr points to a sockaddr structure; for IPv6, to a sockaddr_in6 structure. The first two bytes in the structures identify the protocol family, and hence the structure.

len

(OUT) Points to the size of the address pointed to by addr.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The socket parameter is not a valid socket file handle.

38

ENOTSOCK

The socket parameter is not a valid socket file handle.

55

ENOBUFS

Insufficient resources were available in the system to perform the operation.

57

ENOTCONN

The socket is not connected.

Remarks

The address is truncated if the buffer is too small.