O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required