Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / ntomask.c
bloba607fe3132adc2a0bad71f9c6c0d9a717935a443
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002-2005 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: ntomask.c,v 1.6.2.1 2006/06/16 17:21:07 darrenr Exp
9 */
11 #include "ipf.h"
13 int ntomask(v, nbits, ap)
14 int v, nbits;
15 u_32_t *ap;
17 u_32_t mask;
19 if (nbits < 0)
20 return -1;
22 switch (v)
24 case 4 :
25 if (nbits > 32 || use_inet6 != 0)
26 return -1;
27 if (nbits == 0) {
28 mask = 0;
29 } else {
30 mask = 0xffffffff;
31 mask <<= (32 - nbits);
33 *ap = htonl(mask);
34 break;
36 case 6 :
37 if ((nbits > 128) || (use_inet6 == 0))
38 return -1;
39 fill6bits(nbits, ap);
40 break;
42 default :
43 return -1;
45 return 0;