summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm/t-inet6_ntop.c
blob: ff3bef6a65a4e0e8159bf15ef149f80ce1c6451b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2013 Proofpoint, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include <sm/gen.h>
SM_IDSTR(id, "@(#)$Id: t-inet6_ntop.c,v 1.2 2013-11-22 20:51:43 ca Exp $")

#include <sm/conf.h>
#if NETINET6
#include <sm/io.h>
#include <sm/test.h>
#include <sm/string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

static char *ipv6f[] = {
	"1234:5678:9abc:def0:fedc:dead:f00f:101",
	"1080:0:0:0:8:800:200c:417a",
	"ff01:0:0:0:0:0:0:43",
	"0:0:0:0:0:0:0:1",
	"1:0:0:0:0:0:0:1",
	"0:1:0:0:0:0:0:1",
	"0:0:1:0:0:0:0:1",
	"0:0:0:1:0:0:0:1",
	"0:0:0:0:1:0:0:1",
	"0:0:0:0:0:1:0:1",
	"0:0:0:0:0:0:1:1",
	"1:a:b:c:d:e:f:9",
	"0:0:0:0:0:0:0:0",
	NULL
};

static void
test()
{
	int i, r;
	struct sockaddr_in6 addr;
	char *ip, *ipf, ipv6str[INET6_ADDRSTRLEN];

	for (i = 0; (ip = ipv6f[i]) != NULL; i++) {
		r = inet_pton(AF_INET6, ip, &addr.sin6_addr);
		SM_TEST(r == 1);
		ipf = sm_inet6_ntop(&addr.sin6_addr, ipv6str, sizeof(ipv6str));
		SM_TEST(ipf != NULL);
		SM_TEST(strcmp(ipf, ip) == 0);
	}
}

int
main(argc, argv)
	int argc;
	char **argv;
{
	sm_test_begin(argc, argv, "test inet6_ntop");
	test();
	return sm_test_end();
}
#else /* NETINET6 */

int
main(argc, argv)
	int argc;
	char **argv;
{
	return 0;
}
#endif /* NETINET6 */
OpenPOWER on IntegriCloud