GETPEERNAME(3POSIX)
π GETPEERNAME(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so first things first, bestie, this page lives in the POSIX Programmer's Manual (yes the whole manual, we're fancy here π ). But real talk: the Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. Or, plot twist, the interface might not even be implemented on Linux at all. π iykyk.
β¨ NAME β¨
getpeername β get the name of the peer socket. that's it, that's the whole job, and she does it flawlessly π
πΈ SYNOPSIS πΈ
#include <sys/socket.h>
int getpeername(int socket, struct sockaddr *restrict address,
socklen_t *restrict address_len);
π¦ DESCRIPTION π¦
So the way that getpeername() works is: it retrieves the peer address of the socket you specified, stores that address in the sockaddr structure pointed to by the address argument, and stores the length of that address in the object pointed to by the address_len argument. she's organized. she's thorough. we love her π«Ά
The address_len argument points to a socklen_t object, and this girly has two moods:
- on input, it specifies the length of the supplied
sockaddrstructure π± - on output, it specifies the length of the stored address β¨
and if the actual length of the address is greater than the length of the supplied sockaddr structure? the stored address shall be truncated. yeah. she's cutting it off. no cap. π
one lil edge case though: if the protocol permits connections by unbound clients, and the peer is not bound, then the value stored in the object pointed to by address is unspecified. lowkey mysterious of her but okay π
π₯ RETURN VALUE π₯
- if it ate and left no crumbs:
0shall be returned β - otherwise:
-1shall be returned, anderrnogets set to indicate the error π
π ERRORS π
The getpeername() function shall fail if:
EBADFβ the socket argument is not a valid file descriptor. like girl. that's not a real fd. πEINVALβ the socket has been shut down. she's gone, bestie, she's not coming back π₯ENOTCONNβ the socket is not connected or otherwise has not had the peer pre-specified. no connection, no peer, no vibe π§οΈENOTSOCKβ the socket argument does not refer to a socket. it's giving "that's not a socket" πEOPNOTSUPPβ the operation is not supported for the socket protocol. not every protocol is gonna serve you this, and that's on them π
The getpeername() function may fail if:
ENOBUFSβ insufficient resources were available in the system to complete the call. the system is tired. the system needs a nap. π΄
β¨ heads up bestie: the following sections are informative. not normative. informative. she's just chatting. π¬
π EXAMPLES π
None. nothing. empty. she said "figure it out" π
π APPLICATION USAGE π
None. literally none. iconic of her honestly. no notes. π
π§ RATIONALE π§
None. she simply did not feel like explaining herself. main character energy fr fr π
β FUTURE DIRECTIONS β
None. the future is undefined and so is this section. π
π SEE ALSO π
accept()bind()getsockname()socket()
plus, from the Base Definitions volume of POSIX.1β2017: <sys_socket.h> π
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! πβ¨ππ¦πΈπ π«Ά
signed off by IEEE/The Open Group, 2017 β yeah, the whole entire year, that's the date, we're keeping it ποΈβ¨ stay connected, stay valid, and always check your errno before you blame yourself, ily!! ππ
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms