xref: /freebsd/sbin/ipf/libipf/count6bits.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
1 
2 /*
3  * Copyright (C) 2012 by Darren Reed.
4  *
5  * See the IPFILTER.LICENCE file for details on licencing.
6  *
7  * $Id$
8  */
9 
10 #include "ipf.h"
11 
12 
13 int
count6bits(u_32_t * msk)14 count6bits(u_32_t *msk)
15 {
16 	int i = 0, k;
17 	u_32_t j;
18 
19 	for (k = 3; k >= 0; k--)
20 		if (msk[k] == 0xffffffff)
21 			i += 32;
22 		else {
23 			for (j = msk[k]; j; j <<= 1)
24 				if (j & 0x80000000)
25 					i++;
26 		}
27 	return (i);
28 }
29