sockaddr(3type)

πŸ’– sockaddr β€” the 3type manual, but make it make sense πŸ’–

okay bestie, so you know how sockaddr is that little blob every socket syscall keeps pointing at and you just nod along? yeah. we're fixing that today. this is the sockaddr(3type) page, and by the end of it you will actually get it. no cap. ✨


πŸŽ€ LIBRARY

standard C library, aka libc. the blueprint. the OG. πŸ’…


🌸 SYNOPSIS

#include <sys/socket.h>

struct sockaddr {
    sa_family_t     sa_family;      /* Address family */
    char            sa_data[];      /* Socket address */
};

struct sockaddr_storage {
    sa_family_t     ss_family;      /* Address family */
};

typedef /* ... */ socklen_t;
typedef /* ... */ sa_family_t;

look at that. three little friends: two structs and two typedefs. iconic behavior, honestly. 🫢


✨ DESCRIPTION ✨

okay so here's the tea on each one:

  • sockaddr β€” this is the one that describes a socket address. like, "hi, I am an address, here's my family and my data." that's it. that's the whole job. πŸ‘‘
  • sockaddr_storage β€” this is the chill one that fits everybody. it's at least as large as any other sockaddr_* address structure, and it's aligned so that you can cast a pointer to it into a pointer to any other sockaddr_* structure and just… use its fields like that. it's the universal friend. it's giving "I have room for all of you at my table." πŸ¦‹ genuinely obsessed.
  • socklen_t β€” this describes the length of a socket address. it's an integer type of at least 32 bits. so, a size. for an address. told you it was simple. πŸ’œ
  • sa_family_t β€” this describes a socket's protocol family, and it's an unsigned integer type. that's the whole vibe check. βœ…

Internet domain sockets 🌐

go see sockaddr_in(3type) and sockaddr_in6(3type). those are the internet-flavored ones. they're right there waiting for you, bestie.

UNIX domain sockets πŸ“

go see sockaddr_un(3type). the local-girl version. lives on your own machine, no network nonsense. πŸ’…


πŸ“œ STANDARDS

  • POSIX.1-2024.

periodt.


πŸ•°οΈ HISTORY

  • POSIX.1-2001.

and now the lore, because it's actually so good:

  • socklen_t was invented by POSIX. also go peek at accept(2) while you're here, it's relevant, iykyk. 🌈
  • these structures were invented before modern ISO C strict-aliasing rules even existed. so if you apply those aliasing rules strictly, these structures would be extremely difficult to use without invoking undefined behavior. like, genuinely cursed. πŸ’€
  • but POSIX.1-2024 fixed it β€” it requires that implementations make sure these structures can be safely used as they were designed. slay. the committee finally came through. πŸ”₯

πŸ“ NOTES

a couple "careful, she's also here" moments:

  • socklen_t is also defined in <netdb.h>.
  • sa_family_t is also defined in <netinet/in.h> and <sys/un.h>.

so if you're wondering why it compiles in a file that doesn't include <sys/socket.h>… that's why. πŸ™ˆ


πŸ‘€ SEE ALSO

the whole group chat, in one place:


and that's the whole page, bestie. go forth and cast your pointers safely. πŸ’–

this was Linux man-pages version 6.20, dated 2026-02-08 β€” love that for us. bye pookie, go read socket(2) next πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms