GETSOCKNAME(3POSIX)
π GETSOCKNAME β get the socket name π
okay bestie, real talk: this page lives in the POSIX Programmer's Manual (GETSOCKNAME(3POSIX)), and it's the whole "who am I, actually?" moment for your socket. Let's get into it π«Ά
β¨ PROLOG β¨
so like, heads up before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the real Linux tea β. And also? The interface may not be implemented on Linux at all. it's giving "spec vs. reality", 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 here's the vibe. The getsockname() function shall retrieve the locally-bound name 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. main character energy, honestly π
now, the address_len argument points to a socklen_t object which:
- on input β specifies the length of the supplied
sockaddrstructure - 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. not me shrinking your address to fit the fit π
β οΈ important caveat bestie: if the socket has not been bound to a local name, the value stored in the object pointed to by address is unspecified. so like, don't come for her, she never said she'd have an answer π
β 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. slay when it works, screaming when it doesn't π
π₯ ERRORS π₯
the getsockname() function shall fail if:
EBADFβ thesocketargument is not a valid file descriptor. bestie that's not even a socket, that's a vibe check you failed πENOTSOCKβ thesocketargument does not refer to a socket. it's giving "you brought the wrong thing to the party" πEOPNOTSUPPβ the operation is not supported for this socket's protocol. respectfully, not every protocol does this π«
the getsockname() function may fail if:
EINVALβ the socket has been shut down. she's done, she's logged off, don't @ her πENOBUFSβ insufficient resources were available in the system to complete the function. the system said "no thoughts, out of memory" π
π the following sections are informative. (i.e. they're the bonus content, not the rules, bestie)
π EXAMPLES π
None. literally nothing. empty. a void. ghosted β¨
π APPLICATION USAGE π
None. again, nothing here. the page said "no notes" π«Ά
π RATIONALE π
None. no reasoning given, she just IS. iconic behavior, honestly π
π§ FUTURE DIRECTIONS π§
None. the future is unwritten and also this section is empty π¦
π« SEE ALSO π«
accept()bind()getpeername()socket()
and also: the Base Definitions volume of POSIX.1β2017, <sys_socket.h> π
π COPYRIGHT π
okay so legal moment, but make it cute. 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. so like, the original is the one holding the mic π€
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 . (not me snitching on the converters, but also... yes me π)
and that's the whole page, bestie!! brought to you by IEEE/The Open Group, 2017, on the GETSOCKNAME(3POSIX) manual page. go get your socket's name and live your truth π
β¨π¦
π¦ 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