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