mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42: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
|
@ -48,7 +48,7 @@ TEST(ParseHostsTxt, testCorrectlyTokenizesAndSorts) {
|
|||
ASSERT_EQ(1, fwrite(kInput, strlen(kInput), 1, f));
|
||||
rewind(f);
|
||||
ASSERT_EQ(0, ParseHostsTxt(ht, f));
|
||||
SortHostsTxt(ht);
|
||||
SortHostsTxt(ht, HOSTSTXT_SORTEDBYNAME);
|
||||
ASSERT_EQ(4, ht->entries.i);
|
||||
EXPECT_STREQ("cat.example.", &ht->strings.p[ht->entries.p[0].name]);
|
||||
EXPECT_STREQ("cat.example.", &ht->strings.p[ht->entries.p[0].canon]);
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST(ResolveHostsTxt, testBasicLookups) {
|
|||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(0, ParseHostsTxt(ht, f));
|
||||
SortHostsTxt(ht);
|
||||
SortHostsTxt(ht, HOSTSTXT_SORTEDBYNAME);
|
||||
ASSERT_EQ(5, ht->entries.i);
|
||||
EXPECT_STREQ("127.0.0.1", EzIp4Lookup(ht, "localhost"));
|
||||
EXPECT_STREQ("203.0.113.1", EzIp4Lookup(ht, "lol"));
|
||||
|
@ -66,7 +66,7 @@ TEST(ResolveHostsTxt, testCanonicalize) {
|
|||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(0, ParseHostsTxt(ht, f));
|
||||
SortHostsTxt(ht);
|
||||
SortHostsTxt(ht, HOSTSTXT_SORTEDBYNAME);
|
||||
ASSERT_EQ(5, ht->entries.i);
|
||||
EXPECT_STREQ("localhost", EzCanonicalize(ht, "localhost"));
|
||||
EXPECT_STREQ("lol.example.", EzCanonicalize(ht, "lol"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue