mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 09:48:29 +00:00
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:
parent
05350eca60
commit
248c6d54bb
12 changed files with 334 additions and 10 deletions
|
@ -61,6 +61,7 @@ const struct HostsTxt *GetHostsTxt(void) {
|
|||
init = &g_hoststxt_init;
|
||||
if (!g_hoststxt) {
|
||||
g_hoststxt = &init->ht;
|
||||
init->ht.sorted_by = HOSTSTXT_NOT_SORTED;
|
||||
init->ht.entries.n = pushpop(ARRAYLEN(init->entries));
|
||||
init->ht.entries.p = init->entries;
|
||||
init->ht.strings.n = pushpop(ARRAYLEN(init->strings));
|
||||
|
@ -74,7 +75,7 @@ const struct HostsTxt *GetHostsTxt(void) {
|
|||
/* TODO(jart): Elevate robustness. */
|
||||
}
|
||||
fclose(f);
|
||||
SortHostsTxt(g_hoststxt);
|
||||
SortHostsTxt(g_hoststxt, HOSTSTXT_SORTEDBYNAME);
|
||||
}
|
||||
return g_hoststxt;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue