SCTP_CONNECTX(3)

πŸ“¦
version 1.0.21 Β· 3 versions
  • 1.0.21 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 14.5 Β· freebsd 14.5
  • 15.1 Β· freebsd 15.1
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’… SCTP_CONNECTX(3) β€” bestie's guide to connecting with ALL the addresses

okay so this is a page from the Linux Programmer's Manual, and it's about sctp_connectx, which is literally the main character of "connect to a whole squad of addresses at once". Sit down, grab a boba, we're doing this. πŸ§‹βœ¨


✨ NAME ✨

sctp_connectx β€” initiate a connection on an SCTP socket using multiple destination addresses.

like, plural. many. a whole group chat of addresses. no cap. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>

int sctp_connectx(int sd, struct sockaddr * addrs, int addrcnt,
                  sctp_assoc_t  * id);

πŸ’– DESCRIPTION πŸ’–

so sctp_connectx initiates a connection to a set of addresses β€” they get passed in through the array called addrs β€” to/from the socket sd. and addrcnt is how many addresses are in that array, periodt.

if sd is an IPv4 socket, the addresses you pass must be IPv4 addresses. if sd is an IPv6 socket, the addresses you pass can be either IPv4 or IPv6 addresses. flexible queen behavior fr fr. πŸ¦‹

addrs is a pointer to an array of one or more socket addresses. each address lives inside its appropriate structure (i.e. struct sockaddr_in or struct sockaddr_in6). the family of the address type must be used to distinguish the address length β€” that's not optional, bestie, that's the rules. and the caller specifies the number of addresses in the array with addrcnt.

id is a pointer to the association id and, if provided, will be set to the identifier of the newly created association. cute little output param, we love her. πŸŽ€


πŸ”₯ RETURN VALUE πŸ”₯

  • success β†’ 0 is returned. slay. ✨
  • failure β†’ -1 is returned, and errno is set appropriately. 😭

πŸ’€ ERRORS πŸ’€

like, here's the whole drama list of things that can go wrong:

  • EBADF β€” sd is not a valid descriptor.
  • ENOTSOCK β€” sd is a descriptor for a file, not a socket. bestie. that's a file. not a socket. πŸ™ˆ
  • EFAULT β€” error while copying in or out from the user address space.
  • EINVAL β€” invalid port or address.
  • EACCES β€” the address is protected, and the user is not the super-user.
  • EISCONN β€” the socket is already connected. she's taken. πŸ’…
  • ECONNREFUSED β€” no one listening on the remote address. ghosted fr. πŸ‘»
  • ETIMEDOUT β€” timeout while attempting connection. the server may be too busy to accept new connections. note that for IP sockets the timeout may be very long when syncookies are enabled on the server. like, very long. pack a snack. πŸ“
  • ENETUNREACH β€” network is unreachable.
  • EADDRINUSE β€” local address is already in use.
  • EINPROGRESS β€” the socket is non-blocking and the connection cannot be completed immediately. it is possible to select(2) or poll(2) for completion by selecting the socket for writing. after select indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure).
  • EALREADY β€” the socket is non-blocking and a previous connection attempt has not yet been completed. girl, patience. 🧚
  • EAGAIN β€” no more free local ports or insufficient entries in the routing cache. for PF_INET see the net.ipv4.ip_local_port_range sysctl in ip(7) on how to increase the number of local ports.
  • EAFNOSUPPORT β€” the passed address didn't have the correct address family in its sa_family field.
  • EACCES, EPERM β€” the user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule.
ok important vibe check: EINPROGRESS and EALREADY aren't "you broke it" errors, they're "the plot is still unfolding" errors. handle them like a grown-up. 🫢

🌈 SEE ALSO 🌈

sctp(7) sctp_bindx(3), sctp_sendmsg(3), sctp_sendv(3), sctp_send(3), sctp_recvmsg(3), sctp_recvv(3), sctp_peeloff(3), sctp_getpaddrs(3), sctp_getladdrs(3), sctp_opt_info(3),


and that's the whole page, bestie!! πŸŽ€ this one's from Linux 2.6, dated 2005-10-25 β€” yeah she's vintage, she's an icon, she's still serving. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from