SCTP_GETLADDRS(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_GETLADDRS πŸ’–

okay bestie, welcome to the Linux Programmer's Manual, SCTP_GETLADDRS(3) edition β€” this is the one where you find out every single address your socket is locally bound to. it's giving ✨address reveal party✨ and honestly? obsessed. 🌸


✨ NAME ✨

sctp_getladdrs β€” returns all locally bound addresses on a socket. yes that's literally the whole job. she's focused. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

int sctp_getladdrs(int sd, sctp_assoc_t assoc_id,
                   struct sockaddr **addrs);

void sctp_freeladdrs(struct sockaddr *addrs);

look at those two. they're a package deal, fr fr. one gets you the goods, the other cleans up the mess. 🫢


🌈 DESCRIPTION 🌈

so. sctp_getladdrs returns all locally bound addresses on a socket. when it comes back, addrs will point to a dynamically allocated packed array of sockaddr structures β€” and each one is the appropriate type for its local address, no cap. πŸ‘‘

πŸ’€ real talk tho: the caller should use sctp_freeladdrs to free that memory. and the in/out parameter addrs must not be NULL. like, that's a hard no. don't do it.

if sd is an IPv4 socket, the addresses you get back will be all IPv4 addresses. simple. clean. iconic.

if sd is an IPv6 socket, the addresses you get back can be a mix of IPv4 or IPv6 addresses. she contains multitudes, okay? 🌈

now for the association tea β˜•:

  • for one-to-many style sockets, id specifies the association to query πŸŽ€
  • for one-to-one style sockets, id is ignored. she said "not my business" πŸ™ˆ

and if the id field is set to 0, then the locally bound addresses are returned without regard to any particular association. just vibes. all of them. 🌸

lastly: sctp_freeladdrs frees all the resources allocated by sctp_getladdrs. that's her whole personality and she does it well. ✨


⭐ RETURN VALUE ⭐

  • on success β€” sctp_getladdrs returns the number of local addresses bound to the socket. a little count, a little slay. πŸ”₯
  • if the socket is unbound β€” 0 is returned and the value of *addrs is undefined 😭
  • on error β€” sctp_getladdrs returns -1 and the value of *addrs is undefined πŸ’€
🫢 just to be clear bestie: undefined means undefined. don't go reading *addrs and expecting a gift. that's not the vibe check you want to fail.

πŸŽ€ SEE ALSO πŸŽ€

the whole friend group, assembled. go read them too, iykyk. πŸ‘‘


and that's the page!! this one came straight out of Linux 2.6, dated 2005-10-25 β€” yes she's an elder but she's still serving πŸ’œ β€” mwah, love u, go free your addrs 🫢✨

πŸ“¦ where this page comes from