Solutions
95. Finding the IP address of a host
Host information, including IP addresses, can be retrieved with system-specific network utilities, such as gethostbyname()
. Although this is available on all platforms, the way it is used is different and the requirement is to write a program that works on all platforms. There are various open source cross-platform libraries for networking, such as POCO and Asio/Boost.Asio. POCO is a more complex library, with support for not only networking but also data access, cryptography, XML, JSON, Zip, and others. Asio is a stand-alone, header-only library with a consistent asynchronous I/O model for network programming. It is also available as part of the Boost library, and a standardization proposal based on it is under evaluation. In this book, I will be using the standalone version of Asio, because it is a header-only library and does not have additional dependencies and is, therefore, easier to use. Asio can be used for solving this task.
The stand...