socket_recv4(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 a char ip[4], four bytes, one per octet, no cap) πŸŽ€
  • and she returns the number of bytes actually received β€” or -1 if 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. πŸ’œβœ¨