diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index 0c6473be..5cc61e01 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -73,7 +73,6 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_timeout.c \ ares_update_servers.c \ ares_version.c \ - bitncmp.c \ inet_net_pton.c \ inet_ntop.c \ windows_port.c @@ -98,7 +97,6 @@ HHEADERS = ares__buf.h \ ares_strcasecmp.h \ ares_str.h \ ares_strsplit.h \ - bitncmp.h \ ares_setup.h \ setup_once.h diff --git a/src/lib/ares_getaddrinfo.c b/src/lib/ares_getaddrinfo.c index d5c440b2..af5b5a6e 100644 --- a/src/lib/ares_getaddrinfo.c +++ b/src/lib/ares_getaddrinfo.c @@ -57,7 +57,6 @@ #endif #include "ares.h" -#include "bitncmp.h" #include "ares_private.h" #include "ares_dns.h" diff --git a/src/lib/ares_gethostbyname.c b/src/lib/ares_gethostbyname.c index f0316de4..299c35b4 100644 --- a/src/lib/ares_gethostbyname.c +++ b/src/lib/ares_gethostbyname.c @@ -45,7 +45,6 @@ #include "ares.h" #include "ares_inet_net_pton.h" -#include "bitncmp.h" #include "ares_platform.h" #include "ares_private.h" diff --git a/src/lib/bitncmp.c b/src/lib/bitncmp.c deleted file mode 100644 index 0296316d..00000000 --- a/src/lib/bitncmp.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1996,1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * SPDX-License-Identifier: MIT - */ - -#ifndef HAVE_BITNCMP - -# include "ares_setup.h" -# include "bitncmp.h" - -/* - * int - * bitncmp(l, r, n) - * compare bit masks l and r, for n bits. - * return: - * <0, >0, or 0 in the libc tradition. - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), June 1996 - */ -int ares__bitncmp(const void *l, const void *r, size_t n) -{ - size_t lb; - size_t rb; - ares_ssize_t x; - size_t b; - - b = n / 8; - x = memcmp(l, r, b); - if (x || (n % 8) == 0) { - return (int)x; - } - - lb = ((const unsigned char *)l)[b]; - rb = ((const unsigned char *)r)[b]; - for (b = n % 8; b > 0; b--) { - if ((lb & 0x80) != (rb & 0x80)) { - if (lb & 0x80) { - return (1); - } - return (-1); - } - lb <<= 1; - rb <<= 1; - } - return (0); -} -#endif diff --git a/src/lib/bitncmp.h b/src/lib/bitncmp.h deleted file mode 100644 index 0c4b9c39..00000000 --- a/src/lib/bitncmp.h +++ /dev/null @@ -1,35 +0,0 @@ -/* MIT License - * - * Copyright (c) 2005 Dominick Meglio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * SPDX-License-Identifier: MIT - */ -#ifndef __ARES_BITNCMP_H -#define __ARES_BITNCMP_H - -#ifndef HAVE_BITNCMP -int ares__bitncmp(const void *l, const void *r, size_t n); -#else -# define ares__bitncmp(x, y, z) bitncmp(x, y, z) -#endif - -#endif /* __ARES_BITNCMP_H */ diff --git a/test/ares-test-internal.cc b/test/ares-test-internal.cc index 4a39077f..5ba15bbd 100644 --- a/test/ares-test-internal.cc +++ b/test/ares-test-internal.cc @@ -38,7 +38,6 @@ extern "C" { #include "ares_strsplit.h" #include "ares_private.h" #include "ares__htable.h" -#include "bitncmp.h" #ifdef HAVE_ARPA_INET_H #include @@ -275,30 +274,6 @@ TEST_F(LibraryTest, MallocDataFail) { EXPECT_EQ(nullptr, ares_malloc_data(ARES_DATATYPE_MX_REPLY)); } -TEST(Misc, Bitncmp) { - byte a[4] = {0x80, 0x01, 0x02, 0x03}; - byte b[4] = {0x80, 0x01, 0x02, 0x04}; - byte c[4] = {0x01, 0xFF, 0x80, 0x02}; - EXPECT_GT(0, ares__bitncmp(a, b, sizeof(a)*8)); - EXPECT_LT(0, ares__bitncmp(b, a, sizeof(a)*8)); - EXPECT_EQ(0, ares__bitncmp(a, a, sizeof(a)*8)); - - for (size_t ii = 1; ii < (3*8+5); ii++) { - EXPECT_EQ(0, ares__bitncmp(a, b, ii)); - EXPECT_EQ(0, ares__bitncmp(b, a, ii)); - EXPECT_LT(0, ares__bitncmp(a, c, ii)); - EXPECT_GT(0, ares__bitncmp(c, a, ii)); - } - - // Last byte differs at 5th bit - EXPECT_EQ(0, ares__bitncmp(a, b, 3*8 + 3)); - EXPECT_EQ(0, ares__bitncmp(a, b, 3*8 + 4)); - EXPECT_EQ(0, ares__bitncmp(a, b, 3*8 + 5)); - EXPECT_GT(0, ares__bitncmp(a, b, 3*8 + 6)); - EXPECT_GT(0, ares__bitncmp(a, b, 3*8 + 7)); -} - - TEST_F(LibraryTest, ReadLine) { TempFile temp("abcde\n0123456789\nXYZ\n012345678901234567890\n\n"); FILE *fp = fopen(temp.filename(), "r");