GETPEERNAME(3P)
๐ GETPEERNAME ๐
okay bestie, so this one's from the POSIX Programmer's Manual โ specifically the GETPEERNAME(3P) page, she's a 3P girlie. ๐
quick lil heads up before we dive in: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the actual Linux tea), or the interface may not be implemented on Linux at all. ๐
โจ NAME โจ
getpeername โ get the name of the peer socket ๐ซถ
๐ธ SYNOPSIS ๐ธ
#include <sys/socket.h>
int getpeername(int socket, struct sockaddr *restrict address,
socklen_t *restrict address_len);
๐ฆ DESCRIPTION ๐ฆ
so like. getpeername() shall retrieve the peer address of the specified socket, store this address in the sockaddr structure pointed to by the address argument, and store the length of this address in the object pointed to by the address_len argument. that's the whole gig, no cap. ๐
the address_len argument points to a socklen_t object which โ on input โ specifies the length of the supplied sockaddr structure, and on output 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. ๐ญ (she's getting cut off mid-sentence, tragic.)
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. so like, don't come for her about it, she literally told you it's unspecified. ๐
โญ RETURN VALUE โญ
upon successful completion, 0 shall be returned. otherwise, -1 shall be returned and errno set to indicate the error. that's it that's the vibe check. ๐
๐ฅ ERRORS ๐ฅ
getpeername() shall fail if:
EBADFโ thesocketargument is not a valid file descriptor. ๐EINVALโ the socket has been shut down. ๐ENOTCONNโ the socket is not connected or otherwise has not had the peer pre-specified. not connected bestie, it's giving ghosted. ๐ปENOTSOCKโ thesocketargument does not refer to a socket. wrong kind of girl entirely. ๐ญEOPNOTSUPPโ the operation is not supported for the socket protocol. she said no. ๐
getpeername() may fail if:
ENOBUFSโ insufficient resources were available in the system to complete the call. no room, no vibes. ๐ฅฒ
also, just so you know: the following sections are informative. so they're like, the commentary track, not the main event. ๐ฌ
๐ EXAMPLES ๐
None. โ literally nothing here, she's an empty page. โจ
๐ APPLICATION USAGE ๐
None. โ nope, nada, still nothing. ๐ธ
๐ RATIONALE ๐
None. โ she didn't feel like explaining herself. iconic honestly. ๐
๐ง FUTURE DIRECTIONS ๐ง
None. โ the future is unwritten and she has no notes. ๐ฎ
๐ SEE ALSO ๐
accept()bind()getsockname()socket()
and also โ 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 .
k bye bestie, that's the whole page ๐โจ IEEE/The Open Group, 2017, GETPEERNAME(3P) โ go read your socket's name, she's been waiting ๐ซถ๐
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms