socket_connect6(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_connect6(3) β€” bestie's guide to making a TCP connection πŸ’–

okay so real talk, this one lives in the Library Functions Manual and it's genuinely one of the most useful little gremlins in libowfat/socket.h. sit with me, we're doing this together 🫢


✨ NAME ✨

socket_connect6 β€” attempt to make a TCP connection

like, that's it, that's the whole job. it tries to connect. no cap. πŸ”₯


🌸 SYNTAX 🌸

#include <libowfat/socket.h>

int socket_connect6(int s, const char ip[16],
                    uint16 port,uint32 scope_id);

four args, one int out, slay πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so socket_connect6 attempts to make a connection from TCP socket s to TCP port port on IP address ip. that's the whole vibe. simple. iconic.

Now. The meaning of scope_id is dependent on the implementation and the IPv6 IP. On link-local IPv6 addresses it specifies the outgoing interface index. The name (e.g. "eth0") for a given interface index can be queried with getifname. scope_id should normally be set to 0. normally!! don't be extra about it πŸ™ˆ

socket_connect6 may return

  • 0 β€” to indicate that the connection succeeded (and succeeded immediately, if the socket is non-blocking) ✨
  • -1, setting errno to error_inprogress or error_wouldblock, to indicate that the socket is non-blocking πŸ‘€
  • -1, setting errno to something else, to indicate that the connection failed (and failed immediately, if the socket is non-blocking). πŸ’€

When a background connection succeeds or fails, s becomes writable; you can use socket_connected to see whether the connection succeeded. If the connection failed, socket_connected returns 0, setting errno appropriately.

Once a TCP socket is connected, you can use the read and write system calls to transmit data. yes bestie, that's the payoff, that's the main character moment πŸ‘‘

You can call socket_connect6 without calling socket_bind6. This has the effect as first calling socket_bind6 with IP address :: and port 0. so it just handles it for you, lowkey thoughtful of it πŸŽ€


πŸŽ€ EXAMPLE πŸŽ€

#include <libowfat/socket.h>

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

s = socket_tcp6();
socket_bind6(s,ip,p);
socket_connect6(s,ip,p,0);

look at that. clean. no notes. 🌈


πŸ’œ SEE ALSO πŸ’œ

go read these next, iykyk πŸ“š


okay bye my love 🫢 this was socket_connect6(3) straight out of the Library Functions Manual, and yeah, that's the same socket_connect6(3) you see at the bottom of the page β€” periodt. πŸ’–βœ¨πŸŒΈπŸ¦‹