Fix address family check in extractIpAddressAnswers()
Per Mike's finding in aosp/2185522, inet_ntop() doesn't return
an error when converting a IPv4 string from an IPv6 network address.
That means that using expectAnswersValid(.., AF_INET, ..) to check
IPv6 RRs will pass. extractIpAddressAnswers() fails to check the
address family.
Check the RR type to make sure the RR contains the expected address
family type.
Bug: 242681575
Test: atest CtsNetTestCasesLatestSdk:MultinetworkApiTest
Change-Id: Ieb67513afac0d97971ba4ddab8ceff03eddf6f45
diff --git a/tests/cts/net/jni/NativeMultinetworkJni.cpp b/tests/cts/net/jni/NativeMultinetworkJni.cpp
index 7978ed3..6610d10 100644
--- a/tests/cts/net/jni/NativeMultinetworkJni.cpp
+++ b/tests/cts/net/jni/NativeMultinetworkJni.cpp
@@ -118,6 +118,18 @@
// If there is no valid answer, test will fail.
continue;
}
+
+ const int rtype = ns_rr_type(rr);
+ if (family == AF_INET) {
+ // If there is no expected address type, test will fail.
+ if (rtype != ns_t_a) continue;
+ } else if (family == AF_INET6) {
+ // If there is no expected address type, test will fail.
+ if (rtype != ns_t_aaaa) continue;
+ } else {
+ return -EAFNOSUPPORT;
+ }
+
const uint8_t* rdata = ns_rr_rdata(rr);
char buffer[INET6_ADDRSTRLEN];
if (inet_ntop(family, (const char*) rdata, buffer, sizeof(buffer)) == NULL) {