2 * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/socket.h>
33 #include <arpa/inet.h>
34 #include <netinet/in.h>
41 #include <stringlist.h>
46 #include "freebsd_test_suite/macros.h"
52 TEST_GETHOSTBYNAME2_GETADDRINFO,
53 TEST_GETHOSTBYADDR_GETNAMEINFO,
55 TEST_BUILD_ADDR_SNAPSHOT
58 static int ipnode_flags = 0;
59 static int af_type = AF_INET;
60 static bool use_ipnode_functions;
62 DECLARE_TEST_DATA(hostent)
63 DECLARE_TEST_FILE_SNAPSHOT(hostent)
64 DECLARE_1PASS_TEST(hostent)
65 DECLARE_2PASS_TEST(hostent)
67 /* These stubs will use gethostby***() or getipnodeby***() functions,
68 * depending on the use_ipnode_functions global variable value */
69 static struct hostent *__gethostbyname2(const char *, int);
70 static struct hostent *__gethostbyaddr(const void *, socklen_t, int);
71 static void __freehostent(struct hostent *);
73 static void clone_hostent(struct hostent *, struct hostent const *);
74 static int compare_hostent(struct hostent *, struct hostent *, void *);
75 static void dump_hostent(struct hostent *);
76 static void free_hostent(struct hostent *);
78 static int is_hostent_equal(struct hostent *, struct addrinfo *);
80 static void sdump_hostent(struct hostent *, char *, size_t);
81 static int hostent_read_hostlist_func(struct hostent *, char *);
82 static int hostent_read_snapshot_addr(char *, unsigned char *, size_t);
83 static int hostent_read_snapshot_func(struct hostent *, char *);
85 static int hostent_test_correctness(struct hostent *, void *);
86 static int hostent_test_gethostbyaddr(struct hostent *, void *);
87 static int hostent_test_getaddrinfo_eq(struct hostent *, void *);
88 static int hostent_test_getnameinfo_eq(struct hostent *, void *);
90 static void usage(void) __attribute__((__noreturn__));
92 IMPLEMENT_TEST_DATA(hostent)
93 IMPLEMENT_TEST_FILE_SNAPSHOT(hostent)
94 IMPLEMENT_1PASS_TEST(hostent)
95 IMPLEMENT_2PASS_TEST(hostent)
97 static struct hostent *
98 __gethostbyname2(const char *name, int af)
103 if (use_ipnode_functions) {
105 he = getipnodebyname(name, af, ipnode_flags, &error);
109 he = gethostbyname2(name, af);
114 static struct hostent *
115 __gethostbyaddr(const void *addr, socklen_t len, int af)
120 if (use_ipnode_functions) {
122 he = getipnodebyaddr(addr, len, af, &error);
126 he = gethostbyaddr(addr, len, af);
132 __freehostent(struct hostent *he)
135 /* NOTE: checking for he != NULL - just in case */
136 if (use_ipnode_functions && he != NULL)
141 clone_hostent(struct hostent *dest, struct hostent const *src)
143 ATF_REQUIRE(dest != NULL);
144 ATF_REQUIRE(src != NULL);
151 memset(dest, 0, sizeof(struct hostent));
153 if (src->h_name != NULL) {
154 dest->h_name = strdup(src->h_name);
155 ATF_REQUIRE(dest->h_name != NULL);
158 dest->h_addrtype = src->h_addrtype;
159 dest->h_length = src->h_length;
161 if (src->h_aliases != NULL) {
163 for (cp = src->h_aliases; *cp; ++cp)
166 dest->h_aliases = calloc(1, (aliases_num + 1) *
168 ATF_REQUIRE(dest->h_aliases != NULL);
170 for (cp = src->h_aliases; *cp; ++cp) {
171 dest->h_aliases[cp - src->h_aliases] = strdup(*cp);
172 ATF_REQUIRE(dest->h_aliases[cp - src->h_aliases] != NULL);
176 if (src->h_addr_list != NULL) {
178 for (cp = src->h_addr_list; *cp; ++cp)
181 dest->h_addr_list = calloc(1, (addrs_num + 1) * sizeof(char *));
182 ATF_REQUIRE(dest->h_addr_list != NULL);
184 for (cp = src->h_addr_list; *cp; ++cp) {
185 offset = cp - src->h_addr_list;
186 dest->h_addr_list[offset] = malloc(src->h_length);
187 ATF_REQUIRE(dest->h_addr_list[offset] != NULL);
188 memcpy(dest->h_addr_list[offset],
189 src->h_addr_list[offset], src->h_length);
195 free_hostent(struct hostent *ht)
199 ATF_REQUIRE(ht != NULL);
203 if (ht->h_aliases != NULL) {
204 for (cp = ht->h_aliases; *cp; ++cp)
209 if (ht->h_addr_list != NULL) {
210 for (cp = ht->h_addr_list; *cp; ++cp)
212 free(ht->h_addr_list);
217 compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata)
219 char **c1, **c2, **ct, **cb;
225 if (ht1 == NULL || ht2 == NULL)
228 if (ht1->h_name == NULL || ht2->h_name == NULL)
231 if (ht1->h_addrtype != ht2->h_addrtype ||
232 ht1->h_length != ht2->h_length ||
233 strcmp(ht1->h_name, ht2->h_name) != 0)
239 if ((ht1->h_aliases == NULL || ht2->h_aliases == NULL) &&
240 ht1->h_aliases != ht2->h_aliases)
243 if (c1 != NULL && c2 != NULL) {
247 for (ct = c2; *ct; ++ct) {
248 if (strcmp(*c1, *ct) == 0) {
254 printf("h1 aliases item can't be found in h2 "
263 for (ct = c1; *ct; ++ct) {
264 if (strcmp(*c2, *ct) == 0) {
270 printf("h2 aliases item can't be found in h1 "
277 c1 = ht1->h_addr_list;
278 c2 = ht2->h_addr_list;
280 if ((ht1->h_addr_list == NULL || ht2->h_addr_list== NULL) &&
281 ht1->h_addr_list != ht2->h_addr_list)
284 if (c1 != NULL && c2 != NULL) {
288 for (ct = c2; *ct; ++ct) {
289 if (memcmp(*c1, *ct, ht1->h_length) == 0) {
295 printf("h1 addresses item can't be found in "
304 for (ct = c1; *ct; ++ct) {
305 if (memcmp(*c2, *ct, ht1->h_length) == 0) {
311 printf("h2 addresses item can't be found in "
322 printf("following structures are not equal:\n");
331 check_addrinfo_for_name(struct addrinfo *ai, char const *name)
333 struct addrinfo *ai2;
335 for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) {
336 if (strcmp(ai2->ai_canonname, name) == 0)
344 check_addrinfo_for_addr(struct addrinfo *ai, char const *addr,
345 socklen_t addrlen, int af)
347 struct addrinfo *ai2;
349 for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) {
350 if (af != ai2->ai_family)
356 (void *)&((struct sockaddr_in *)ai2->ai_addr)->sin_addr,
357 MIN(addrlen, ai2->ai_addrlen)) == 0)
362 (void *)&((struct sockaddr_in6 *)ai2->ai_addr)->sin6_addr,
363 MIN(addrlen, ai2->ai_addrlen)) == 0)
375 is_hostent_equal(struct hostent *he, struct addrinfo *ai)
381 printf("checking equality of he and ai\n");
384 rv = check_addrinfo_for_name(ai, he->h_name);
386 printf("not equal - he->h_name couldn't be found\n");
390 for (cp = he->h_addr_list; *cp; ++cp) {
391 rv = check_addrinfo_for_addr(ai, *cp, he->h_length,
394 printf("not equal - one of he->h_addr_list couldn't be found\n");
407 sdump_hostent(struct hostent *ht, char *buffer, size_t buflen)
413 written = snprintf(buffer, buflen, "%s %d %d",
414 ht->h_name, ht->h_addrtype, ht->h_length);
416 if (written > buflen)
420 if (ht->h_aliases != NULL) {
421 if (*(ht->h_aliases) != NULL) {
422 for (cp = ht->h_aliases; *cp; ++cp) {
423 written = snprintf(buffer, buflen, " %s",*cp);
425 if (written > buflen)
433 written = snprintf(buffer, buflen, " noaliases");
435 if (written > buflen)
440 written = snprintf(buffer, buflen, " (null)");
442 if (written > buflen)
447 written = snprintf(buffer, buflen, " : ");
449 if (written > buflen)
453 if (ht->h_addr_list != NULL) {
454 if (*(ht->h_addr_list) != NULL) {
455 for (cp = ht->h_addr_list; *cp; ++cp) {
456 for (i = 0; i < ht->h_length; ++i ) {
457 written = snprintf(buffer, buflen,
458 i + 1 != ht->h_length ? "%d." : "%d",
459 (unsigned char)(*cp)[i]);
461 if (written > buflen)
470 written = snprintf(buffer, buflen, " ");
472 if (written > buflen)
478 written = snprintf(buffer, buflen, " noaddrs");
480 if (written > buflen)
485 written = snprintf(buffer, buflen, " (null)");
487 if (written > buflen)
494 hostent_read_hostlist_func(struct hostent *he, char *line)
496 struct hostent *result;
500 printf("resolving %s: ", line);
502 result = __gethostbyname2(line, af_type);
503 if (result != NULL) {
508 rv = hostent_test_correctness(result, NULL);
510 __freehostent(result);
514 clone_hostent(he, result);
515 __freehostent(result);
518 printf("not found\n");
520 memset(he, 0, sizeof(struct hostent));
521 he->h_name = strdup(line);
522 ATF_REQUIRE(he->h_name != NULL);
528 hostent_read_snapshot_addr(char *addr, unsigned char *result, size_t len)
533 while ( (s = strsep(&ps, ".")) != NULL) {
537 *result = (unsigned char)strtol(s, &ts, 10);
551 hostent_read_snapshot_func(struct hostent *ht, char *line)
553 StringList *sl1, *sl2;
558 printf("1 line read from snapshot:\n%s\n", line);
565 memset(ht, 0, sizeof(struct hostent));
566 while ((s = strsep(&ps, " ")) != NULL) {
569 ht->h_name = strdup(s);
570 ATF_REQUIRE(ht->h_name != NULL);
574 ht->h_addrtype = (int)strtol(s, &ts, 10);
580 ht->h_length = (int)strtol(s, &ts, 10);
587 if (strcmp(s, "(null)") == 0)
591 ATF_REQUIRE(sl1 != NULL);
593 if (strcmp(s, "noaliases") != 0) {
595 ATF_REQUIRE(ts != NULL);
599 if (strcmp(s, ":") == 0)
603 ATF_REQUIRE(ts != NULL);
611 if (strcmp(s, "(null)") == 0)
615 ATF_REQUIRE(sl2 != NULL);
617 if (strcmp(s, "noaddrs") != 0) {
618 ts = calloc(1, ht->h_length);
619 ATF_REQUIRE(ts != NULL);
620 rv = hostent_read_snapshot_addr(s,
628 ts = calloc(1, ht->h_length);
629 ATF_REQUIRE(ts != NULL);
630 rv = hostent_read_snapshot_addr(s,
631 (unsigned char *)ts, ht->h_length);
641 if (i != 3 && i != 4)
648 ht->h_aliases = sl1->sl_str;
652 ht->h_addr_list = sl2->sl_str;
655 if ((i != 4) || (rv != 0)) {
657 memset(ht, 0, sizeof(struct hostent));
661 /* NOTE: is it a dirty hack or not? */
668 dump_hostent(struct hostent *result)
670 if (result != NULL) {
672 sdump_hostent(result, buffer, sizeof(buffer));
673 printf("%s\n", buffer);
679 hostent_test_correctness(struct hostent *ht, void *mdata)
683 printf("testing correctness with the following data:\n");
690 if (ht->h_name == NULL)
693 if (!((ht->h_addrtype >= 0) && (ht->h_addrtype < AF_MAX)))
696 if ((ht->h_length != sizeof(struct in_addr)) &&
697 (ht->h_length != sizeof(struct in6_addr)))
700 if (ht->h_aliases == NULL)
703 if (ht->h_addr_list == NULL)
712 printf("incorrect\n");
718 hostent_test_gethostbyaddr(struct hostent *he, void *mdata)
720 struct hostent *result;
721 struct hostent_test_data *addr_test_data;
724 addr_test_data = (struct hostent_test_data *)mdata;
726 /* We should omit unresolved hostents */
727 if (he->h_addr_list != NULL) {
729 for (cp = he->h_addr_list; *cp; ++cp) {
731 printf("doing reverse lookup for %s\n", he->h_name);
734 result = __gethostbyaddr(*cp, he->h_length,
736 if (result == NULL) {
738 printf("%s: warning: reverse lookup failed "
739 "for %s: %s\n", __func__, he->h_name,
744 rv = hostent_test_correctness(result, NULL);
746 __freehostent(result);
750 if (addr_test_data != NULL)
751 TEST_DATA_APPEND(hostent, addr_test_data,
754 __freehostent(result);
762 hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata)
764 struct addrinfo *ai, hints;
768 memset(&hints, 0, sizeof(struct addrinfo));
769 hints.ai_family = af_type;
770 hints.ai_flags = AI_CANONNAME;
772 printf("using getaddrinfo() to resolve %s\n", he->h_name);
774 /* struct hostent *he was not resolved */
775 if (he->h_addr_list == NULL) {
776 /* We can be sure that he->h_name is not NULL */
777 rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
779 printf("not ok - shouldn't have been resolved\n");
783 rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
785 printf("not ok - should have been resolved\n");
789 rv = is_hostent_equal(he, ai);
791 printf("not ok - addrinfo and hostent are not equal\n");
801 hostent_test_getnameinfo_eq(struct hostent *he, void *mdata)
804 char buffer[NI_MAXHOST];
805 struct sockaddr_in sin;
806 struct sockaddr_in6 sin6;
807 struct sockaddr *saddr;
808 struct hostent *result;
811 if (he->h_addr_list == NULL)
814 for (cp = he->h_addr_list; *cp; ++cp) {
816 printf("doing reverse lookup for %s\n", he->h_name);
818 result = __gethostbyaddr(*cp, he->h_length,
820 if (result != NULL) {
821 rv = hostent_test_correctness(result, NULL);
823 __freehostent(result);
827 printf("%s: warning: reverse lookup failed "
828 "for %s: %s\n", __func__, he->h_name,
831 switch (he->h_addrtype) {
833 memset(&sin, 0, sizeof(struct sockaddr_in));
834 sin.sin_len = sizeof(struct sockaddr_in);
835 sin.sin_family = AF_INET;
836 memcpy(&sin.sin_addr, *cp, he->h_length);
838 saddr = (struct sockaddr *)&sin;
841 memset(&sin6, 0, sizeof(struct sockaddr_in6));
842 sin6.sin6_len = sizeof(struct sockaddr_in6);
843 sin6.sin6_family = AF_INET6;
844 memcpy(&sin6.sin6_addr, *cp, he->h_length);
846 saddr = (struct sockaddr *)&sin6;
849 printf("warning: %d family is unsupported\n",
854 ATF_REQUIRE(saddr != NULL);
855 rv = getnameinfo(saddr, saddr->sa_len, buffer,
856 sizeof(buffer), NULL, 0, NI_NAMEREQD);
858 if (rv != 0 && result != NULL) {
859 printf("getnameinfo() didn't make the reverse "
860 "lookup, when it should have (%s)\n",
865 if (rv == 0 && result == NULL) {
866 printf("getnameinfo() made the "
867 "reverse lookup, when it shouldn't have\n");
871 if (rv != 0 && result == NULL) {
873 printf("both getnameinfo() and ***byaddr() failed as "
880 printf("comparing %s with %s\n", result->h_name,
885 * An address might reverse resolve to hostname alias or the
886 * official hostname, e.g. moon.vub.ac.be.
890 if (strcmp(result->h_name, buffer) == 0) {
891 found_a_match = true;
893 printf("matched official hostname\n");
896 for (i = 0; i < nitems(result->h_aliases); i++) {
897 printf("[%d] resolved: %s\n", i,
898 result->h_aliases[i]);
899 if (strcmp(result->h_aliases[i],
901 printf("matched hostname alias\n");
902 found_a_match = true;
907 __freehostent(result);
911 printf("getnameinfo() and ***byaddr() results are "
915 printf("getnameinfo() and ***byaddr() results are not "
916 "equal for %s\n", he->h_name);
925 run_tests(const char *hostlist_file, const char *snapshot_file, int af_type,
926 enum test_methods method, bool use_ipv6_mapping)
928 struct hostent_test_data td, td_addr, td_snap;
934 ATF_REQUIRE_FEATURE("inet");
935 ATF_REQUIRE(!use_ipv6_mapping);
938 ATF_REQUIRE_FEATURE("inet6");
941 atf_tc_fail("unhandled address family: %d", af_type);
945 if (!use_ipnode_functions) {
946 statp = __res_state();
947 if (statp == NULL || ((statp->options & RES_INIT) == 0 &&
948 res_ninit(statp) == -1)) {
949 printf("error: can't init res_state\n");
954 if (use_ipv6_mapping)
955 statp->options |= RES_USE_INET6;
957 statp->options &= ~RES_USE_INET6;
960 TEST_DATA_INIT(hostent, &td, clone_hostent, free_hostent);
961 TEST_DATA_INIT(hostent, &td_addr, clone_hostent, free_hostent);
962 TEST_DATA_INIT(hostent, &td_snap, clone_hostent, free_hostent);
964 if (access(hostlist_file, R_OK) != 0) {
965 printf("can't access the hostlist file %s\n", hostlist_file);
971 printf("building host lists from %s\n", hostlist_file);
974 rv = TEST_SNAPSHOT_FILE_READ(hostent, hostlist_file, &td,
975 hostent_read_hostlist_func);
977 printf("failed to read the host list file: %s\n",
982 if (snapshot_file != NULL) {
983 if (access(snapshot_file, W_OK | R_OK) != 0) {
984 if (errno == ENOENT) {
985 if (method != TEST_GETHOSTBYADDR)
986 method = TEST_BUILD_SNAPSHOT;
988 method = TEST_BUILD_ADDR_SNAPSHOT;
990 printf("can't access the snapshot file %s\n",
996 rv = TEST_SNAPSHOT_FILE_READ(hostent, snapshot_file,
997 &td_snap, hostent_read_snapshot_func);
999 printf("error reading snapshot file\n");
1006 case TEST_GETHOSTBYNAME2:
1007 if (snapshot_file != NULL)
1008 rv = DO_2PASS_TEST(hostent, &td, &td_snap,
1009 compare_hostent, NULL);
1011 case TEST_GETHOSTBYADDR:
1012 rv = DO_1PASS_TEST(hostent, &td,
1013 hostent_test_gethostbyaddr, (void *)&td_addr);
1017 if (snapshot_file != NULL)
1018 rv = DO_2PASS_TEST(hostent, &td_addr, &td_snap,
1019 compare_hostent, NULL);
1021 case TEST_GETHOSTBYNAME2_GETADDRINFO:
1022 rv = DO_1PASS_TEST(hostent, &td,
1023 hostent_test_getaddrinfo_eq, NULL);
1025 case TEST_GETHOSTBYADDR_GETNAMEINFO:
1026 rv = DO_1PASS_TEST(hostent, &td,
1027 hostent_test_getnameinfo_eq, NULL);
1029 case TEST_BUILD_SNAPSHOT:
1030 if (snapshot_file != NULL) {
1031 rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file,
1032 &td, sdump_hostent);
1035 case TEST_BUILD_ADDR_SNAPSHOT:
1036 if (snapshot_file != NULL) {
1037 rv = DO_1PASS_TEST(hostent, &td,
1038 hostent_test_gethostbyaddr, (void *)&td_addr);
1041 rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file,
1042 &td_addr, sdump_hostent);
1051 TEST_DATA_DESTROY(hostent, &td_snap);
1052 TEST_DATA_DESTROY(hostent, &td_addr);
1053 TEST_DATA_DESTROY(hostent, &td);
1058 #define HOSTLIST_FILE "mach"
1060 #define _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
1062 char *_hostlist_file; \
1063 char *_snapshot_file; \
1064 ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
1065 atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
1066 if (snapshot_file == NULL) \
1067 _snapshot_file = NULL; \
1069 _snapshot_file = strdup(snapshot_file); \
1070 ATF_REQUIRE(_snapshot_file != NULL); \
1072 ATF_REQUIRE(run_tests(_hostlist_file, _snapshot_file, af_type, \
1073 method, use_ipv6_mapping) == 0); \
1076 #define RUN_HOST_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
1078 use_ipnode_functions = false; \
1079 _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
1082 #define RUN_IPNODE_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
1084 use_ipnode_functions = true; \
1085 _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
1088 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4);
1089 ATF_TC_BODY(gethostbyaddr_ipv4, tc)
1092 RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false);
1095 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4_with_snapshot);
1096 ATF_TC_BODY(gethostbyaddr_ipv4_with_snapshot, tc)
1099 RUN_HOST_TESTS(tc, "snapshot_htaddr4", AF_INET, TEST_GETHOSTBYADDR, false);
1102 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6);
1103 ATF_TC_BODY(gethostbyaddr_ipv6, tc)
1106 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false);
1109 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_AI_V4MAPPED);
1110 ATF_TC_BODY(gethostbyaddr_ipv6_AI_V4MAPPED, tc)
1113 ipnode_flags = AI_V4MAPPED;
1114 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
1117 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot);
1118 ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot, tc)
1121 RUN_HOST_TESTS(tc, "snapshot_htaddr6", AF_INET6, TEST_GETHOSTBYADDR, false);
1124 ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED);
1125 ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc)
1128 ipnode_flags = AI_V4MAPPED;
1129 RUN_HOST_TESTS(tc, "snapshot_htaddr6map", AF_INET6, TEST_GETHOSTBYADDR, true);
1132 ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv4);
1133 ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv4, tc)
1136 RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
1139 ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv6);
1140 ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv6, tc)
1143 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
1146 ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv4);
1147 ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv4, tc)
1150 RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
1153 ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv6);
1154 ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv6, tc)
1157 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
1160 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4);
1161 ATF_TC_BODY(gethostbyname2_ipv4, tc)
1164 RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
1167 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4_with_snapshot);
1168 ATF_TC_BODY(gethostbyname2_ipv4_with_snapshot, tc)
1171 RUN_HOST_TESTS(tc, "snapshot_htname4", AF_INET, TEST_GETHOSTBYNAME2, false);
1174 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6);
1175 ATF_TC_BODY(gethostbyname2_ipv6, tc)
1178 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
1181 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_AI_V4MAPPED);
1182 ATF_TC_BODY(gethostbyname2_ipv6_AI_V4MAPPED, tc)
1185 ipnode_flags = AI_V4MAPPED;
1186 RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
1189 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot);
1190 ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot, tc)
1193 RUN_HOST_TESTS(tc, "snapshot_htname6", AF_INET6, TEST_GETHOSTBYNAME2, false);
1196 ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED);
1197 ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED, tc)
1200 ipnode_flags = AI_V4MAPPED;
1201 RUN_HOST_TESTS(tc, "snapshot_htname6map", AF_INET6, TEST_GETHOSTBYNAME2, true);
1204 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4);
1205 ATF_TC_BODY(getipnodebyaddr_ipv4, tc)
1208 RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false);
1211 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4_with_snapshot);
1212 ATF_TC_BODY(getipnodebyaddr_ipv4_with_snapshot, tc)
1215 RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr4", AF_INET, TEST_GETHOSTBYADDR, false);
1218 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv4);
1219 ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv4, tc)
1222 RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
1225 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6);
1226 ATF_TC_BODY(getipnodebyaddr_ipv6, tc)
1229 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false);
1232 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED);
1233 ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED, tc)
1236 ipnode_flags = AI_V4MAPPED;
1237 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
1240 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG);
1241 ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG, tc)
1244 ipnode_flags = AI_V4MAPPED_CFG;
1245 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
1248 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL);
1249 ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc)
1252 ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
1253 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
1256 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot);
1257 ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot, tc)
1260 RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr6", AF_INET6, TEST_GETHOSTBYADDR, false);
1263 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED);
1264 ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc)
1267 ipnode_flags = AI_V4MAPPED;
1268 RUN_IPNODE_TESTS(tc,
1269 "snapshot_ipnodeaddr6_AI_V4MAPPED", AF_INET6,
1270 TEST_GETHOSTBYADDR, true);
1273 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG);
1274 ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc)
1277 ipnode_flags = AI_V4MAPPED_CFG;
1278 RUN_IPNODE_TESTS(tc,
1279 "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG", AF_INET6,
1280 TEST_GETHOSTBYADDR, true);
1283 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
1284 ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc)
1287 ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
1288 RUN_IPNODE_TESTS(tc,
1289 "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6,
1290 TEST_GETHOSTBYADDR, true);
1293 ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv6);
1294 ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv6, tc)
1297 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
1300 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4);
1301 ATF_TC_BODY(getipnodebyname_ipv4, tc)
1304 RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
1307 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot);
1308 ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot, tc)
1311 RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4", AF_INET, TEST_GETHOSTBYNAME2, false);
1314 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_AI_ADDRCONFIG);
1315 ATF_TC_BODY(getipnodebyname_ipv4_AI_ADDRCONFIG, tc)
1318 ipnode_flags = AI_ADDRCONFIG;
1319 RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
1322 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG);
1323 ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG, tc)
1326 ipnode_flags = AI_ADDRCONFIG;
1327 RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4_AI_ADDRCONFIG", AF_INET,
1328 TEST_GETHOSTBYNAME2, false);
1331 ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv4);
1332 ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv4, tc)
1335 RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
1338 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6);
1339 ATF_TC_BODY(getipnodebyname_ipv6, tc)
1342 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
1345 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot);
1346 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot, tc)
1349 RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6", AF_INET6, TEST_GETHOSTBYNAME2, false);
1352 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_ADDRCONFIG);
1353 ATF_TC_BODY(getipnodebyname_ipv6_AI_ADDRCONFIG, tc)
1356 ipnode_flags = AI_ADDRCONFIG;
1357 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
1360 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED);
1361 ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED, tc)
1364 ipnode_flags = AI_V4MAPPED;
1365 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
1368 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG);
1369 ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG, tc)
1372 ipnode_flags = AI_V4MAPPED_CFG;
1373 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
1376 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
1377 ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc)
1380 ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
1381 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
1384 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL);
1385 ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc)
1388 ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
1389 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
1392 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED);
1393 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED, tc)
1396 ipnode_flags = AI_V4MAPPED;
1397 RUN_IPNODE_TESTS(tc,
1398 "snapshot_ipnodename6_AI_V4MAPPED", AF_INET6,
1399 TEST_GETHOSTBYNAME2, true);
1402 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG);
1403 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc)
1406 ipnode_flags = AI_V4MAPPED_CFG;
1407 RUN_IPNODE_TESTS(tc,
1408 "snapshot_ipnodename6_AI_V4MAPPED_CFG", AF_INET6,
1409 TEST_GETHOSTBYNAME2, true);
1412 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
1413 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc)
1416 ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
1417 RUN_IPNODE_TESTS(tc,
1418 "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ADDRCONFIG", AF_INET6,
1419 TEST_GETHOSTBYNAME2, false);
1422 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
1423 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc)
1426 ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
1427 RUN_IPNODE_TESTS(tc,
1428 "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6,
1429 TEST_GETHOSTBYNAME2, true);
1432 ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG);
1433 ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG, tc)
1436 ipnode_flags = AI_ADDRCONFIG;
1437 RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6_AI_ADDRCONFIG", AF_INET6,
1438 TEST_GETHOSTBYNAME2, false);
1441 ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv6);
1442 ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv6, tc)
1445 RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
1452 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4);
1453 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4_with_snapshot);
1454 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6);
1455 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_AI_V4MAPPED); /* XXX */
1456 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot);
1457 ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED);
1458 ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv4);
1459 ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv6);
1461 /* gethostbyname2 */
1462 ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv4);
1463 ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv6);
1464 ATF_TP_ADD_TC(tp, gethostbyname2_ipv4);
1465 ATF_TP_ADD_TC(tp, gethostbyname2_ipv4_with_snapshot);
1466 ATF_TP_ADD_TC(tp, gethostbyname2_ipv6);
1467 ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_AI_V4MAPPED);
1468 ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot);
1469 ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED);
1471 /* getipnodebyaddr */
1472 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4);
1473 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4_with_snapshot);
1474 ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv4);
1475 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6);
1476 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED);
1477 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG);
1478 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL);
1479 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot);
1480 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED);
1481 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG);
1482 ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
1483 ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv6);
1485 /* getipnodebyname */
1486 ATF_TP_ADD_TC(tp, getipnodebyname_ipv4);
1487 ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot);
1488 ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_AI_ADDRCONFIG);
1489 ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG);
1490 ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv4);
1491 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6);
1492 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot);
1493 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_ADDRCONFIG);
1494 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED);
1495 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG);
1496 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
1497 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL);
1498 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED);
1499 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG);
1500 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
1501 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
1502 ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG);
1503 ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv6);
1505 return (atf_no_error());