qlibs:(socket_recv)

πŸ“¦ version 31, in alpine 3.24

πŸŽ€ NAME πŸŽ€

okay bestie, welcome to the qlibs:(socket_recv) page β€” manual name folded in like a lil sticker, periodt ✨

socket_recv β€” receive UDP datagrams over IPv4/IPv6 connections.


✨ SYNTAX ✨

include this header and this signature, no cap:

#include "socket_if.h"

int socket_recv(int s, const char *buf, unsigned int len,
                    const char ip[16], uint16 *port, uint32 *scope_id);

πŸ’– DESCRIPTION πŸ’–

okay so socket_recv reads len bytes starting at buf in a UDP datagram over the socket s. while it's doing that, it also hands you info about the remote IP address ip, the UDP port, and the perhaps scope_id of the receiving interface 🫢

and here's the cute part: you can call socket_recv without calling socket_bind first. that has the effect as first calling socket_bind with IP address :: and port 0. literally no bind, still fine πŸ’…


🌸 RETURN VALUE 🌸

socket_recv returns n, the number of bytes received β€” or otherwise -1 and sets errno appropriately. that's the whole vibe check 😭


πŸ¦‹ EXAMPLE πŸ¦‹

here's the example, keep it exact bestie:

         #include <socket_if.h>
         #include <ip.h>

         int s;
         char localip[16];
         char remoteip[16];
         uint16 p, port;
         uint32 scope_id;
         unsigned int len;
         int r;
         char buf[MTUSIZE+1];

         s = socket_udp();
         socket_bind_reuse(s,localip,p,0);
         r = socket_recv(s,buf,len,remoteip,&port,&scope_id);

🌈 SEE ALSO 🌈


okay that's the whole page, bestie! 🫢 cute lil footer sign-off: source/version is qlibs:(socket_recv), date/section is 3. go forth and receive those datagrams responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from