qlibs:(socket_bind)
π 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 socketstoipandportrespectively. iconic, straightforward, no notes. πsocket_bind4_reuseβ sets the local IP address and TCP/UDP port of a TCP/UDP socketstoipandportrespectively. Unlikesocket_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 socketstoip,port, andscope_idrespectively. v6 girlies rise. πsocket_bind6_reuseβ sets the local IP address and TCP/UDP port of a TCP/UDP socketstoip,port, andscope_idrespectively. Unlikesocket_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 socketstoip,port, andscope_idrespectively. for IPv4 and IPv4-mapped IPv6 addresses,socket_bindwill usesocket_bind4or otherwisesocket_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 socketstoip,port, andscope_idrespectively. Unlikesocket_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_reusewill usesocket_bind4_reuseor otherwisesocket_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
- alpine 3.24: fehqlibs-doc 31-r0 Β· Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms