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