getsockname(2)
โจ getsockname(2) โจ
okay so bestie, this is the getsockname page from the System Calls Manual โ section 2, system calls, iykyk ๐
. It's the one that tells you what name your socket is currently wearing. Let's get into it ๐ซถ
๐ NAME ๐
getsockname โ get socket name โจ
๐ LIBRARY ๐
Standard C library (libc, -lc) โ she lives in libc, no cap ๐
๐ธ SYNOPSIS ๐ธ
#include <sys/socket.h>
int getsockname(int sockfd, struct sockaddr *restrict addr,
socklen_t *restrict addrlen);
there she is ๐ note those restrict qualifiers, they're doing real work, we respect them ๐
๐ DESCRIPTION ๐
okay so getsockname() returns the current address that the socket sockfd is bound to, and it drops it into the buffer pointed at by addr. it's giving "who am I, really" โจ
The addrlen argument? You gotta initialize it yourself to say how much space (in bytes) you've got at the address pointed to by addr. Then, on return, it holds the actual size of the socket address โ so it may come back different than you sent it. main character energy, honestly ๐
So the returned address gets truncated if the buffer you handed over is too small. And in that case, addrlen will return a value greater than what you supplied to the call โ that's how you know you got cut off ๐ญ plan your buffer accordingly babes.
๐ฅ RETURN VALUE ๐ฅ
- On success: zero is returned. slay โจ
- On error: -1 is returned, and
errnogets set to tell you which error it was. not the vibe ๐
๐ ERRORS ๐
EBADFโ thesockfdargument is not a valid file descriptor ๐EFAULTโ the addr argument points to memory that isn't in a valid part of the process address space. off the map, literally ๐บ๏ธ๐EINVALโaddrlenis invalid, like for example it's negative. girl. negative bytes?? ๐ญENOBUFSโ insufficient resources were available in the system to perform the operation ๐ฅฒ the system was simply not serving todayENOTSOCKโ the file descriptorsockfddoes not refer to a socket. it's giving impostor ๐ซ
๐ STANDARDS ๐
POSIX.1-2024. periodt ๐
๐ฆ HISTORY ๐ฆ
POSIX.1-2001, SVr4, 4.2BSD. she's been around, she's iconic, she's seen things ๐
๐ SEE ALSO ๐
bind(2), socket(2), getifaddrs(3), ip(7), socket(7), unix(7)
and that's the whole page bestie, go check your socket's name, she deserves to be seen ๐ธ know your bind, own your bind ๐
this has been Linux man-pages 6.20, dated 2025-10-29 โ mwah, sending you the biggest hug, now go read bind(2) next, mwah ๐โจ
๐ฆ where this page comes from
- 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 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1983-1991, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms