socket_connect6(3)
π socket_connect6(3) β bestie's guide to making a TCP connection π
okay so real talk, this one lives in the Library Functions Manual and it's genuinely one of the most useful little gremlins in libowfat/socket.h. sit with me, we're doing this together π«Ά
β¨ NAME β¨
socket_connect6 β attempt to make a TCP connection
like, that's it, that's the whole job. it tries to connect. no cap. π₯
πΈ SYNTAX πΈ
#include <libowfat/socket.h>
int socket_connect6(int s, const char ip[16],
uint16 port,uint32 scope_id);
four args, one int out, slay π
π¦ DESCRIPTION π¦
okay so socket_connect6 attempts to make a connection from TCP socket s to TCP port port on IP address ip. that's the whole vibe. simple. iconic.
Now. The meaning of scope_id is dependent on the implementation and the IPv6 IP. On link-local IPv6 addresses it specifies the outgoing interface index. The name (e.g. "eth0") for a given interface index can be queried with getifname. scope_id should normally be set to 0. normally!! don't be extra about it π
socket_connect6 may return
0β to indicate that the connection succeeded (and succeeded immediately, if the socket is non-blocking) β¨-1, settingerrnotoerror_inprogressorerror_wouldblock, to indicate that the socket is non-blocking π-1, settingerrnoto something else, to indicate that the connection failed (and failed immediately, if the socket is non-blocking). π
When a background connection succeeds or fails, s becomes writable; you can use socket_connected to see whether the connection succeeded. If the connection failed, socket_connected returns 0, setting errno appropriately.
Once a TCP socket is connected, you can use the read and write system calls to transmit data. yes bestie, that's the payoff, that's the main character moment π
You can call socket_connect6 without calling socket_bind6. This has the effect as first calling socket_bind6 with IP address :: and port 0. so it just handles it for you, lowkey thoughtful of it π
π EXAMPLE π
#include <libowfat/socket.h>
int s;
char ip[16];
uint16 p;
s = socket_tcp6();
socket_bind6(s,ip,p);
socket_connect6(s,ip,p,0);
look at that. clean. no notes. π
π SEE ALSO π
go read these next, iykyk π
okay bye my love π«Ά this was socket_connect6(3) straight out of the Library Functions Manual, and yeah, that's the same socket_connect6(3) you see at the bottom of the page β periodt. πβ¨πΈπ¦
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms