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 othersockaddr_*address structure, and it's aligned so that you can cast a pointer to it into a pointer to any othersockaddr_*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_twas invented by POSIX. also go peek ataccept(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-2024fixed 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_tis also defined in<netdb.h>.sa_family_tis 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:
accept(2),bind(2),connect(2),getpeername(2),getsockname(2),getsockopt(2),sendto(2),setsockopt(2),socket(2),socketpair(2),getaddrinfo(3),gethostbyaddr(3),getnameinfo(3),htonl(3),ipv6(7),socket(7)
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
- Copyright 2020, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms