t-inet6_ntop.c revision 266692
162587Sitojun/*
278064Sume * Copyright (c) 2013 Proofpoint, Inc. and its suppliers.
362587Sitojun *	All rights reserved.
452904Sshin *
552904Sshin * By using this file, you agree to the terms and conditions set
652904Sshin * forth in the LICENSE file which can be found at the top level of
753541Sshin * the sendmail distribution.
852904Sshin */
952904Sshin
1052904Sshin#include <sm/gen.h>
1152904SshinSM_IDSTR(id, "@(#)$Id: t-inet6_ntop.c,v 1.2 2013-11-22 20:51:43 ca Exp $")
1252904Sshin
1352904Sshin#include <sm/conf.h>
1452904Sshin#if NETINET6
1552904Sshin#include <sm/io.h>
1652904Sshin#include <sm/test.h>
1752904Sshin#include <sm/string.h>
1852904Sshin#include <sys/socket.h>
1953541Sshin#include <netinet/in.h>
2052904Sshin#include <arpa/inet.h>
2152904Sshin
2252904Sshinstatic char *ipv6f[] = {
2352904Sshin	"1234:5678:9abc:def0:fedc:dead:f00f:101",
2452904Sshin	"1080:0:0:0:8:800:200c:417a",
2552904Sshin	"ff01:0:0:0:0:0:0:43",
2652904Sshin	"0:0:0:0:0:0:0:1",
2752904Sshin	"1:0:0:0:0:0:0:1",
2852904Sshin	"0:1:0:0:0:0:0:1",
2952904Sshin	"0:0:1:0:0:0:0:1",
3052904Sshin	"0:0:0:1:0:0:0:1",
3152904Sshin	"0:0:0:0:1:0:0:1",
3252904Sshin	"0:0:0:0:0:1:0:1",
3352904Sshin	"0:0:0:0:0:0:1:1",
3452904Sshin	"1:a:b:c:d:e:f:9",
3552904Sshin	"0:0:0:0:0:0:0:0",
3652904Sshin	NULL
3752904Sshin};
3852904Sshin
3952904Sshinstatic void
4052904Sshintest()
4152904Sshin{
4252904Sshin	int i, r;
4352904Sshin	struct sockaddr_in6 addr;
4452904Sshin	char *ip, *ipf, ipv6str[INET6_ADDRSTRLEN];
4552904Sshin
4652904Sshin	for (i = 0; (ip = ipv6f[i]) != NULL; i++) {
4752904Sshin		r = inet_pton(AF_INET6, ip, &addr.sin6_addr);
4852904Sshin		SM_TEST(r == 1);
4952904Sshin		ipf = sm_inet6_ntop(&addr.sin6_addr, ipv6str, sizeof(ipv6str));
5052904Sshin		SM_TEST(ipf != NULL);
5152904Sshin		SM_TEST(strcmp(ipf, ip) == 0);
5252904Sshin	}
5352904Sshin}
5452904Sshin
5552904Sshinint
5652904Sshinmain(argc, argv)
5752904Sshin	int argc;
5852904Sshin	char **argv;
5952904Sshin{
6052904Sshin	sm_test_begin(argc, argv, "test inet6_ntop");
6152904Sshin	test();
6252904Sshin	return sm_test_end();
6352904Sshin}
6452904Sshin#else /* NETINET6 */
6552904Sshin
6652904Sshinint
6752904Sshinmain(argc, argv)
6862587Sitojun	int argc;
6978064Sume	char **argv;
7057120Sshin{
7157120Sshin	return 0;
7262587Sitojun}
7362587Sitojun#endif /* NETINET6 */
7462587Sitojun