t_sockaddr.c revision ca41b452ede6feaa9d8739ec3cae19389a7b0d03
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉/*
9e0d0a279b956cc2eae41c00a6846b0ca8c617c6Automatic Updater * Copyright (C) 1999, 2000 Internet Software Consortium.
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 *
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * Permission to use, copy, modify, and distribute this software for any
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * purpose with or without fee is hereby granted, provided that the above
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * copyright notice and this permission notice appear in all copies.
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 *
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 * SOFTWARE.
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 */
8ac908b38a2fd9b780ae3a27ff26932a17823ae0Mark Andrews
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <config.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <stdio.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <stdlib.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <unistd.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <isc/assertions.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <isc/error.h>
2fff8b8280779a25fbdb891b2d3d9b435d2084f0Tatuya JINMEI 神明達哉#include <isc/mem.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <isc/sockaddr.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉#include <isc/result.h>
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉#include <tests/t_api.h>
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉static int
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉test_isc_sockaddr_eqaddrprefix(void) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews struct in_addr ina_a;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews struct in_addr ina_b;
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 struct in_addr ina_c;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews isc_sockaddr_t isa_a;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews isc_sockaddr_t isa_b;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 isc_sockaddr_t isa_c;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (inet_pton(AF_INET, "194.100.32.87", &ina_a) < 0)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (inet_pton(AF_INET, "194.100.32.80", &ina_b) < 0)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (inet_pton(AF_INET, "194.101.32.87", &ina_c) < 0)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews isc_sockaddr_fromin(&isa_a, &ina_a, 0);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews isc_sockaddr_fromin(&isa_b, &ina_b, 42);
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 isc_sockaddr_fromin(&isa_c, &ina_c, 0);
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 0) != ISC_TRUE)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 29) != ISC_TRUE)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 30) != ISC_FALSE)
7f1785d0ded8897082abacec5219b27feac755afFrancis Dupont return T_FAIL;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 32) != ISC_FALSE)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 8) != ISC_TRUE)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 if (isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 16) != ISC_FALSE)
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_FAIL;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉 return T_PASS;
bfcc5ae79a46c5c55e6cf1a9fe4d70a957712d2bTatuya JINMEI 神明達哉}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewsstatic void
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewst1(void) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews int result;
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews t_assert("isc_sockaddr_eqaddrprefix", 1, T_REQUIRED,
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "isc_sockaddr_eqaddrprefix() returns ISC_TRUE when "
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews "prefixes of a and b are equal, and ISC_FALSE when "
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 "they are not equal");
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 result = test_isc_sockaddr_eqaddrprefix();
8ac908b38a2fd9b780ae3a27ff26932a17823ae0Mark Andrews t_result(result);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
2fff8b8280779a25fbdb891b2d3d9b435d2084f0Tatuya JINMEI 神明達哉testspec_t T_testlist[] = {
2fff8b8280779a25fbdb891b2d3d9b435d2084f0Tatuya JINMEI 神明達哉 { t1, "isc_sockaddr_eqaddrprefix" },
7c60401dbd4dce617dffc685c269fca224c589adTatuya JINMEI 神明達哉 { NULL, NULL }
7c60401dbd4dce617dffc685c269fca224c589adTatuya JINMEI 神明達哉};
7c60401dbd4dce617dffc685c269fca224c589adTatuya JINMEI 神明達哉
7c60401dbd4dce617dffc685c269fca224c589adTatuya JINMEI 神明達哉