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