socket_info(3)

πŸ“¦ version 31, in alpine 3.24

✨ NAME ✨

okay so socket_info(3) β€” from the Library Functions Manual, bestie β€” is literally the page for retrieving IP connection information for an existing socket. It's giving "tell me about this socket's IP situation" energy πŸ’…βœ¨

πŸŽ€ SYNTAX πŸŽ€

       #include "socket_if.h"

       int socket_local(int s,char ip[16],
                       uint16 *port,uint32 *scope_id);

       int socket_remote(int s,char ip[16],
                        uint16 *port,uint32 *scope_id);

No cap, those are the exact signatures. Slay. πŸ’–

πŸ¦‹ DESCRIPTION πŸ¦‹

  • socket_local β€” returns the local IPv6 or IPv4-mapped IPv6 address as ip, the port as port, and perhaps the scope_id as scope_id for the UDP or TCP socket. It's the "where am I?" of socket lore 😭🌐
  • socket_remote β€” returns the remote IPv6 or IPv4-mapped IPv6 address as ip, the port as port, and perhaps the scope_id as scope_id for the UDP or TCP socket. That's the "who's on the other end?" vibe fr fr 🫢

πŸ’€ RETURN CODES πŸ’€

If something goes wrong, socket_local and socket_remote return -1, setting errno appropriately. So if you see -1, bestie, that's the plot twist β€” and errno is the tea πŸ˜­πŸ’€

πŸ“ EXAMPLE πŸ“

       #include <socket_if.h>
         int s;
         char ip[16];
         uint16 port;

         if (socket_remote(s,ip,&port,0) == -1)
           err_tmp("",111,"unable to get remote address: ");

Literally the whole example, no edits, periodt πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘


bye bestie! πŸ’– signing off from the Library Functions Manual with socket_info(3) as the footer's source/version β€” and since no date is printed there, we're not inventing one, periodt πŸŽ€βœ¨

πŸ“¦ where this page comes from