socket_bind6_reuse(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– socket_bind6_reuse β€” bestie's guide to claiming your IPv6 throne πŸ’–

okay so this one lives in section 3 of the Library Functions Manual, aka the part of the manual where we keep all the library function girlies. sit down, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

socket_bind6_reuse β€” set the local IP address and port of a socket

no cap, that's the whole vibe: you're telling a socket where it lives on the local machine.


🌸 SYNTAX 🌸

#include <libowfat/socket.h>

int socket_bind6_reuse(int s,char ip[16],uint16 port,
                       uint16 scope_id);

that's the whole signature, copy it exactly bestie, don't get cute with it πŸŽ€


πŸ’… DESCRIPTION πŸ’…

so socket_bind6_reuse sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip and port respectively. literally just: you give it the socket, it gives the socket an address. iconic.

if the IP address is ::, the operating system chooses a local IP address. if port is 0, the operating system chooses a port. so if you're feeling indecisive, the OS is your main character and will pick for you ✨

normally socket_bind6_reuse returns 0. if anything goes wrong, socket_bind6_reuse returns -1, setting errno appropriately. so like, check your return values, i'm begging 😭

the scope_id should normally be zero, but for link-local addresses it specifies the interface number on which to bind. the interface number for a given network interface name can be found with socket_getifidx. so if you're doing link-local stuff, that's your girl πŸ’œ

unlike socket_bind6 this function will also tell the operating system that the address is to be reused soon, which turns off the normal pause before this IP and port can be bound again. that's the whole point of the _reuse in the name β€” it skips the little cooldown period. no waiting around, we hate waiting πŸ’€

heads up bestie: "reuse soon" means you're telling the kernel the address is coming back fast. that's the feature, that's why you'd pick this over socket_bind6. don't be surprised when the normal pause just… isn't there.

🌈 EXAMPLE 🌈

#include <libowfat/socket.h>

int s;
char ip[16];
uint16 p;

s = socket_tcp4();
socket_bind6_reuse(s,ip,p);
socket_connect4(s,ip,p);

look at her go. make a socket, bind it with the reuse energy, then connect. simple, clean, slay πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page fr fr. this one comes to you courtesy of the Library Functions Manual, section 3 β€” the socket_bind6_reuse(3) energy, immortalized forever. go bind something responsibly, bestie πŸ’–βœ¨πŸŽ€πŸ«Ά