qlibs:(socket_send)

πŸ“¦ version 31, in alpine 3.24

πŸ’– qlibs:(socket_send) πŸ’–

okay bestie, welcome to qlibs:(socket_send) β€” the manual page for sending data over a UDP socket, and we are gonna make it make sense πŸ’…

πŸŽ€ ROUTINES πŸŽ€

  • socket_send β€” sending data over a UDP socket πŸ’Œ

πŸ“¦ SYNTAX πŸ“¦

       #include "socket_if.h"

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

✨ DESCRIPTION ✨

So here's the vibe: socket_send4 sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IPv4 address ip. Slay πŸ’…

socket_send6 sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IPv6 address ip and perhaps using scope_id as the outging interface πŸ‘€

For link-local IPv6 (LLU) addresses, scope_id specifies the outgoing interface index. socket_id can be queried for the given name of the interface (e.g. "eth0") by means of socket_getifidx. scope_id should normally be set to 0 except for link local IPv6 addresses πŸ¦‹

socket_send sends len bytes starting at buf in a UDP datagram over the socket s to UDP port port on IP address ip and perhaps using scope_id as the outging interface ✨

And here's the iconic part: you can call socket_send* without calling socket_bind* 🫢 This has the effect as first calling socket_bind4 with IP address 0.0.0.0 and port 0 or socket_bind6 with IP address :: and port 0. no cap.

πŸ”₯ RETURN VALUE πŸ”₯

socket_send* returns n, the number of bytes transmitted in the datagram. If not, it returns -1 and sets errno appropriately 😭

🌸 EXAMPLE 🌸

         #include <socket_if.h>

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

         s = socket_udp();
         socket_bind(s,ip,p);
         socket_send(s,"hello, world",12,ip,p,0);

πŸ‘‘ SEE ALSO πŸ‘‘


xoxo, stay slay β€” this has been qlibs:(socket_send), section 3, periodt πŸ’…πŸ«Ά

πŸ“¦ where this page comes from