xref: /freebsd/contrib/sendmail/libsm/t-inet6_ntop.c (revision 5dd76dd0cc19450133aa379ce0ce4a68ae07fb39)
1*5dd76dd0SGregory Neil Shapiro /*
2*5dd76dd0SGregory Neil Shapiro  * Copyright (c) 2013 Proofpoint, Inc. and its suppliers.
3*5dd76dd0SGregory Neil Shapiro  *	All rights reserved.
4*5dd76dd0SGregory Neil Shapiro  *
5*5dd76dd0SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
6*5dd76dd0SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
7*5dd76dd0SGregory Neil Shapiro  * the sendmail distribution.
8*5dd76dd0SGregory Neil Shapiro  */
9*5dd76dd0SGregory Neil Shapiro 
10*5dd76dd0SGregory Neil Shapiro #include <sm/gen.h>
11*5dd76dd0SGregory Neil Shapiro SM_IDSTR(id, "@(#)$Id: t-inet6_ntop.c,v 1.2 2013/11/22 20:51:43 ca Exp $")
12*5dd76dd0SGregory Neil Shapiro 
13*5dd76dd0SGregory Neil Shapiro #include <sm/conf.h>
14*5dd76dd0SGregory Neil Shapiro #if NETINET6
15*5dd76dd0SGregory Neil Shapiro #include <sm/io.h>
16*5dd76dd0SGregory Neil Shapiro #include <sm/test.h>
17*5dd76dd0SGregory Neil Shapiro #include <sm/string.h>
18*5dd76dd0SGregory Neil Shapiro #include <sys/socket.h>
19*5dd76dd0SGregory Neil Shapiro #include <netinet/in.h>
20*5dd76dd0SGregory Neil Shapiro #include <arpa/inet.h>
21*5dd76dd0SGregory Neil Shapiro 
22*5dd76dd0SGregory Neil Shapiro static char *ipv6f[] = {
23*5dd76dd0SGregory Neil Shapiro 	"1234:5678:9abc:def0:fedc:dead:f00f:101",
24*5dd76dd0SGregory Neil Shapiro 	"1080:0:0:0:8:800:200c:417a",
25*5dd76dd0SGregory Neil Shapiro 	"ff01:0:0:0:0:0:0:43",
26*5dd76dd0SGregory Neil Shapiro 	"0:0:0:0:0:0:0:1",
27*5dd76dd0SGregory Neil Shapiro 	"1:0:0:0:0:0:0:1",
28*5dd76dd0SGregory Neil Shapiro 	"0:1:0:0:0:0:0:1",
29*5dd76dd0SGregory Neil Shapiro 	"0:0:1:0:0:0:0:1",
30*5dd76dd0SGregory Neil Shapiro 	"0:0:0:1:0:0:0:1",
31*5dd76dd0SGregory Neil Shapiro 	"0:0:0:0:1:0:0:1",
32*5dd76dd0SGregory Neil Shapiro 	"0:0:0:0:0:1:0:1",
33*5dd76dd0SGregory Neil Shapiro 	"0:0:0:0:0:0:1:1",
34*5dd76dd0SGregory Neil Shapiro 	"1:a:b:c:d:e:f:9",
35*5dd76dd0SGregory Neil Shapiro 	"0:0:0:0:0:0:0:0",
36*5dd76dd0SGregory Neil Shapiro 	NULL
37*5dd76dd0SGregory Neil Shapiro };
38*5dd76dd0SGregory Neil Shapiro 
39*5dd76dd0SGregory Neil Shapiro static void
40*5dd76dd0SGregory Neil Shapiro test()
41*5dd76dd0SGregory Neil Shapiro {
42*5dd76dd0SGregory Neil Shapiro 	int i, r;
43*5dd76dd0SGregory Neil Shapiro 	struct sockaddr_in6 addr;
44*5dd76dd0SGregory Neil Shapiro 	char *ip, *ipf, ipv6str[INET6_ADDRSTRLEN];
45*5dd76dd0SGregory Neil Shapiro 
46*5dd76dd0SGregory Neil Shapiro 	for (i = 0; (ip = ipv6f[i]) != NULL; i++) {
47*5dd76dd0SGregory Neil Shapiro 		r = inet_pton(AF_INET6, ip, &addr.sin6_addr);
48*5dd76dd0SGregory Neil Shapiro 		SM_TEST(r == 1);
49*5dd76dd0SGregory Neil Shapiro 		ipf = sm_inet6_ntop(&addr.sin6_addr, ipv6str, sizeof(ipv6str));
50*5dd76dd0SGregory Neil Shapiro 		SM_TEST(ipf != NULL);
51*5dd76dd0SGregory Neil Shapiro 		SM_TEST(strcmp(ipf, ip) == 0);
52*5dd76dd0SGregory Neil Shapiro 	}
53*5dd76dd0SGregory Neil Shapiro }
54*5dd76dd0SGregory Neil Shapiro 
55*5dd76dd0SGregory Neil Shapiro int
56*5dd76dd0SGregory Neil Shapiro main(argc, argv)
57*5dd76dd0SGregory Neil Shapiro 	int argc;
58*5dd76dd0SGregory Neil Shapiro 	char **argv;
59*5dd76dd0SGregory Neil Shapiro {
60*5dd76dd0SGregory Neil Shapiro 	sm_test_begin(argc, argv, "test inet6_ntop");
61*5dd76dd0SGregory Neil Shapiro 	test();
62*5dd76dd0SGregory Neil Shapiro 	return sm_test_end();
63*5dd76dd0SGregory Neil Shapiro }
64*5dd76dd0SGregory Neil Shapiro #else /* NETINET6 */
65*5dd76dd0SGregory Neil Shapiro 
66*5dd76dd0SGregory Neil Shapiro int
67*5dd76dd0SGregory Neil Shapiro main(argc, argv)
68*5dd76dd0SGregory Neil Shapiro 	int argc;
69*5dd76dd0SGregory Neil Shapiro 	char **argv;
70*5dd76dd0SGregory Neil Shapiro {
71*5dd76dd0SGregory Neil Shapiro 	return 0;
72*5dd76dd0SGregory Neil Shapiro }
73*5dd76dd0SGregory Neil Shapiro #endif /* NETINET6 */
74