Sockets Address Data Structures

There are a number of data structures used to represent network addresses, along with a number of functions for converting addresses between different formats.

The fundamental data structure in the sockets API is struct sockaddr:

s​t​r​u​c​t​ ​s​o​c​k​a​d​d​r​ ​{​
 ​ ​ ​ ​u​i​n​t​8​_​t​ ​ ​ ​ ​ ​s​a​_​l​e​n​;​
 ​ ​ ​ ​s​a​_​f​a​m​i​l​y​_​t​ ​s​a​_​f​a​m​i​l​y​;​
 ​ ​ ​ ​c​h​a​r​ ​ ​ ​ ​ ​ ​ ​ ​s​a​_​d​a​t​a​[​1​4​]​;​

struct sockaddr acts like an abstract base class in object-oriented languages. It defines two fields that are common amongst all of the different address types. By examining these fields you can see how large the address structure is by looking at sa_len, and you can see what kind of address it ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.