Sockets

Focused on sockets

This is definitely not exhaustive. I’m adding to it all the time, focusing on what’s most relevant to my day to day.

Domains

AF_INET / AF_INET6

IPv4 and IPv6, respectively. Though be careful lumping them together, they are separate implementations with different behaviors.

AF_UNIX - Unix domain socket (UDS)

Types

  • SOCK_STREAM - reliable, non message boundary preserving.
  • SOCK_DGRAM - unreliable, message boundary preserving.
  • SOCK_SEQPACKET - reliable, message boundary preserving. Linux-specific. Mainly for AF_UNIX usage.

More details on these in this blog

Syscalls

A minimal sockets example will use these syscalls:

Socket options (blog post forthcoming):

I use these primarily for passing sockets via SCM_RIGHTS (blog post forthcoming):

Others:

Relevant Cheatsheets

Other Resources