~donmcc/ood

043d40c215be352c93b58cadb44e54a4d36ad131 — Don McCaughey 10 months ago b1c46d4
Readme fix and improvements.

Fix broken `sockaddr` link, add a link to the POSIX docs for
`sockaddr_un` and add the `sa` union declaration.
1 files changed, 20 insertions(+), 5 deletions(-)

M src/sa/README.md
M src/sa/README.md => src/sa/README.md +20 -5
@@ 1,7 1,7 @@
# _SA_: Socket Addresses

A wrapper around the polymorphic [`sockaddr`][] family of structs and a set of 
helper functions for common socket address chores.
A wrapper around the polymorphic [`sockaddr`][sockaddr] family of structs and a 
set of helper functions for common socket address chores.

[sockaddr]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html



@@ 9,17 9,32 @@ helper functions for common socket address chores.
## Overview

The `sa` union holds storage for each of the `sockaddr` [type puns][] along with 
space for a string representation.  For the `sockaddr_un` address type, the 
`sun_path` field is used as the string representation.
space for a string representation.  For the [`sockaddr_un`][sockaddr_un] address 
type, the `sun_path` field is used as the string representation.

[type puns]: https://en.wikipedia.org/wiki/Type_punning
[sockaddr_un]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html

The union contains fields `.ipv4`, `.ipv6` and `.local` which correspond to 
structs `sockaddr_in`, `sockaddr_in6` and `sockaddr_un` respectively.
Additionally, `.generic` corresponds to a `sockaddr` struct and `.storage` to
a `sockaddr_storage` struct.

NB: Because the symbol `unix` is #defined in some Unix C compilers, `sa`
    union sa {
        struct sockaddr generic;
        struct {
            struct sockaddr_in ipv4;
            char ipv4_str[SA_IPV4_STR_SIZE];
        };
        struct {
            struct sockaddr_in6 ipv6;
            char ipv6_str[SA_IPV6_STR_SIZE];
        };
        struct sockaddr_un local;
        struct sockaddr_storage storage;
    };

NB: Because the symbol `unix` is `#define`d in some Unix C compilers, `sa`
uses the name `local` for Unix domain sockets (often referred to as "local"
sockets).