Address Conversions

There are two fundamental forms for IP addresses. The first is a human-readable presentation form, such as the IPv4 dotted-quad or the IPv6 colon-delimited hex address. The other is a binary format network form that can be used by the sockets API to actually send data across the network. The presentation address is what the user interacts with, and the network form is used by the program’s code.

IPv4- and IPv6-compatible functions

The inet_pton() function converts from an address in presentation format to one in network format, hence the P to N in the function name.

i​n​t​ ​i​n​e​t​_​p​t​o​n​ ​(​i​n​t​ ​a​d​d​r​e​s​s​F​a​m​i​l​y​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​s​o​u​r​c​e​B​u​f​f​e​r​,​ ​v​o​i​d​ ​*​d​e​s​t​i​n​a​t​i​o​n​A​d​d​r​e​s​s​)​;​ ...

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.