getnameinfo: Don't add flag NI_NUMERICHOST for well-known prefix address
Currently, getnameinfo() will never issue a reverse DNS lookup if the first
byte of the IPv6 address is 0x00. This means it is not possible to do a
reverse DNS lookup for a NAT64 address if the NAT64 prefix is the well-known
prefix. Make this possible by treating the well-known prefix specially. This
is not needed for unicast NAT64 prefixes because they do not start with 0x00.
Bug: 78545619
Test: netd_{unit,integration}_test pass
Test: bionic-unit-tests --gtest_filter='net*' pass
Change-Id: I176d30dcf411a5ffe1eec110db99cd73b48e956f
diff --git a/libc/dns/net/getnameinfo.c b/libc/dns/net/getnameinfo.c
index 5fa4e37..31d07c5 100644
--- a/libc/dns/net/getnameinfo.c
+++ b/libc/dns/net/getnameinfo.c
@@ -68,6 +68,13 @@
#include <stddef.h>
#include <string.h>
+/* This macro is modelled after the ones in <netinet/in6.h>. */
+/* RFC 6052, section 2.1 */
+#define IN6_IS_ADDR_WKP(a) \
+ ((((a)->s6_addr32[0]) == ntohl(0x0064ff9b)) && \
+ (((a)->s6_addr32[1]) == 0) && \
+ (((a)->s6_addr32[2]) == 0))
+
static const struct afd {
int a_af;
socklen_t a_addrlen;
@@ -248,6 +255,8 @@
;
else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
;
+ else if (IN6_IS_ADDR_WKP(&sin6->sin6_addr))
+ ;
else
flags |= NI_NUMERICHOST;
break;