Remove building with NOCRYPTO option
[minix3.git] / tests / lib / libc / inet / t_inet_addr.c
blobd7547fd7b3ff17de78616b821d5fb791886f70f0
1 /* $NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $ */
3 /*
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
11 * are met:
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>
38 #include <atf-c.h>
39 #include <stdio.h>
40 #include <string.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" };
53 struct in_addr ia;
54 const char *ian;
55 in_addr_t addr;
56 size_t i;
58 for (i = 0; i < __arraycount(addrs); i++) {
60 (void)fprintf(stderr, "checking %s\n", addrs[i]);;
62 addr = inet_addr(addrs[i]);
63 ia.s_addr = addr;
64 ian = inet_ntoa(ia);
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", "", " "};
84 struct in_addr ia;
85 const char *ian;
86 in_addr_t addr;
87 size_t i;
89 for (i = 0; i < __arraycount(addrs); i++) {
91 (void)fprintf(stderr, "checking %s\n", addrs[i]);;
93 addr = inet_addr(addrs[i]);
94 ia.s_addr = addr;
95 ian = inet_ntoa(ia);
97 ATF_REQUIRE(ian != NULL);
98 ATF_CHECK(strcmp(ian, addrs[i]) != 0);
102 ATF_TP_ADD_TCS(tp)
105 ATF_TP_ADD_TC(tp, inet_addr_basic);
106 ATF_TP_ADD_TC(tp, inet_addr_err);
108 return atf_no_error();