GETSOCKNAME(3P)
π GETSOCKNAME(3P) β the POSIX Programmer's Manual, bestie edition π
okay so real talk first: this page lives in the POSIX Programmer's Manual, and there's a whole PROLOG situation you need to know about before we go any further.
β οΈ Heads up babes: the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for details on Linux behavior), or the interface may not be implemented on Linux at all. iykyk. π«Ά
β¨ NAME β¨
getsockname β get the socket name π
πΈ SYNOPSIS πΈ
#include <sys/socket.h>
int getsockname(int socket, struct sockaddr *restrict address,
socklen_t *restrict address_len);
π DESCRIPTION π
okay so what is getsockname() actually doing? she's retrieving the locally-bound name of the specified socket, that's her whole job. she stores this address in the sockaddr structure pointed to by the address argument, and she stores the length of this address in the object pointed to by the address_len argument. two outputs, one call, she's efficient like that. π
now, the address_len argument points to a socklen_t object, and she's got main character energy in both directions:
- on input β it specifies the length of the supplied
sockaddrstructure - on output β it specifies the length of the stored address
and here's the plot twist: if the actual length of the address is greater than the length of the supplied sockaddr structure, the stored address shall be truncated. π not ideal but that's the rule.
also important, no cap: if the socket has not been bound to a local name, the value stored in the object pointed to by address is unspecified. like, genuinely unspecified. don't come for her about it. π
π₯ RETURN VALUE π₯
upon successful completion:
0shall be returned β- the
addressargument shall point to the address of the socket - the
address_lenargument shall point to the length of the address
otherwise? -1 shall be returned and errno set to indicate the error. we love a clean failure signal. π
π ERRORS π
the ones where she shall fail π€
EBADFβ thesocketargument is not a valid file descriptor.ENOTSOCKβ thesocketargument does not refer to a socket.EOPNOTSUPPβ the operation is not supported for this socket's protocol.
the ones where she may fail π«
EINVALβ the socket has been shut down.ENOBUFSβ insufficient resources were available in the system to complete the function.
btw the following sections are informative β that's manpage speak for "chill, this part is extra". β¨
π¦ EXAMPLES π¦
None.
literally nothing here bestie, that's what it says. π
π APPLICATION USAGE π
None.
π§ RATIONALE π§
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
accept()bind()getpeername()socket()
also, 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, no crumbs left. π β¨ she was published in 2017 by IEEE/The Open Group, and her name is GETSOCKNAME(3P) β go get those socket names, you absolute icon. π«Άππ¦
π¦ 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