mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix(native): gethostbyname no longer answers failed lookups with Ubuntu and Debian addresses
This commit is contained in:
1 parent
54acba5f94
commit
f88d6a8f26
1 file changed
-49
@@ -951,53 +951,4 @@ int res_search(const char *dname, int class, int type,
|
||||
return orig_res_search ? orig_res_search(dname, class, type, answer, anslen) : -1;
|
||||
}
|
||||
|
||||
static struct hostent s_fallback_hostent;
|
||||
static char *s_fallback_aliases[1] = { NULL };
|
||||
static in_addr_t s_fallback_addr1;
|
||||
static in_addr_t s_fallback_addr2;
|
||||
static char *s_fallback_addr_list[3] = { NULL, NULL, NULL };
|
||||
|
||||
static struct hostent *get_fallback_hostent(const char *name) {
|
||||
if (!name) return NULL;
|
||||
if (strstr(name, "ubuntu.com") != NULL) {
|
||||
inet_pton(AF_INET, "91.189.91.103", &s_fallback_addr1);
|
||||
inet_pton(AF_INET, "91.189.92.21", &s_fallback_addr2);
|
||||
} else if (strstr(name, "debian.org") != NULL) {
|
||||
inet_pton(AF_INET, "151.101.130.132", &s_fallback_addr1);
|
||||
inet_pton(AF_INET, "151.101.2.132", &s_fallback_addr2);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
s_fallback_addr_list[0] = (char *)&s_fallback_addr1;
|
||||
s_fallback_addr_list[1] = (char *)&s_fallback_addr2;
|
||||
s_fallback_addr_list[2] = NULL;
|
||||
|
||||
s_fallback_hostent.h_name = (char *)name;
|
||||
s_fallback_hostent.h_aliases = s_fallback_aliases;
|
||||
s_fallback_hostent.h_addrtype = AF_INET;
|
||||
s_fallback_hostent.h_length = sizeof(in_addr_t);
|
||||
s_fallback_hostent.h_addr_list = s_fallback_addr_list;
|
||||
return &s_fallback_hostent;
|
||||
}
|
||||
|
||||
struct hostent *gethostbyname(const char *name) {
|
||||
static struct hostent *(*orig_gethostbyname)(const char *) = NULL;
|
||||
if (!orig_gethostbyname) orig_gethostbyname = (struct hostent *(*)(const char *))dlsym(RTLD_NEXT, "gethostbyname");
|
||||
struct hostent *ret = orig_gethostbyname ? orig_gethostbyname(name) : NULL;
|
||||
if (!ret && name && (strstr(name, "ubuntu.com") || strstr(name, "debian.org"))) {
|
||||
return get_fallback_hostent(name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct hostent *gethostbyname2(const char *name, int af) {
|
||||
static struct hostent *(*orig_gethostbyname2)(const char *, int) = NULL;
|
||||
if (!orig_gethostbyname2) orig_gethostbyname2 = (struct hostent *(*)(const char *, int))dlsym(RTLD_NEXT, "gethostbyname2");
|
||||
struct hostent *ret = orig_gethostbyname2 ? orig_gethostbyname2(name, af) : NULL;
|
||||
if (!ret && (af == AF_INET || af == AF_UNSPEC) && name && (strstr(name, "ubuntu.com") || strstr(name, "debian.org"))) {
|
||||
return get_fallback_hostent(name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !DDNATV_HOST_TEST */
|
||||
Reference in new issue
Block a user