- Which function fills in an address needed for socket programming in a portable and protocol-independent way?
getaddrinfo()is the function to use for this.
- Which socket programming function can be used to convert an IP address back into a name?
getnameinfo()can be used to convert addresses back to names.
- A DNS query converts a name to an address, and a reverse DNS query converts an address back into a name. If you run a DNS query on a name, and then a reverse DNS query on the resulting address, do you always get back the name you started with?
Sometimes, you will get the same name back but not always. This is because the forward and reverse lookups use independent records. It's also possible to have many names point to one address, but that one address can only have one record that points back to a single name.
- What are the DNS record types used to return IPv4 and IPv6 addresses for a name?
Arecord type returns an IPv4 address, and the
AAAArecord type returns an IPv6 address.
- Which DNS record type stores special information about email servers?
MXrecord type is used to return email server information.
getaddrinfo()always return immediately? Or can it block?
getaddrinfo()is doing name lookups, it will often block. In the worst-case scenario, many UDP messages would need to be sent to various DNS servers, so this can be a noticeable delay. This is one reason why DNS caching is important.If you are simply using
getaddrinfo()to convert from a text IP address, then it shouldn't block.
- What happens when a DNS response is too large to fit into a single UDP packet?
The DNS response will have the
TCbit set in its header. This indicates that the message was truncated. The query should be resent using TCP.