GETSOCKNAME(2)
β¨ GETSOCKNAME(2) β¨
okay bestie, we're in the System Calls Manual section, and today's main character is getsockname β yes, that's the whole name, no notes π
πΈ NAME πΈ
getsockname β get socket name π
π LIBRARY π
Standard C Library (libc, -lc) β she lives in libc, as she should π
π¦ SYNOPSIS π¦
#include <sys/types.h>
#include <sys/socket.h>
int
getsockname(int s, struct sockaddr * restrict name,
socklen_t * restrict namelen);
β¨ DESCRIPTION β¨
so basically, the getsockname() system call returns the current name for the socket you point at. that's it, that's the vibe π
the namelen argument? you gotta initialize it first, bestie β it tells the system how much space name has to work with. and on return, it's been updated to hold the actual size of the name returned, in bytes. glow-up behavior fr fr β¨
π₯ RETURN VALUES π₯
getsockname() returns the value 0 if it's successful π«Ά otherwise it returns -1 and sets the global variable errno to indicate the error. no cap, that's just how she communicates π
π ERRORS π
the call succeeds unless β and girl, there are receipts:
[EBADF]β the argumentsis not a valid descriptor. not it. π«[ECONNRESET]β the connection has been reset by the peer. they hung up, literally π[EINVAL]β the value of thenamelenargument is not valid. π₯΄[ENOTSOCK]β the argumentsis a file, not a socket. wrong main character energy π[ENOBUFS]β insufficient resources were available in the system to perform the operation. the system said "i'm tired" π[EFAULT]β thenameargument points to memory not in a valid part of the process address space. lost in the void π
π SEE ALSO π
bind(2), getpeername(2), socket(2) β the whole friend group, go read them too π«Ά
π HISTORY π
the getsockname() system call appeared in 4.2BSD. vintage icon behavior, she's been serving since day one π
π BUGS π
names bound to sockets in the UNIX domain are inaccessible; getsockname() returns a zero length name.
so yeah, if you were expecting a name back, you're getting nothing. zero. the void. it's giving ghosted π
and that's the whole page, bestie β written on the Debian vibe, dated June 4, 1993, and filed under GETSOCKNAME(2) π
β¨ mwah, go call getsockname() responsibly π«Άπ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms