Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getaddrinfo() vs NAPTR/SRV record

Tags:

linux

dns

I have a doubt regarding Domain name resolution.We can do address resolution from DNS to ip-address format by using the function getaddrinfo() or by the procedure of NAPTR query,SRV record query and A/AAAA record. 1. Does the function use getaddrinfo() use the NAPTR query technique internally ? 2. What is the advantage of using the function getaddrinfo() over the other procedure ?

like image 773
user2139084 Avatar asked Jan 14 '23 00:01

user2139084


1 Answers

getaddrinfo() does not query NAPTR or SRV records, or indeed any type of record except A and AAAA. getaddrinfo() is an interface to libc's hostname resolution service which is modelled as a simple mapping between names and addresses. To see how this is the case, consider that this resolution service may consult /etc/hosts or, more rarely, NIS+, LDAP, relational databases, and so on, as per its configuration file /etc/nsswitch.conf. Notice how none of these NSS backends understand anything about NAPTR or SRV records.

Only DNS implements NAPTR and SRV records, and if you want to query them, you will have to use an API to query DNS directly (see res_init() and related functions, or more interesting third-party libraries like c-ares that support non-blocking operations). You can't use the libc hostname resolution service to do it.

As to your second question, the advantages of using getaddrinfo() are (1) it's a lot easier to use, and (2) you'll locate entries which users may have inserted into /etc/hosts, which you'll miss if you query DNS directly.

like image 119
Celada Avatar answered Jan 16 '23 01:01

Celada