freebsd5/sys/netipsec/key.c
/*
 * compare two buffers with mask.
 * IN:
 *	addr1: source
 *	addr2: object
 *	bits:  Number of bits to compare
 * OUT:
 *	1 : equal
 *	0 : not equal
 */
compare two buffers with mask.
compare two buffers with mask .
static int
key_bbcmp(const void *a1, const void *a2, u_int bits)
{
	const unsigned char *p1 = a1;
	const unsigned char *p2 = a2;
	if (p1 == NULL || p2 == NULL)
		return (p1 == p2);
	while (bits >= 8) {
		if (*p1++ != *p2++)
			return 0;
		bits -= 8;
	}
	if (bits > 0) {
		u_int8_t mask = ~((1<<(8-bits))-1);
		if ((*p1 & mask) != (*p2 & mask))
			return 0;
	}
	return 1;	
}
static int key_bbcmp ( const void * a1 , const void * a2 , u_int bits ) { const unsigned char * p1 = a1 ; const unsigned char * p2 = a2 ; if ( p1 == NULL || p2 == NULL ) return ( p1 == p2 ) ; while ( bits >= 8 ) { if ( * p1 ++ != * p2 ++ ) return 0 ; bits -= 8 ; } if ( bits > 0 ) { u_int8_t mask = ~ ( ( 1 << ( 8 - bits ) ) - 1 ) ; if ( ( * p1 & mask ) != ( * p2 & mask ) ) return 0 ; } return 1 ; }
compare two buffers with mask.
compare two buffers with mask .
/* XXX: This could be considerably faster if we compare a word
	 * at a time, but it is complicated on LSB Endian machines */ /* Handle null pointers */ /* Match! */