+static int
+check_subnet_v4(const struct sockaddr_in *address,
+ const struct sockaddr_in *mask, const struct addrinfo *ai)
+{
+ for (; ai; ai = ai->ai_next) {
+ struct sockaddr_in *sin = (struct sockaddr_in *)ai->ai_addr;
+
+ if (sin->sin_family != AF_INET)
+ continue;
+
+ if (mask_match(address->sin_addr.s_addr,
+ sin->sin_addr.s_addr,
+ mask->sin_addr.s_addr))
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef IPV6_SUPPORTED
+static int
+check_subnet_v6(const struct sockaddr_in6 *address,
+ const struct sockaddr_in6 *mask, const struct addrinfo *ai)
+{
+ for (; ai; ai = ai->ai_next) {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr;
+
+ if (sin6->sin6_family != AF_INET6)
+ continue;
+
+ if (mask_match(address->sin6_addr.s6_addr32[0],
+ sin6->sin6_addr.s6_addr32[0],
+ mask->sin6_addr.s6_addr32[0]) &&
+ mask_match(address->sin6_addr.s6_addr32[1],
+ sin6->sin6_addr.s6_addr32[1],
+ mask->sin6_addr.s6_addr32[1]) &&
+ mask_match(address->sin6_addr.s6_addr32[2],
+ sin6->sin6_addr.s6_addr32[2],
+ mask->sin6_addr.s6_addr32[2]) &&
+ mask_match(address->sin6_addr.s6_addr32[3],
+ sin6->sin6_addr.s6_addr32[3],
+ mask->sin6_addr.s6_addr32[3]))
+ return 1;
+ }
+ return 0;
+}
+#else /* !IPV6_SUPPORTED */
+static int
+check_subnet_v6(const struct sockaddr_in6 *UNUSED(address),
+ const struct sockaddr_in6 *UNUSED(mask),
+ const struct addrinfo *UNUSED(ai))
+{
+ return 0;
+}
+#endif /* !IPV6_SUPPORTED */
+
+/*
+ * Check each address listed in @ai against the subnetwork or
+ * host address stored in @clp. Return 1 if an address in @hp
+ * matches the host address stored in @clp, otherwise zero.
+ */
+static int
+check_subnetwork(const nfs_client *clp, const struct addrinfo *ai)
+{
+ switch (get_addrlist(clp, 0)->sa_family) {
+ case AF_INET:
+ return check_subnet_v4(get_addrlist_in(clp, 0),
+ get_addrlist_in(clp, 1), ai);
+ case AF_INET6:
+ return check_subnet_v6(get_addrlist_in6(clp, 0),
+ get_addrlist_in6(clp, 1), ai);
+ }
+
+ return 0;
+}
+
+/*
+ * Check if a wildcard nfs_client record matches the canonical name
+ * or the aliases of a host. Return 1 if a match is found, otherwise
+ * zero.
+ */
+static int
+check_wildcard(const nfs_client *clp, const struct addrinfo *ai)
+{
+ char *cname = clp->m_hostname;
+ char *hname = ai->ai_canonname;
+ struct hostent *hp;
+ char **ap;
+
+ if (wildmat(hname, cname))