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 โ€” the socket argument 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 โ€” the socket argument 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> ๐Ÿ“š


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