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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.