1 /* $NetBSD: sockaddr_test.c,v 1.1.1.3 2014/12/10 03:34:44 christos Exp $ */
2
3 /*
4 * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /* Id */
20
21 /*! \file */
22
23 #include <config.h>
24
25 #include <atf-c.h>
26
27 #include <unistd.h>
28
29 #include <isc/sockaddr.h>
30 #include <isc/print.h>
31
32 #include "isctest.h"
33
34 /*
35 * Individual unit tests
36 */
37
38 ATF_TC(sockaddr_hash);
ATF_TC_HEAD(sockaddr_hash,tc)39 ATF_TC_HEAD(sockaddr_hash, tc) {
40 atf_tc_set_md_var(tc, "descr", "sockaddr hash");
41 }
ATF_TC_BODY(sockaddr_hash,tc)42 ATF_TC_BODY(sockaddr_hash, tc) {
43 isc_result_t result;
44 isc_sockaddr_t addr;
45 struct in_addr in;
46 struct in6_addr in6;
47 unsigned int h1, h2, h3, h4;
48 int ret;
49
50 UNUSED(tc);
51
52 result = isc_test_begin(NULL, ISC_TRUE);
53 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
54
55 in.s_addr = inet_addr("127.0.0.1");
56 isc_sockaddr_fromin(&addr, &in, 1);
57 h1 = isc_sockaddr_hash(&addr, ISC_TRUE);
58 h2 = isc_sockaddr_hash(&addr, ISC_FALSE);
59 ATF_CHECK(h1 != h2);
60
61 ret = inet_pton(AF_INET6, "::ffff:127.0.0.1", &in6);
62 ATF_CHECK(ret == 1);
63 isc_sockaddr_fromin6(&addr, &in6, 1);
64 h3 = isc_sockaddr_hash(&addr, ISC_TRUE);
65 h4 = isc_sockaddr_hash(&addr, ISC_FALSE);
66 ATF_CHECK(h1 == h3);
67 ATF_CHECK(h2 == h4);
68
69 isc_test_end();
70 }
71
72 /*
73 * Main
74 */
ATF_TP_ADD_TCS(tp)75 ATF_TP_ADD_TCS(tp) {
76 ATF_TP_ADD_TC(tp, sockaddr_hash);
77
78 return (atf_no_error());
79 }
80
81