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 sockaddr structure
  • 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:

  • 0 shall be returned ⭐
  • the address argument shall point to the address of the socket
  • the address_len argument 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 β€” the socket argument is not a valid file descriptor.
  • ENOTSOCK β€” the socket argument 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> 🌸


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