1 #include "ipf.h" 2 3 int ntomask(v, nbits, ap) 4 int v, nbits; 5 u_32_t *ap; 6 { 7 u_32_t mask; 8 9 if (nbits < 0) 10 return -1; 11 12 switch (v) 13 { 14 case 4 : 15 if (nbits > 32 || use_inet6 != 0) 16 return -1; 17 if (nbits == 0) { 18 mask = 0; 19 } else { 20 mask = 0xffffffff; 21 mask <<= (32 - nbits); 22 } 23 *ap = htonl(mask); 24 break; 25 26 case 6 : 27 if ((nbits > 128) || (use_inet6 == 0)) 28 return -1; 29 fill6bits(nbits, ap); 30 break; 31 32 default : 33 return -1; 34 } 35 return 0; 36 } 37