Get the name of the peer connected to a socket
#include <sys/socket.h>
int getpeername( int s,
struct sockaddr * name,
socklen_t * namelen );
- 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.
libsocket
Use the -l socket option to
qcc
to link against this library.
The getpeername() function returns the name of
the peer connected to socket s.
The name is truncated if the buffer provided is too small.
- 0
- Success.
- -1
- An error occurred
(errno
is set).
- 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.
POSIX 1003.1
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
accept(),
bind(),
getsockname(),
socket()