qlibs:(socket_setup)
π NAME π
socket_setup β listen to or accept socket for incoming TCP connections
okay so welcome to the qlibs:(socket_setup) page, bestie π
this is the one about getting your TCP socket ready to listen and then actually accepting the connection. no cap, it's giving networking main character energy π¦
πΈ SYNTAX πΈ
#include "socket_if.h"
int socket_listen(int s,int n);
int socket_accept(int s,char ip[16],
uint16 *port,uint32 *scope_id);
int socket_ipoptionskill(int s);
int socket_ip6anycast((int s);
int socket_dualstack(int s);
int socket_nodualstack(int s);
β¨ DESCRIPTION β¨
socket_listenβ prepares TCP socketsto accept TCP connections. It allows a backlog of approximatelynTCP SYNs. On systems supporting SYN cookies, the backlog is irrelevant β iconic caveat, bestie β¨socket_acceptβ accepts the connection. It creates a new socket for the connection and returns a file descriptor pointing to the new socket; you can use thereadandwritesystem calls to transmit data through that file descriptor. It also gives you info about the client's ip address and TCP port number, perhaps together with local receiving interfacescope_idπsocket_ipoptionskillβ used to disable previously defined options in IPv4 or IPv6 packets like Source Routing prior to using this socket for data exchange. It uses thesetsockoptπsocket_ip6anycastβ enables unspecified reversed anycasting on the listening socketswith IPv6 address::. Upon receiving IPv6 packets, the socket records the incoming IPv6 address and the receivingscope_idin order to provide additional routing information π¦socket_dualstackandsocket_nodualstackβ can be used to force or forbid dual-stack behavior by setting thesetsockoptvariableIPV6_V6ONLYappropriately. In the last case, a potential servers needs two instances to accept incoming IPv6 and IPv6 packets β yes, that's exactly the energy of that line, bestie π
π₯ RETURN CODES π₯
Normally socket_listen, socket_accept and socket_ipotionskill β yep, that's the exact spelling in this line of the source, typo and all π β as well as socket_dualstack and socket_nodualstack return 0. If anything goes wrong, they return -1, setting errno appropriately.
π EXAMPLE π
here's the example, copied exactly, no edits, no extra sparkle inside the code block π
#include <socket_if.h>
int s, t;
int r;
char ip[16];
uint16 p;
if ((s = socket_tcp()) == -1)
err_tmp("",111,"unable to create TCP socket: ");
r = socket_ipoptionskill(s);
if (socket_bind_reuse(s,(char *)V6localnet,8002,0) == -1)
err_tmp("",111,"unable to bind: ");
if (socket_listen(s,1) == -1)
err_tmp("",111,"unable to listen: ");
t = socket_tcp();
socket_bind(t,ip,p,0);
socket_listen(s,16);
socket_accept(t,ip,&p,&scope_id);
π¦ SEE ALSO π¦
go read these too, bestie: socket_if(3), socket_bind(3), socket_connect(3), socket_info(3), socket_recv(3), socket_send(3), socket_tcp(3), socket_udp(3)
bestie, that's the whole qlibs:(socket_setup) page β source/version: qlibs, section 3; date: the original footer does not list one, so no invented date here, just vibes π«Άβ¨
π¦ 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