2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: genmask.c,v 1.7 2003/11/11 13:40:15 darrenr Exp $
12 int genmask(msk
, mskp
)
19 if (strchr(msk
, '.') || strchr(msk
, 'x') || strchr(msk
, ':')) {
20 /* possibly of the form xxx.xxx.xxx.xxx
24 if (inet_pton(AF_INET6
, msk
, mskp
) != 1)
28 if (inet_aton(msk
, (struct in_addr
*)mskp
) == 0)
32 * set x most significant bits
34 bits
= (int)strtol(msk
, &endptr
, 0);
36 if ((*endptr
!= '\0') ||
37 ((bits
> 32) && !use_inet6
) || (bits
< 0) ||
38 ((bits
> 128) && use_inet6
))
40 if (*endptr
!= '\0' || bits
> 32 || bits
< 0)
45 fill6bits(bits
, mskp
);
51 *mskp
= htonl(0xffffffff << (32 - bits
));