The DNS is used to assign names to computers and systems connected to the internet. Similar to how a phone book can be used to link a phone number to a name, the DNS allows us to link a hostname to an IP address.
When your program needs to connect to a remote computer, such as www.example.com, it first needs to find the IP address for www.example.com. In this book so far, we have been using the built-in getaddrinfo() function for this purpose. When you call getaddrinfo(), your operating system goes through a number of steps to resolve the domain name.
First, your operating system checks whether it already knows the IP address for www.example.com. If you have used that hostname recently, the OS is allowed to remember it in a local cache for a time. This time is referred to as time-to-live (TTL) and is set by the DNS server responsible for...