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 fill6bits(bits, msk) 15 int bits; 16 u_int *msk; 17 { 18 if (bits == 0) { 19 msk[0] = 0; 20 msk[1] = 0; 21 msk[2] = 0; 22 msk[3] = 0; 23 return; 24 } 25 26 msk[0] = 0xffffffff; 27 msk[1] = 0xffffffff; 28 msk[2] = 0xffffffff; 29 msk[3] = 0xffffffff; 30 31 if (bits == 128) 32 return; 33 if (bits > 96) { 34 msk[3] = htonl(msk[3] << (128 - bits)); 35 } else if (bits > 64) { 36 msk[3] = 0; 37 msk[2] = htonl(msk[2] << (96 - bits)); 38 } else if (bits > 32) { 39 msk[3] = 0; 40 msk[2] = 0; 41 msk[1] = htonl(msk[1] << (64 - bits)); 42 } else { 43 msk[3] = 0; 44 msk[2] = 0; 45 msk[1] = 0; 46 msk[0] = htonl(msk[0] << (32 - bits)); 47 } 48 } 49