sockaddr_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <isc/sockaddr.h>
00028 #include <isc/print.h>
00029 
00030 #include "isctest.h"
00031 
00032 /*
00033  * Individual unit tests
00034  */
00035 
00036 ATF_TC(sockaddr_hash);
00037 ATF_TC_HEAD(sockaddr_hash, tc) {
00038         atf_tc_set_md_var(tc, "descr", "sockaddr hash");
00039 }
00040 ATF_TC_BODY(sockaddr_hash, tc) {
00041         isc_result_t result;
00042         isc_sockaddr_t addr;
00043         struct in_addr in;
00044         struct in6_addr in6;
00045         unsigned int h1, h2, h3, h4;
00046         int ret;
00047 
00048         UNUSED(tc);
00049 
00050         result = isc_test_begin(NULL, ISC_TRUE);
00051         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00052 
00053         in.s_addr = inet_addr("127.0.0.1");
00054         isc_sockaddr_fromin(&addr, &in, 1);
00055         h1 = isc_sockaddr_hash(&addr, ISC_TRUE);
00056         h2 = isc_sockaddr_hash(&addr, ISC_FALSE);
00057         ATF_CHECK(h1 != h2);
00058 
00059         ret = inet_pton(AF_INET6, "::ffff:127.0.0.1", &in6);
00060         ATF_CHECK(ret == 1);
00061         isc_sockaddr_fromin6(&addr, &in6, 1);
00062         h3 = isc_sockaddr_hash(&addr, ISC_TRUE);
00063         h4 = isc_sockaddr_hash(&addr, ISC_FALSE);
00064         ATF_CHECK(h1 == h3);
00065         ATF_CHECK(h2 == h4);
00066 
00067         isc_test_end();
00068 }
00069 
00070 /*
00071  * Main
00072  */
00073 ATF_TP_ADD_TCS(tp) {
00074         ATF_TP_ADD_TC(tp, sockaddr_hash);
00075 
00076         return (atf_no_error());
00077 }
00078 

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha