dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / ipf / lib / common / ntomask.c
bloba52d475f95bdcf370d38098f5879fd2f08361c1a
1 /*
2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include "ipf.h"
14 int ntomask(v, nbits, ap)
15 int v, nbits;
16 u_32_t *ap;
18 u_32_t mask;
20 if (nbits < 0)
21 return -1;
23 switch (v)
25 case 4 :
26 if (nbits > 32 || use_inet6 != 0)
27 return -1;
28 if (nbits == 0) {
29 mask = 0;
30 } else {
31 mask = 0xffffffff;
32 mask <<= (32 - nbits);
34 *ap = htonl(mask);
35 break;
37 case 6 :
38 if (nbits > 128)
39 return -1;
40 fill6bits(nbits, ap);
41 break;
43 default :
44 return -1;
46 return 0;