Performing a network address resolution

Most applications will eventually need to convert host/service names to sockaddr structures and sockaddr structures to host/service names. The BSD Socket Library has two functions to assist with these conversions:

  • Getaddrinfo(): This is a function that will return information about a given host/service name. The results are returned in an addrinfo structure.
  • Getnameinfo(): This is a function that will return the host and service names, given a sockaddr structure.

The getaddrinfo() and getnameinfo() functions make the gethostbyname(), gethostbyaddr(), and getservbyport() functions obsolete. One of the main advantages that the getaddrinfo() and getnameinfo() functions has over the obsolete functions is that they ...

Get iOS and OS X Network Programming Cookbook 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.