socket_recv4(3)
π socket_recv4(3) π
okay bestie, gather round, we're reading a man page from the Library Functions Manual (section 3, the library-call section, iykyk) and honestly? she's a little icon. it's socket_recv4, and she does exactly one thing and does it slayfully.
β¨ NAME β¨
socket_recv4 β receive a UDP datagram π¦
β¨ SYNTAX β¨
#include <libowfat/socket.h>
ssize_t socket_recv4(int s, char* buf, size_t len,
char ip[4],uint16* port);
yes the include is #include <libowfat/socket.h>, not just <socket.h>, do NOT come to me having forgotten the libowfat/ prefix, I will simply pass away π
β¨ DESCRIPTION β¨
so here's the vibe: socket_recv4 receives up to len bytes, starting at buf, from a UDP datagram that came in on the socket s. that's it, that's the whole job, main character energy fr fr.
and because UDP is a little gossip who always tells you where the message came from, she also hands you the receipts:
- she writes the UDP port into
portπΈ - she writes the IP address into
ip(it's achar ip[4], four bytes, one per octet, no cap) π - and she returns the number of bytes actually received β or
-1if anything went wrong π
not me getting emotional over a datagram. anyway.
β¨ RETURN VALUE β¨
socket_recv4 returns the number of bytes in the datagram, if a datagram was received. π«Ά
if not? she returns -1 and sets errno appropriately. that's the deal. check your errno, bestie, it's literally right there trying to tell you something.
β¨ EXAMPLE β¨
here's the whole thing, verbatim, copy it exactly and don't get creative:
#include <libowfat/socket.h>
int s;
char ip[4];
uint16 p;
char buf[1000];
int len;
s = socket_tcp4();
socket_bind4(s,ip,p);
len = socket_recv4(s,buf,sizeof(buf),ip,&p);
look at her. buf is a thousand bytes of pure potential. len catches the answer. iconic. π
β¨ SEE ALSO β¨
socket_recv6(3)β for when you've moved on to the six-byte address era π
heads up: this page is literally just about UDP. UDP gives you no promises, no handshakes, no follow-up texts. if nothing arrived, you get -1, not a sad little message. that's not a bug, that's just her. π
and that's the page, bestie!! from the Library Functions Manual, filed under socket_recv4(3) β go forth, receive your datagrams, and remember: check errno, hydrate, and slay. πβ¨
π¦ 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