15dd76dd0SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro * Copyright (c) 2013 Proofpoint, Inc. and its suppliers.
35dd76dd0SGregory Neil Shapiro * All rights reserved.
45dd76dd0SGregory Neil Shapiro *
55dd76dd0SGregory Neil Shapiro * By using this file, you agree to the terms and conditions set
65dd76dd0SGregory Neil Shapiro * forth in the LICENSE file which can be found at the top level of
75dd76dd0SGregory Neil Shapiro * the sendmail distribution.
85dd76dd0SGregory Neil Shapiro */
95dd76dd0SGregory Neil Shapiro
105dd76dd0SGregory Neil Shapiro #include <sm/gen.h>
11*4313cc83SGregory Neil Shapiro SM_IDSTR(id, "@(#)$Id: t-inet6_ntop.c,v 1.2 2013-11-22 20:51:43 ca Exp $")
125dd76dd0SGregory Neil Shapiro
135dd76dd0SGregory Neil Shapiro #include <sm/conf.h>
145dd76dd0SGregory Neil Shapiro #if NETINET6
155dd76dd0SGregory Neil Shapiro #include <sm/io.h>
165dd76dd0SGregory Neil Shapiro #include <sm/test.h>
175dd76dd0SGregory Neil Shapiro #include <sm/string.h>
185dd76dd0SGregory Neil Shapiro #include <sys/socket.h>
195dd76dd0SGregory Neil Shapiro #include <netinet/in.h>
205dd76dd0SGregory Neil Shapiro #include <arpa/inet.h>
215dd76dd0SGregory Neil Shapiro
225dd76dd0SGregory Neil Shapiro static char *ipv6f[] = {
235dd76dd0SGregory Neil Shapiro "1234:5678:9abc:def0:fedc:dead:f00f:101",
245dd76dd0SGregory Neil Shapiro "1080:0:0:0:8:800:200c:417a",
255dd76dd0SGregory Neil Shapiro "ff01:0:0:0:0:0:0:43",
265dd76dd0SGregory Neil Shapiro "0:0:0:0:0:0:0:1",
275dd76dd0SGregory Neil Shapiro "1:0:0:0:0:0:0:1",
285dd76dd0SGregory Neil Shapiro "0:1:0:0:0:0:0:1",
295dd76dd0SGregory Neil Shapiro "0:0:1:0:0:0:0:1",
305dd76dd0SGregory Neil Shapiro "0:0:0:1:0:0:0:1",
315dd76dd0SGregory Neil Shapiro "0:0:0:0:1:0:0:1",
325dd76dd0SGregory Neil Shapiro "0:0:0:0:0:1:0:1",
335dd76dd0SGregory Neil Shapiro "0:0:0:0:0:0:1:1",
345dd76dd0SGregory Neil Shapiro "1:a:b:c:d:e:f:9",
355dd76dd0SGregory Neil Shapiro "0:0:0:0:0:0:0:0",
365dd76dd0SGregory Neil Shapiro NULL
375dd76dd0SGregory Neil Shapiro };
385dd76dd0SGregory Neil Shapiro
395dd76dd0SGregory Neil Shapiro static void
test()405dd76dd0SGregory Neil Shapiro test()
415dd76dd0SGregory Neil Shapiro {
425dd76dd0SGregory Neil Shapiro int i, r;
435dd76dd0SGregory Neil Shapiro struct sockaddr_in6 addr;
445dd76dd0SGregory Neil Shapiro char *ip, *ipf, ipv6str[INET6_ADDRSTRLEN];
455dd76dd0SGregory Neil Shapiro
465dd76dd0SGregory Neil Shapiro for (i = 0; (ip = ipv6f[i]) != NULL; i++) {
475dd76dd0SGregory Neil Shapiro r = inet_pton(AF_INET6, ip, &addr.sin6_addr);
485dd76dd0SGregory Neil Shapiro SM_TEST(r == 1);
495dd76dd0SGregory Neil Shapiro ipf = sm_inet6_ntop(&addr.sin6_addr, ipv6str, sizeof(ipv6str));
505dd76dd0SGregory Neil Shapiro SM_TEST(ipf != NULL);
515dd76dd0SGregory Neil Shapiro SM_TEST(strcmp(ipf, ip) == 0);
525dd76dd0SGregory Neil Shapiro }
535dd76dd0SGregory Neil Shapiro }
545dd76dd0SGregory Neil Shapiro
555dd76dd0SGregory Neil Shapiro int
main(argc,argv)565dd76dd0SGregory Neil Shapiro main(argc, argv)
575dd76dd0SGregory Neil Shapiro int argc;
585dd76dd0SGregory Neil Shapiro char **argv;
595dd76dd0SGregory Neil Shapiro {
605dd76dd0SGregory Neil Shapiro sm_test_begin(argc, argv, "test inet6_ntop");
615dd76dd0SGregory Neil Shapiro test();
625dd76dd0SGregory Neil Shapiro return sm_test_end();
635dd76dd0SGregory Neil Shapiro }
645dd76dd0SGregory Neil Shapiro #else /* NETINET6 */
655dd76dd0SGregory Neil Shapiro
665dd76dd0SGregory Neil Shapiro int
675dd76dd0SGregory Neil Shapiro main(argc, argv)
685dd76dd0SGregory Neil Shapiro int argc;
695dd76dd0SGregory Neil Shapiro char **argv;
705dd76dd0SGregory Neil Shapiro {
715dd76dd0SGregory Neil Shapiro return 0;
725dd76dd0SGregory Neil Shapiro }
735dd76dd0SGregory Neil Shapiro #endif /* NETINET6 */
74