Added getnameinfo with only name lookup (#172)

Added necessary constants (DNS_TYPE_PTR, NI_NUMERICHOST etc.).
Implementation of getnameinfo is similar to getaddrinfo, with internal
functions:

* ResolveDnsReverse: performs rDNS query and parses the PTR record
* ResolveHostsReverse: reads /etc/hosts to map hostname to
  address

Earlier, the HOSTS.txt would only need to be sorted at loading time,
because the only kind of lookup was name -> address. Now since address
-> name lookups are also possible, so the HostsTxt struct, the sorting
method (and the related tests) was changed to reflect this.
This commit is contained in:
Gautham 2021-06-10 08:05:44 +05:30 committed by GitHub
parent 05350eca60
commit 248c6d54bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 334 additions and 10 deletions

View file

@ -52,6 +52,8 @@ int ResolveHostsTxt(const struct HostsTxt *ht, int af, const char *name,
struct sockaddr_in *addr4;
struct HostsTxtEntry *entry;
if (af != AF_INET && af != AF_UNSPEC) return eafnosupport();
if (ht->sorted_by != HOSTSTXT_SORTEDBYNAME)
SortHostsTxt(ht, HOSTSTXT_SORTEDBYNAME);
if ((entry = bsearch_r(name, ht->entries.p, ht->entries.i,
sizeof(struct HostsTxtEntry), (void *)hoststxtgetcmp,
ht->strings.p))) {