aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Marshall <tdm.code@gmail.com>2020-01-16 13:07:04 -0800
committerHan Wang <416810799@qq.com>2020-01-17 18:54:50 +0200
commitd1d03ac595f2a2a227572de0fa00f1a17e190f69 (patch)
treebe4d0e7c7bac1638c11610ba5363cffe20fe3875
parentedb3c4489ee8f2f0cf1fbca5f7111086f7318aac (diff)
downloadandroid_bionic-d1d03ac595f2a2a227572de0fa00f1a17e190f69.tar.gz
android_bionic-d1d03ac595f2a2a227572de0fa00f1a17e190f69.tar.bz2
android_bionic-d1d03ac595f2a2a227572de0fa00f1a17e190f69.zip
bionic: Support wildcards in cached hosts file
If an exact name is not found in the hosts file and the host name contains at least one dot, search for entries of the form "*.domain", where domain is the portion of the host name after the first dot. If that is not found, repeat using the domain. Example: a.b.c.example.com would search for the following in turn: a.b.c.example.com *.b.c.example.com *.c.example.com *.example.com *.com Change-Id: I4b0bb81699151d5b371850daebf785e35ec9b180
-rw-r--r--libc/dns/net/hosts_cache.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/libc/dns/net/hosts_cache.c b/libc/dns/net/hosts_cache.c
index deafb78b7..5038986be 100644
--- a/libc/dns/net/hosts_cache.c
+++ b/libc/dns/net/hosts_cache.c
@@ -121,7 +121,7 @@ static int cmp_hcent_name(const void *a, const void *b)
return hstrcmp(na, nb);
}
-static struct hcent *_hcfindname(const char *name)
+static struct hcent *_hcfindname_exact(const char *name)
{
size_t first, last, mid;
struct hcent *cur = NULL;
@@ -162,6 +162,33 @@ found:
return cur;
}
+static struct hcent *_hcfindname(const char *name)
+{
+ struct hcent *ent;
+ char namebuf[MAX_HOSTLEN];
+ char *p;
+ char *dot;
+
+ ent = _hcfindname_exact(name);
+ if (!ent && strlen(name) < sizeof(namebuf)) {
+ strcpy(namebuf, name);
+ p = namebuf;
+ do {
+ dot = strchr(p, '.');
+ if (!dot)
+ break;
+ if (dot > p) {
+ *(dot - 1) = '*';
+ ent = _hcfindname_exact(dot - 1);
+ }
+ p = dot + 1;
+ }
+ while (!ent);
+ }
+
+ return ent;
+}
+
/*
* Find next name on line, if any.
*