Use std::vector to store domains of nameservers and minor change
1.
Drop the old C style used to store domains.
Previously, resolv is limited to use 6 search domains with total 255 length.
(including zero padding)
After this change, the length of each domain could exactly be at most 255. (rfc 1035)
Also, invalid or duplicate domains will be dropped.
2. rename resolv_set_nameservers_for_net to resolv_set_nameservers
Bug: 135506574
Test: cd system/netd && atest
Change-Id: I94129ea521522c817d087332a7b467f616cc4895
diff --git a/res_query.cpp b/res_query.cpp
index 13696c4..3776772 100644
--- a/res_query.cpp
+++ b/res_query.cpp
@@ -207,7 +207,7 @@
int* herrno) /* legacy and extended
h_errno NETD_RESOLV_H_ERRNO_EXT_* */
{
- const char *cp, *const *domain;
+ const char* cp;
HEADER* hp = (HEADER*) (void*) answer;
u_int dots;
int ret, saved_herrno;
@@ -251,12 +251,10 @@
*/
_resolv_populate_res_for_net(statp);
- for (domain = (const char* const*) statp->dnsrch; *domain && !done; domain++) {
+ for (const auto& domain : statp->search_domains) {
+ if (domain == "." || domain == "") ++root_on_list;
- if (domain[0][0] == '\0' || (domain[0][0] == '.' && domain[0][1] == '\0'))
- root_on_list++;
-
- ret = res_nquerydomain(statp, name, *domain, cl, type, answer, anslen, herrno);
+ ret = res_nquerydomain(statp, name, domain.c_str(), cl, type, answer, anslen, herrno);
if (ret > 0) return ret;
/*
@@ -295,7 +293,6 @@
/* anything else implies that we're done */
done++;
}
-
}
}