getpeername(2) System Calls Manual getpeername(2) NOME getpeername - get name of connected peer socket BIBLIOTECA Biblioteca C Padrao (libc, -lc) SINOPSE #include int getpeername(int sockfd, struct sockaddr *restrict addr, socklen_t *restrict addrlen); DESCRICAO 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 endereco retornado e 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 e retornado. Em caso de erro, -1 e retornado, e errno e definido para indicar o erro. ERROS EBADF O argumento sockfd nao e um descritor de arquivo valido. EFAULT O argumento addr aponta para memoria que nao esta em uma parte valida do espaco de endereco de processo. EINVAL addrlen e invalido (por exemplo, e negativo). ENOBUFS Recursos insuficientes no seu sistema para completar a operacao. ENOTCONN O 'socket' nao esta conectado. ENOTSOCK O descritor de arquivo sockfd nao faz referencia a um socket. PADROES POSIX.1-2024. HISTORICO 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 TAMBEM accept(2), bind(2), getsockname(2), ip(7), socket(7), unix(7) TRADUCAO A traducao para portugues brasileiro desta pagina man foi criada por Andre Luiz Fassone e Ricardo C.O.Freitas Esta traducao e uma documentacao livre; leia a Licenca Publica Geral GNU Versao 3 ou posterior para as condicoes de direitos autorais. Nenhuma responsabilidade e aceita. Se voce encontrar algum erro na traducao desta pagina de manual, envie um e-mail para a lista de discussao de tradutores . Linux man-pages 6.18 29 outubro 2025 getpeername(2)