qlibs:(socket_udp)

πŸ“¦ version 31, in alpine 3.24

socket_udp πŸ¦‹ β€” from the qlibs manual, section 3

🌸 NAME 🌸

socket_udp β€” setting up UDP datagram sockets. Bestie, this is the whole β€œmake a UDP socket happen” situation πŸ’…

✨ SYNTAX ✨

#include "socket_if.h"

int socket_udp4();
int socket_udp6();
int socket_udp();

πŸ’– DESCRIPTION πŸ’–

Okay so, these routines are literally here to set up UDP datagram sockets. Let’s go:

  • socket_udp4() β€” creates a non-blocking UDP/IPv4 datagram socket and provides a file descriptor pointing to that socket. Slay.
  • socket_udp6() β€” creates a non-blocking UDP/IPv6 datagram socket and provides a file descriptor pointing to that socket. Iconic.
  • socket_udp() β€” creates a non-blocking IPv6 UDP socket calling socket_udp6 unless it can’t bind to IPv6 and now facilitating socket_tcp4. That’s the exact vibe, no cap.

πŸ’€ REMOTE CODES πŸ’€

Vibe check on return values: all these routines return 0 except in case of failures, returning -1 and setting errno appropriately, without allocating any resources. So yeah β€” 0 is the good ending, -1 means it’s giving failure, and no resources get allocated. Periodt.

πŸŽ€ EXAMPLE πŸŽ€

Here’s the example, bestie β€” keep it exactly as shown, braces and all πŸ™ˆ

         #include <socket_if.h>
         int u;
         char localip[16];
         char remoteip[16];
         uint16 p; // port

         if (ip6_isv4mapped(remoteip)) {
           u = socket_udp4();
           socket_bind4(u,localip + 12,p);
         } else
           u = socket_udp6();
           socket_bind6(u,localip,p,0);
         }
         socket_connect(u,remoteip,p,0);

🫢 SEE ALSO 🫢

Go check out the rest of the friend group: socket_if(3), socket_bind(3), socket_connect(3), socket_info(3), socket_recv(3), socket_send(3), socket_setup(3), socket_tcp(3). Iykyk πŸ’œ


That’s the whole page, bestie β€” signing off from section 3, qlibs:(socket_udp) πŸŒˆπŸ’…βœ¨

πŸ“¦ where this page comes from