Home | man(3)


sockaddr(3type)                                                sockaddr(3type)

NAME
       sockaddr, sockaddr_storage, socklen_t - socket address

LIBRARY
       Standard C library (libc)

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;

DESCRIPTION
       sockaddr
              Describes a socket address.

       sockaddr_storage
              A  structure  at  least as large as any other sockaddr_* address
              structures.  It's aligned so that a pointer to it can be cast as
              a pointer to other sockaddr_* structures and used to access  its
              fields.

       socklen_t
              Describes  the  length  of a socket address.  This is an integer
              type of at least 32 bits.

       sa_family_t
              Describes a socket's protocol family.  This is an unsigned inte‐
              ger type.

   Internet domain sockets
       See sockaddr_in(3type) and sockaddr_in6(3type).

   UNIX domain sockets
       See sockaddr_un(3type).

STANDARDS
       POSIX.1-2024.

HISTORY
       POSIX.1-2001.

       socklen_t was invented by POSIX.  See also accept(2).

       These structures were invented  before  modern  ISO  C  strict-aliasing
       rules.   If aliasing rules are applied strictly, these structures would
       be extremely difficult to  use  without  invoking  undefined  behavior.
       POSIX.1-2024  fixed  this  by  requiring that implementations make sure
       that these structures can be safely used as they were designed.

NOTES
       socklen_t is also defined in <netdb.h>.

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

SEE ALSO
       accept(2), bind(2), connect(2),  getpeername(2),  getsockname(2),  get‐
       sockopt(2),  sendto(2), setsockopt(2), socket(2), socketpair(2), getad‐
       drinfo(3),   gethostbyaddr(3),   getnameinfo(3),   htonl(3),   ipv6(7),
       socket(7)

Linux man-pages 6.17              2026-02-08                   sockaddr(3type)