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