BINDRESVPORT(3)
π BINDRESVPORT(3) β Library Functions Manual π
okay bestie so we're in section 3 of the library functions manual, and today's main character is bindresvport plus its equally iconic sibling bindresvport_sa. pull up a chair, we're binding sockets to privileged ports and it's giving root access energy β¨
β¨ NAME β¨
bindresvport, bindresvport_sa β bind a socket to a privileged IP port π
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <rpc/rpc.h>
int
bindresvport(int sd, struct sockaddr_in *sin);
int
bindresvport_sa(int sd, struct sockaddr *sa);
πΈ DESCRIPTION πΈ
so basically, bindresvport() and bindresvport_sa() are the girlies you call when you wanna bind a socket descriptor to a privileged IP port β and by privileged we mean a port number in the range 0-1023. yeah. the fancy zone. π
if sin is a pointer to a struct sockaddr_in, then bestie, you gotta define the appropriate fields in that structure yourself. and heads up: sin->sin_family must be initialized to the address family of the socket that's being passed in through sd. no skipping that step, it's not optional, iykyk.
if sin->sin_port is '0', then an anonymous port will be chosen β specifically one in the range 600-1023 β and if bind(2) succeeds, sin->sin_port gets updated to hold the allocated port. cute, right? it tells you what it picked. π«Ά
if sin is the NULL pointer, an anonymous port gets allocated too (same deal as above). but β and this is the sad part π β there is no way for bindresvport() to return that allocated port back to you in this case. it's gone. a mystery. we don't know her.
also only root can bind to a privileged port. literally just root. this call will fail for every other user, no exceptions, no cap.
now, the function prototype of bindresvport() is biased toward AF_INET sockets. the bindresvport_sa() function acts exactly the same, it just has a more neutral function prototype. and like β note that both functions behave exactly the same, and both support AF_INET6 sockets as well as AF_INET sockets. equal opportunity socket binding. periodt. π
π RETURN VALUES π
the bindresvport() function returns the value 0 if it's successful. otherwise, the value -1 is returned and the global variable errno is set to indicate the error. so like, check your errno, bestie, she's trying to tell you something.
π ERRORS π
[EPFNOSUPPORT]β if a second argument was supplied, and the address family did not match between the arguments. mismatched vibes. rejected. π
the bindresvport() function may also fail and set errno for any of the errors specified for the calls bind(2), getsockopt(2), or setsockopt(2). so if it's acting up, go read those pages too, they're the supporting cast.
π¦ AVAILABILITY π¦
the bindresvport() function is part of libtirpc. that's where she lives. π
β SEE ALSO β
and that's the whole page, bestie!! this lil masterpiece comes to you courtesy of Debian, dated November 22, 1987 β yes, 1987, she's an elder and she's still slaying π go bind something privileged (if you're root, otherwise, respectfully, no) πβ¨
π¦ where this page comes from
- alpine 3.22: libtirpc-doc 1.3.5-r0 Β· BSD-3-Clause
- alpine 3.23: libtirpc-doc 1.3.5-r1 Β· BSD-3-Clause
- alpine 3.24: libtirpc-doc 1.3.5-r1 Β· BSD-3-Clause
- arch rolling: libtirpc 1.3.8-1 Β· SISSL AND BSD-3-Clause
- centos-stream 10: libtirpc-devel 1.3.5-1.el10 Β· SISSL AND BSD-3-Clause
- centos-stream 9: libtirpc-devel 1.3.3-9.el9 Β· SISSL and BSD
- centos-stream 9: libtirpc-devel 1.3.3-9.el9 Β· SISSL and BSD
- debian bookworm: libtirpc-dev 1.3.3+ds-1 Β· BSD-3-Clause
- debian trixie: libtirpc-dev 1.3.6+ds-1 Β· BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-0.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-0.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-1.rc1.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-1.rc1.fc43 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.7-2.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.7-2.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.8-0.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.8-0.fc44 Β· SISSL AND BSD-3-Clause
- nixos 26.05: libtirpc 1.3.7
- nixpkgs unstable: libtirpc 1.3.7
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- ubuntu jammy: libtirpc-dev 1.3.2-2build1 Β· BSD-3-Clause
- ubuntu jammy: libtirpc-dev 1.3.2-2ubuntu0.1 Β· BSD-3-Clause
- ubuntu noble: libtirpc-dev 1.3.4+ds-1.1build1 Β· BSD-3-Clause
- ubuntu questing: libtirpc-dev 1.3.6+ds-1
- ubuntu resolute: libtirpc-dev 1.3.7-0.1 Β· BSD-3-Clause
- ubuntu stonking: libtirpc-dev 1.3.7+ds-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms