Getaddrinfo () vs NAPTR / SRV record

I have doubts about domain name resolution. We can resolve the address from DNS to the ip address format using the getaddrinfo () function or using the NAPTR request procedure, SRV record request, and A / AAAA record. 1. Does the getaddrinfo () function use the internal NAPTR request technique? 2. What is the advantage of using the getaddrinfo () function over another procedure?

+4
source share
1 answer

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.

+7
source

Source: https://habr.com/ru/post/1489219/


All Articles