socket_bind6(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 β€” bestie's guide to claiming your socket's home address πŸ’–

okay so real quick, this is a page from the Library Functions Manual (the socket_bind6(3) one, yes the 3 means it's a library function, iykyk) πŸŽ€

✨ NAME ✨

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

like... you're giving your socket an address. a little home. a vibe. 🏠✨


🌸 SYNTAX 🌸

#include <libowfat/socket.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So socket_bind6 sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip and port respectively. It's giving "this is where I live now" energy πŸ’…

  • If the IP address is ::, the operating system chooses a local IP address. Let the OS cook. πŸ‘‘
  • If port is 0, the operating system chooses a port. Also letting the OS cook. πŸ“

Normally socket_bind6 returns 0. It's chill like that. 😌 But if anything goes wrong, it returns -1 and sets errno appropriately β€” so go check errno, bestie, don't just sit there wondering. 😭

The scope_id should normally be zero, but for link-local addresses it specifies the interface number on which to bind. Basically: which network interface you're binding to. 🌈 And you can find the interface number for a given network interface name with socket_getifidx. bestie helping bestie fr fr 🫢


⭐ EXAMPLE ⭐

#include <libowfat/socket.h>

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

s = socket_tcp6();
socket_bind6(s,ip,p,scope_id);
socket_connect6(s,ip,p);

look at that. bind then connect. main character socket behavior. πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole thing!! this page is literally socket_bind6(3) and it's been iconic from top to bottom, no cap πŸ’–πŸ’œβœ¨