xref: /illumos-gate/usr/src/cmd/ipf/lib/common/fill6bits.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * $Id: fill6bits.c,v 1.5 2002/03/27 15:09:57 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate  */
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #include "ipf.h"
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate 
fill6bits(bits,msk)12*7c478bd9Sstevel@tonic-gate void fill6bits(bits, msk)
13*7c478bd9Sstevel@tonic-gate int bits;
14*7c478bd9Sstevel@tonic-gate u_int *msk;
15*7c478bd9Sstevel@tonic-gate {
16*7c478bd9Sstevel@tonic-gate 	if (bits == 0) {
17*7c478bd9Sstevel@tonic-gate 		msk[0] = 0;
18*7c478bd9Sstevel@tonic-gate 		msk[1] = 0;
19*7c478bd9Sstevel@tonic-gate 		msk[2] = 0;
20*7c478bd9Sstevel@tonic-gate 		msk[3] = 0;
21*7c478bd9Sstevel@tonic-gate 		return;
22*7c478bd9Sstevel@tonic-gate 	}
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate 	msk[0] = 0xffffffff;
25*7c478bd9Sstevel@tonic-gate 	msk[1] = 0xffffffff;
26*7c478bd9Sstevel@tonic-gate 	msk[2] = 0xffffffff;
27*7c478bd9Sstevel@tonic-gate 	msk[3] = 0xffffffff;
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate 	if (bits == 128)
30*7c478bd9Sstevel@tonic-gate 		return;
31*7c478bd9Sstevel@tonic-gate 	if (bits > 96) {
32*7c478bd9Sstevel@tonic-gate 		msk[3] = htonl(msk[3] << (128 - bits));
33*7c478bd9Sstevel@tonic-gate 	} else if (bits > 64) {
34*7c478bd9Sstevel@tonic-gate 		msk[3] = 0;
35*7c478bd9Sstevel@tonic-gate 		msk[2] = htonl(msk[2] << (96 - bits));
36*7c478bd9Sstevel@tonic-gate 	} else if (bits > 32) {
37*7c478bd9Sstevel@tonic-gate 		msk[3] = 0;
38*7c478bd9Sstevel@tonic-gate 		msk[2] = 0;
39*7c478bd9Sstevel@tonic-gate 		msk[1] = htonl(msk[1] << (64 - bits));
40*7c478bd9Sstevel@tonic-gate 	} else {
41*7c478bd9Sstevel@tonic-gate 		msk[3] = 0;
42*7c478bd9Sstevel@tonic-gate 		msk[2] = 0;
43*7c478bd9Sstevel@tonic-gate 		msk[1] = 0;
44*7c478bd9Sstevel@tonic-gate 		msk[0] = htonl(msk[0] << (32 - bits));
45*7c478bd9Sstevel@tonic-gate 	}
46*7c478bd9Sstevel@tonic-gate }
47