| getpeername(2) | System Calls Manual | getpeername(2) |
NOME¶
getpeername - get name of connected peer socket
BIBLIOTECA¶
Biblioteca C Padrão (libc, -lc)
SINOPSE¶
#include <sys/socket.h>
int getpeername(int sockfd, struct sockaddr *restrict addr,
socklen_t *restrict addrlen);
DESCRIÇÃO¶
getpeername() returns the address of the peer connected to the socket sockfd, in the buffer pointed to by addr. The addrlen argument should be initialized to indicate the amount of space pointed to by addr. On return it contains the actual size of the name returned (in bytes). The name is truncated if the buffer provided is too small.
O endereço retornado é truncado se o buffer fornecido for pequeno demais; neste caspp, addrlen vai retornar um valor maior que o que foi fornecido para a chamada.
VALOR DE RETORNO¶
Em caso de sucesso, zero é retornado. Em caso de erro, -1 é retornado, e errno é definido para indicar o erro.
ERROS¶
- EBADF
- O argumento sockfd não é um descritor de arquivo válido.
- EFAULT
- O argumento addr aponta para memória que não está em uma parte válida do espaço de endereço de processo.
- EINVAL
- addrlen é inválido (por exemplo, é negativo).
- ENOBUFS
- Recursos insuficientes no seu sistema para completar a operação.
- ENOTCONN
- O 'socket' não está conectado.
- ENOTSOCK
- O descritor de arquivo sockfd não faz referência a um socket.
PADRÕES¶
POSIX.1-2024.
HISTÓRICO¶
POSIX.1-2001, SVr4, 4.4BSD (apareceu pela primeira vez em 4.2BSD).
NOTAS¶
For stream sockets, once a connect(2) has been performed, either socket can call getpeername() to obtain the address of the peer socket. On the other hand, datagram sockets are connectionless. Calling connect(2) on a datagram socket merely sets the peer address for outgoing datagrams sent with write(2) or recv(2). The caller of connect(2) can use getpeername() to obtain the peer address that it earlier set for the socket. However, the peer socket is unaware of this information, and calling getpeername() on the peer socket will return no useful information (unless a connect(2) call was also executed on the peer). Note also that the receiver of a datagram can obtain the address of the sender when using recvfrom(2).
VEJA TAMBÉM¶
accept(2), bind(2), getsockname(2), ip(7), socket(7), unix(7)
TRADUÇÃO¶
A tradução para português brasileiro desta página man foi criada por André Luiz Fassone <lonely_wolf@ig.com.br> e Ricardo C.O.Freitas <english.quest@best-service.com>
Esta tradução é uma documentação livre; leia a Licença Pública Geral GNU Versão 3 ou posterior para as condições de direitos autorais. Nenhuma responsabilidade é aceita.
Se você encontrar algum erro na tradução desta página de manual, envie um e-mail para a lista de discussão de tradutores.
| 29 outubro 2025 | Linux man-pages 6.17 |