getaddrinfo() does not request NAPTR or SRV records or even any type of record except A and AAAA strong>. getaddrinfo() is an interface for the libc host name resolution service, which is modeled as a simple mapping between names and addresses. To find out how this happens, keep in mind that this permission service can access /etc/hosts or, less commonly, NIS +, LDAP, relational databases, etc. According to the configuration file /etc/nsswitch.conf . Note that none of these NSS databases understands anything in NAPTR or SRV records .
Only DNS implements NAPTR and SRV records , and if you want to request them, you will have to use the API to directly query DNS (see res_init() and or more interesting third-party libraries such as c-ares that support non-blocking operations). You cannot use the libc host name resolution service for this.
As for your second question, the advantages of using getaddrinfo() are as follows: (1) it is much easier to use, and (2) you will find entries that users could insert in /etc/hosts , which you will skip if You are directly querying DNS.
source share