socket_send4(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_send4 β€” bestie's guide to yeeting a UDP datagram

okay so this is a page from the Library Functions Manual (yes that's the whole manual name, we're being fancy today), and it's all about socket_send4(3). let's get into it πŸ’–


✨ NAME ✨

socket_send4 β€” send a UDP datagram

like. that's it. that's the whole job. one datagram, out the door, no strings attached. πŸ’…


πŸ¦‹ SYNTAX πŸ¦‹

#include <libowfat/socket.h>

ssize_t socket_send4(int s, const char* buf, size_t len,
                     const char ip[4],uint16 port);

look at her. five little args and she's ready to go. 🌸


πŸ‘‘ DESCRIPTION πŸ‘‘

so socket_send4 sends len bytes, starting at buf, inside a UDP datagram. where's it going? over the socket s, to UDP port port, on IP address ip. that's the whole vibe check. πŸ“¬

and here's the part that's genuinely so considerate of her: you can call socket_send4 without calling socket_bind4 first. it does not care. the effect is the same as if you had called socket_bind4 first with IP address 0.0.0.0 and port 0. so like, she binds for you. main character energy fr fr. 🫢


🌈 RETURN VALUE 🌈

  • 0 β€” the datagram was sent successfully. slay. we ate. πŸŽ€
  • -1 β€” nope, it didn't work, and errno gets set appropriately so you can go find out why. 😭

πŸ“ EXAMPLE πŸ“

#include <libowfat/socket.h>

int s;
char ip[4];
uint16 p;

s = socket_tcp4();
socket_bind4(s,ip,p);
socket_send4(s,"hello, world",12,ip,p);

literally sending "hello, world" into the void. iconic. ✨

ngl bestie, this is the example exactly as she wrote it β€” socket_tcp4(), the socket_bind4(s,ip,p) line, all of it. don't come for me, i don't make the rules. πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ

  • socket_send6(3) β€” her IPv6 sister. same energy, longer addresses. 🌟

and that's the page!! written by the libowfat girlies, straight out of the Library Functions Manual β€” socket_send4(3), mwah. go send a datagram, you've got this. πŸ’–βœ¨πŸŽ€