qlibs:(socket_bind)

πŸ“¦ version 31, in alpine 3.24

πŸ’– socket_bind πŸ’–

okay so bestie, welcome to the qlibs:(socket_bind) page β€” the one where we bind a TCP/UDP socket to a local IP address, port, and maybe a scope_id ✨. It's giving "plumbing but make it cute," and honestly the system calls ate. πŸ’…

πŸŽ€ NAME πŸŽ€

socket_bind β€” binding a TCP/UDP socket to a local IP address, port, and perhaps scope_id πŸ‘€.

✨ SYNTAX ✨

here's the whole squad, signature-for-signature, no edits, no cap:

#include "socket_if.h"

int socket_bind4(int s,char ip[4],uint16 port);
int socket_bind4_reuse(int s,char ip[4],uint16 port);

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

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

πŸ¦‹ DESCRIPTION πŸ¦‹

  • socket_bind4 β€” sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip and port respectively. iconic, straightforward, no notes. πŸ’…
  • socket_bind4_reuse β€” sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip and port respectively. Unlike socket_bind4, 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. so impatient, so slay. πŸ”₯
  • socket_bind6 β€” sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively. v6 girlies rise. 🌈
  • socket_bind6_reuse β€” sets the local IP address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively. 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. periodt. πŸ’–
  • socket_bind β€” sets the local IPv4/IPv6 address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively. for IPv4 and IPv4-mapped IPv6 addresses, socket_bind will use socket_bind4 or otherwise socket_bind6. it's giving switch-up main character energy. πŸ¦‹
  • socket_bind_reuse β€” sets the local IPv4/IPv6 address and TCP/UDP port of a TCP/UDP socket s to ip, port, and scope_id respectively. Unlike socket_bind, 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. for IPv4 and IPv4-mapped IPv6 addresses, socket_bind_reuse will use socket_bind4_reuse or otherwise socket_bind6_reuse. reuse era, obsessed. 🫢

🌸 AUTOMATIC BINDING 🌸

If the IPv4 address is 0 or the IPv6 address is ::, the operating system chooses a local IP address. If port is 0, the operating system chooses a port. scope_id is usually 0, except for IPv6 LLU addresses where socket_getifidx can be used to determine scope_id from the interface name. auto-pilot vibes only. ✨

⭐ RETURN CODES ⭐

Normally, all socket_bind* routines return 0. If anything goes wrong, the return code is -1 and setting errno appropriately. so if you see -1, that's your cue to check errno, bestie 😭.

πŸŽ€ EXAMPLE πŸŽ€

copy this one exactly, including the exact spelling lcoalip β€” character-for-character, bestie 🫢:

         #include <socket_if.h>
         #include <ip.h>

         int s;
         char lcoalip[16];
         char remoteip[16];
         uint16 p = 0;
         uint32 scope_id = 0;

         if (ip6_isv4mapped(ip))
           s = socket_tcp4();
         else
           s = socket_tcp6();
         if (s == -1)
           err_tmp(111,"unable to create TCP socket: ");

         socket_connect(s,remoteip,p,scope_id);

πŸ’œ SEE ALSO πŸ’œ

go be nosy with socket_if(3), socket_connect(3), socket_info(3), socket_recv(3), socket_send(3), socket_setup(3), socket_tcp(3), and socket_udp(3) πŸ’…βœ¨


xoxo, qlibs:(socket_bind) β€” section 3, signing off πŸ’–πŸ«Άβœ¨ (date not printed on this footer, bestie, but the section + name are right here 😌)

πŸ“¦ where this page comes from