socket_connect4(3)
π socket_connect4 β bestie's guide to saying "hey" over TCP π
okay so you wanna know about socket_connect4, from the Library Functions Manual, section 3. It's a libowfat thing and honestly? It's giving "let me introduce you to somebody." Sit down, hydrate, let's go. π«Ά
β¨ NAME β¨
socket_connect4 β attempt to make a TCP connection π
πΈ SYNTAX πΈ
#include <libowfat/socket.h>
int socket_connect4(int s,const char ip[4],uint16 port);
no cap, that's the whole signature. s is your TCP socket, ip is a 4-byte address, port is a uint16. that's it bestie. π
π¦ DESCRIPTION π¦
So like β socket_connect4 attempts to make a connection from TCP socket s to TCP port port on IP address ip. Simple. Iconic. A matchmaker for sockets. π₯
Now the part you actually need to internalise: socket_connect4 may return a few different things, and each one is a whole mood. π
0β this means the connection succeeded, and it succeeded immediately if the socket is non-blocking. slay.-1, witherrnoset toerror_inprogressorerror_wouldblockβ this is the "it's not a no, it's a not-yet" outcome. It means the socket is non-blocking. the connection is still out there doing its thing.-1, witherrnoset to something else β this means the connection failed (and it failed immediately, if the socket is non-blocking). π
Heads up bestie: those last two both look like-1from the outside, so the way you tell "still cooking" apart from "it's over" is by checkingerrno. Don't skip that step, I'm begging. π
When a background connection succeeds or fails, s becomes writable. So that's your cue to check in. You can use socket_connected to see whether the connection actually succeeded. And 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. yep, the normal ones. the classics. π
And here's a cute lil flex: you can call socket_connect4 without calling socket_bind4. That has the effect as first calling socket_bind4 with IP address 0.0.0.0 and port 0. So like, the universe just handles it for you. π
π EXAMPLE π
copy this, it's cute:
#include <libowfat/socket.h>
int s;
char ip[4];
uint16 p;
s = socket_tcp4();
socket_bind4(s,ip,p);
socket_connect4(s,ip,p);
π SEE ALSO π
socket_connect6(3)β for when your bestie has a 128-bit address πΈsocket_fastopen_connect4(3)β the speedrun version β
okay so that's the whole page, mwah π This one is socket_connect4(3) β section 3 of the Library Functions Manual β and that's genuinely the whole footer situation, no version, no date stamp, so that's the receipt. go forth and connect, bestie, you're gonna eat π
β¨π
π¦ 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