1 /* $NetBSD: t_print.c,v 1.2 2014/12/03 13:10:49 christos Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_print.c,v 1.2 2014/12/03 13:10:49 christos Exp $");
34 #include "netinet6/in6_print.c"
35 #include "netinet/in_print.c"
50 IN6ADDR_LOOPBACK_INIT
,
55 IN6ADDR_NODELOCAL_ALLNODES_INIT
,
60 {{{ 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
61 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }}},
62 "1020:3040:5060:7080:102:304:506:708",
66 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0xff, 0xff, 0x88, 0x44, 0x22, 0x11 }}},
68 "::ffff:136.68.34.17",
75 ATF_TC_HEAD(in6_print
, tc
)
78 atf_tc_set_md_var(tc
, "descr", "printing of struct in6_addr");
81 ATF_TC_BODY(in6_print
, tc
)
83 char buf
[INET6_ADDRSTRLEN
];
85 size_t l
= sizeof(buf
);
87 for (size_t i
= 0; i
< __arraycount(tst
); i
++) {
88 r
= in6_print(buf
, l
, &tst
[i
].ia
);
89 ATF_REQUIRE_STREQ(buf
, tst
[i
].str
);
90 ATF_REQUIRE_EQ(r
, tst
[i
].len
);
94 for (size_t i
= 0; i
< __arraycount(tst
); i
++) {
95 r
= in6_print(buf
, l
, &tst
[i
].ia
);
96 ATF_CHECK(strncmp(buf
, tst
[i
].str
, l
- 1) == 0);
98 ATF_REQUIRE_EQ(buf
[l
- 1], '\0');
99 ATF_REQUIRE_EQ(r
, tst
[i
].len
);
104 ATF_TC_HEAD(sin6_print
, tc
)
107 atf_tc_set_md_var(tc
, "descr", "printing of sockaddr_in6");
110 ATF_TC_BODY(sin6_print
, tc
)
115 size_t l
= sizeof(buf
);
116 struct sockaddr_in6 sin6
;
117 memset(&sin6
, 0, sizeof(sin6
));
119 for (size_t i
= 0; i
< __arraycount(tst
); i
++) {
120 sin6
.sin6_addr
= tst
[i
].ia
;
121 sin6
.sin6_port
= (in_port_t
)htons(i
);
122 r
= sin6_print(buf
, l
, &sin6
);
124 e
= snprintf(res
, sizeof(res
), "%s", tst
[i
].str
);
126 e
= snprintf(res
, sizeof(res
), "[%s]:%zu",
129 ATF_REQUIRE_STREQ(buf
, res
);
130 ATF_REQUIRE_EQ(r
, e
);
134 for (size_t i
= 0; i
< __arraycount(tst
); i
++) {
135 sin6
.sin6_addr
= tst
[i
].ia
;
136 sin6
.sin6_port
= (in_port_t
)htons(i
);
137 r
= sin6_print(buf
, l
, &sin6
);
139 e
= snprintf(res
, l
, "%s", tst
[i
].str
);
141 e
= snprintf(res
, l
, "[%s]:%zu", tst
[i
].str
, i
);
143 ATF_REQUIRE_STREQ(buf
, res
);
144 ATF_REQUIRE_EQ(r
, e
);
151 ATF_TP_ADD_TC(tp
, in6_print
);
152 ATF_TP_ADD_TC(tp
, sin6_print
);
153 return atf_no_error();