1 /* $NetBSD: t_sockaddr.c,v 1.5 2014/12/10 04:37:54 christos Exp $ */
4 * Copyright (C) 2004, 2007, 2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: t_sockaddr.c,v 1.14 2007/06/19 23:47:00 tbox Exp */
24 #include <isc/netaddr.h>
25 #include <isc/result.h>
26 #include <isc/sockaddr.h>
28 #include <tests/t_api.h>
31 test_isc_sockaddr_eqaddrprefix(void) {
39 if (inet_pton(AF_INET
, "194.100.32.87", &ina_a
) < 0)
41 if (inet_pton(AF_INET
, "194.100.32.80", &ina_b
) < 0)
43 if (inet_pton(AF_INET
, "194.101.32.87", &ina_c
) < 0)
45 isc_sockaddr_fromin(&isa_a
, &ina_a
, 0);
46 isc_sockaddr_fromin(&isa_b
, &ina_b
, 42);
47 isc_sockaddr_fromin(&isa_c
, &ina_c
, 0);
49 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_b
, 0) != ISC_TRUE
)
51 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_b
, 29) != ISC_TRUE
)
53 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_b
, 30) != ISC_FALSE
)
55 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_b
, 32) != ISC_FALSE
)
57 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_c
, 8) != ISC_TRUE
)
59 if (isc_sockaddr_eqaddrprefix(&isa_a
, &isa_c
, 16) != ISC_FALSE
)
68 t_assert("isc_sockaddr_eqaddrprefix", 1, T_REQUIRED
,
69 "isc_sockaddr_eqaddrprefix() returns ISC_TRUE when "
70 "prefixes of a and b are equal, and ISC_FALSE when "
71 "they are not equal");
72 result
= test_isc_sockaddr_eqaddrprefix();
77 test_isc_netaddr_masktoprefixlen(void) {
88 if (inet_pton(AF_INET
, "0.0.0.0", &na_a
) < 0)
90 if (inet_pton(AF_INET
, "255.255.255.254", &na_b
) < 0)
92 if (inet_pton(AF_INET
, "255.255.255.255", &na_c
) < 0)
94 if (inet_pton(AF_INET
, "255.255.255.0", &na_d
) < 0)
96 isc_netaddr_fromin(&ina_a
, &na_a
);
97 isc_netaddr_fromin(&ina_b
, &na_b
);
98 isc_netaddr_fromin(&ina_c
, &na_c
);
99 isc_netaddr_fromin(&ina_d
, &na_d
);
101 if (isc_netaddr_masktoprefixlen(&ina_a
, &plen
) != ISC_R_SUCCESS
)
106 if (isc_netaddr_masktoprefixlen(&ina_b
, &plen
) != ISC_R_SUCCESS
)
111 if (isc_netaddr_masktoprefixlen(&ina_c
, &plen
) != ISC_R_SUCCESS
)
116 if (isc_netaddr_masktoprefixlen(&ina_d
, &plen
) != ISC_R_SUCCESS
)
127 t_assert("isc_netaddr_masktoprefixlen", 1, T_REQUIRED
,
128 "isc_netaddr_masktoprefixlen() calculates "
129 "correct prefix lengths ");
130 result
= test_isc_netaddr_masktoprefixlen();
134 testspec_t T_testlist
[] = {
135 { (PFV
) t1
, "isc_sockaddr_eqaddrprefix" },
136 { (PFV
) t2
, "isc_netaddr_masktoprefixlen" },
142 main(int argc
, char **argv
) {
143 t_settests(T_testlist
);
144 return (t_main(argc
, argv
));