getpeername()

Updated: April 19, 2023

Get the name of the peer connected to a socket

Synopsis:

#include <sys/socket.h>

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

Arguments:

s
The socket whose connected peer you want to get.
name
A buffer where the function can store the name of the peer.
namelen
A pointer to a socklen_t object that initially specifies the size of the buffer. This function stores the actual size of the name, in bytes, in this object.

Library:

libsocket

Use the -l socket option to qcc to link against this library.

Description:

The getpeername() function returns the name of the peer connected to socket s. The name is truncated if the buffer provided is too small.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EBADF
Invalid descriptor s.
EFAULT
The name parameter points to memory not in a valid part of the process address space.
ENOBUFS
Insufficient resources were available in the system to perform the operation.
ENOTCONN
The socket isn't connected.

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes