bindresvport(3)
β¨ bindresvport β¨
okay bestie, we're looking at bindresvport(3) from the Library Functions Manual and honestly? it's giving "tiny function, big privileges" π
π NAME π
bindresvport β bind a socket to a privileged IP port π
π LIBRARY π
Standard C library (libc, -lc) π«Ά
π¦ SYNOPSIS π¦
#include <sys/types.h>
#include <netinet/in.h>
int bindresvport(int sockfd, struct sockaddr_in *sin);
π DESCRIPTION π
so bindresvport() is here to bind the socket that's referenced by the file descriptor sockfd to a privileged anonymous IP port β and by that we mean a port number that's just... arbitrarily selected from the range 512 to 1023. she picks for you, you don't pick for her, periodt β¨
if the bind(2) that bindresvport() performs actually goes through, and sin is not NULL, then sin->sin_port hands you back the port number that was actually allocated. slay π
now, sin can be NULL, in which case sin->sin_family is implicitly taken to be AF_INET. but lowkey there's a catch: in that case, bindresvport() has literally no way to return the port number actually allocated π. (you can still get that info later using getsockname(2), so it's not the end of the world bestie)
πΈ RETURN VALUE πΈ
- she returns
0on success π - otherwise
-1is returned, anderrnois set to indicate the error π
π ERRORS π
bindresvport() can fail for any of the same reasons as bind(2). on top of that, these errors can also happen:
EACCESβ the calling process was not privileged. (on Linux specifically: the calling process did not have theCAP_NET_BIND_SERVICEcapability in the user namespace governing its network namespace.) not me getting denied at the door πEADDRINUSEβ all privileged ports are in use. every single one. she's booked, fully, no vacancy πEAFNOSUPPORT(EPFNOSUPPORTin glibc 2.7 and earlier) βsinis notNULLandsin->sin_familyis notAF_INET. wrong family, we don't serve that here π«
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7). here's the vibe check:
- Interface:
bindresvport() - Attribute: Thread safety
- Value:
glibc >= 2.17: MT-Safe;glibc < 2.17: MT-Unsafe
and the lore behind that: the bindresvport() function uses a static variable that was not protected by a lock before glibc 2.17, which made the function MT-Unsafe. she was messy before the glow-up, ngl π
β VERSIONS β
present on the BSDs, Solaris, and many other systems. she gets around, iconic behavior π
π§ NOTES π§
unlike some bindresvport() implementations, the glibc implementation ignores any value that the caller supplies in sin->sin_port. like... she didn't ask, she doesn't care, she chooses π
π STANDARDS π
BSD.
π₯ SEE ALSO π₯
fr fr, that's the whole page. go bind something privileged, but stay safe out there π β¨
signing off with the receipts: this is Linux man-pages 6.20, dated 2026-02-08, and you were reading bindresvport(3) ππ¦πΈ
π¦ 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: Linux-man-pages-copyleft
- Copyright 2007, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms