Domain Name Lookup

Human beings tend to prefer dealing with hostnames rather than working with raw IP addresses, even if the IP address is in a nice user-friendly presentation format. DNS, short for Domain Name Service, is the mechanism for translating human-readable hostnames, like www.bignerdranch.com, into a corresponding IP address.

You will use struct hostent when looking up hostnames to resolve the address.

s​t​r​u​c​t​ ​h​o​s​t​e​n​t​ ​{​
 ​ ​ ​ ​c​h​a​r​ ​ ​ ​*​h​_​n​a​m​e​;​
 ​ ​ ​ ​c​h​a​r​ ​ ​*​*​h​_​a​l​i​a​s​e​s​;​
 ​ ​ ​ ​i​n​t​ ​ ​ ​ ​ ​h​_​a​d​d​r​t​y​p​e​;​
 ​ ​ ​ ​i​n​t​ ​ ​ ​ ​ ​h​_​l​e​n​g​t​h​;​
 ​ ​ ​ ​c​h​a​r​ ​ ​*​*​h​_​a​d​d​r​_​l​i​s​t​;​
 ​ ​ ​ ​#​d​e​f​i​n​e​ ​h​_​a​d​d​r​ ​ ​h​_​a​d​d​r​_​l​i​s​t​[​0​]​
}​;​

The elements ...

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.