$NetBSD$

--- sendmail/conf.c.orig	2021-03-18 16:00:25.583958271 +0100
+++ sendmail/conf.c	2021-03-18 16:03:30.983504694 +0100
@@ -46,8 +46,12 @@
 #if STARTTLS
 # include "tls.h"
 #endif
 
+#if !HAS_GETHOSTBYNAME2
+extern struct __res_state sm_res;
+#endif
+
 static void	setupmaps __P((void));
 static void	setupmailers __P((void));
 static void	setupqueues __P((void));
 static int	get_num_procs_online __P((void));
@@ -4311,17 +4315,17 @@
 
 	if (family == AF_INET6)
 	{
 		/* From RFC2133, section 6.1 */
-		resv6 = bitset(RES_USE_INET6, _res.options);
-		_res.options |= RES_USE_INET6;
+		resv6 = bitset(RES_USE_INET6, sm_res.options);
+		sm_res.options |= RES_USE_INET6;
 	}
 #  endif /* RES_USE_INET6 */
 	SM_SET_H_ERRNO(0);
 	h = gethostbyname(name);
 #  ifdef RES_USE_INET6
 	if (!resv6)
-		_res.options &= ~RES_USE_INET6;
+		sm_res.options &= ~RES_USE_INET6;
 #  endif
 
 	/* the function is supposed to return only the requested family */
 	if (h != NULL && h->h_addrtype != family)
@@ -4535,9 +4539,10 @@
 	struct hostent *hp;
 
 #if NETINET6
 	if (type == AF_INET6 &&
-	    IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr))
+	    (IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr) ||
+	    IN6_IS_ADDR_LINKLOCAL((struct in6_addr *) addr)))
 	{
 		/* Avoid reverse lookup for IPv6 unspecified address */
 		SM_SET_H_ERRNO(HOST_NOT_FOUND);
 		return NULL;
@@ -5689,15 +5694,21 @@
 	char *hostname;
 {
 	size_t len_host, len_domain;
 
-	if (!*_res.defdname)
-		res_init();
+	if (!*sm_res.defdname) {
+#if NAMED_RESN
+		emset(&sm_res, 0, sizeof(sm_res));
+		res_ninit(&sm_res); /* No error check? */
+#else
+		res_init(); /* No error check? */
+#endif
+	}
 	len_host = strlen(hostname);
-	len_domain = strlen(_res.defdname);
+	len_domain = strlen(sm_res.defdname);
 	if (len_host > len_domain &&
 	    (sm_strcasecmp(hostname + len_host - len_domain,
-			_res.defdname) == 0) &&
+			sm_res.defdname) == 0) &&
 	    hostname[len_host - len_domain - 1] == '.')
 		return len_host - len_domain - 1;
 	else
 		return 0;
