1 /* $NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __COPYRIGHT("@(#) Copyright (c) 2011\
33 The NetBSD Foundation, inc. All rights reserved.");
34 __RCSID("$NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $");
36 #include <arpa/inet.h>
42 ATF_TC(inet_addr_basic
);
43 ATF_TC_HEAD(inet_addr_basic
, tc
)
45 atf_tc_set_md_var(tc
, "descr", "Checks inet_addr(3)");
48 ATF_TC_BODY(inet_addr_basic
, tc
)
50 static const char *addrs
[] = {
51 "127.0.0.1", "99.99.99.99", "0.0.0.0", "255.255.255.255" };
58 for (i
= 0; i
< __arraycount(addrs
); i
++) {
60 (void)fprintf(stderr
, "checking %s\n", addrs
[i
]);;
62 addr
= inet_addr(addrs
[i
]);
66 ATF_REQUIRE(ian
!= NULL
);
67 ATF_CHECK(strcmp(ian
, addrs
[i
]) == 0);
71 ATF_TC(inet_addr_err
);
72 ATF_TC_HEAD(inet_addr_err
, tc
)
74 atf_tc_set_md_var(tc
, "descr", "Invalid addresses with inet_addr(3)");
77 ATF_TC_BODY(inet_addr_err
, tc
)
79 static const char *addrs
[] = {
80 ". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
81 "................................................",
82 "a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
89 for (i
= 0; i
< __arraycount(addrs
); i
++) {
91 (void)fprintf(stderr
, "checking %s\n", addrs
[i
]);;
93 addr
= inet_addr(addrs
[i
]);
97 ATF_REQUIRE(ian
!= NULL
);
98 ATF_CHECK(strcmp(ian
, addrs
[i
]) != 0);
105 ATF_TP_ADD_TC(tp
, inet_addr_basic
);
106 ATF_TP_ADD_TC(tp
, inet_addr_err
);
108 return atf_no_error();