Refactor ResState to store nameserver addresses by IPSockAddr
IPSockAddr is more safer and convenient to store socket addresses,
to compare two socket addresses, and to make the code more readable.
The change also removes get_nsaddr(), a static function in res_send.cpp.
Bug: 137169582
Test: cd packages/modules/DnsResolver && atest
Change-Id: I694c293139b01a39c40cc50ba8c4f067a2ac4b07
diff --git a/res_init.cpp b/res_init.cpp
index 049e225..ca054fc 100644
--- a/res_init.cpp
+++ b/res_init.cpp
@@ -97,17 +97,8 @@
statp->netid = netcontext->dns_netid;
statp->uid = netcontext->uid;
statp->pid = netcontext->pid;
- statp->nscount = 1;
+ statp->nscount = 0;
statp->id = arc4random_uniform(65536);
- // The following dummy initialization is probably useless because
- // it's overwritten later by resolv_populate_res_for_net().
- // TODO: check if it's safe to remove.
- const sockaddr_union u{
- .sin.sin_addr.s_addr = INADDR_ANY,
- .sin.sin_family = AF_INET,
- .sin.sin_port = htons(NAMESERVER_PORT),
- };
- memcpy(&statp->nsaddrs, &u, sizeof(u));
for (auto& sock : statp->nssocks) {
sock.reset();