mirror of https://github.com/c-ares/c-ares.git
parent
e55c48b8cf
commit
00b7a550b5
7 changed files with 151 additions and 38 deletions
@ -0,0 +1,59 @@ |
||||
/*
|
||||
* 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. |
||||
*/ |
||||
|
||||
#ifndef HAVE_BITNCMP |
||||
|
||||
#include <sys/types.h> |
||||
#include <string.h> |
||||
#include "bitncmp.h" |
||||
|
||||
/*
|
||||
* int |
||||
* bitncmp(l, r, n) |
||||
* compare bit masks l and r, for n bits. |
||||
* return: |
||||
* -1, 1, 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, int n) { |
||||
u_int lb, rb; |
||||
int x, b; |
||||
|
||||
b = n / 8; |
||||
x = memcmp(l, r, b); |
||||
if (x) |
||||
return (x); |
||||
|
||||
lb = ((const u_char *)l)[b]; |
||||
rb = ((const u_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 |
@ -0,0 +1,26 @@ |
||||
/* $Id$ */ |
||||
|
||||
/*
|
||||
* Permission to use, copy, modify, and distribute this |
||||
* software and its documentation for any purpose and without |
||||
* fee is hereby granted, provided that the above copyright |
||||
* notice appear in all copies and that both that copyright |
||||
* notice and this permission notice appear in supporting |
||||
* documentation, and that the name of M.I.T. not be used in |
||||
* advertising or publicity pertaining to distribution of the |
||||
* software without specific, written prior permission. |
||||
* M.I.T. makes no representations about the suitability of |
||||
* this software for any purpose. It is provided "as is" |
||||
* without express or implied warranty. |
||||
*/ |
||||
|
||||
#ifndef BITNCMP_H |
||||
#define BITNCMP_H |
||||
|
||||
#ifndef HAVE_BITNCMP |
||||
int ares_bitncmp(const void *l, const void *r, int n); |
||||
#else |
||||
#define ares_bitncmp(x,y,z) bitncmp(x,y,z) |
||||
#endif |
||||
|
||||
#endif /* BITNCMP_H */ |
Loading…
Reference in new issue