1*637Sml37995 /* 2*637Sml37995 * Copyright (C) 2002 by Darren Reed. 3*637Sml37995 * 4*637Sml37995 * See the IPFILTER.LICENCE file for details on licencing. 5*637Sml37995 * 6*637Sml37995 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 7*637Sml37995 * Use is subject to license terms. 8*637Sml37995 */ 9*637Sml37995 10*637Sml37995 #pragma ident "%Z%%M% %I% %E% SMI" 11*637Sml37995 120Sstevel@tonic-gate #include "ipf.h" 130Sstevel@tonic-gate ntomask(v,nbits,ap)140Sstevel@tonic-gateint ntomask(v, nbits, ap) 150Sstevel@tonic-gate int v, nbits; 160Sstevel@tonic-gate u_32_t *ap; 170Sstevel@tonic-gate { 180Sstevel@tonic-gate u_32_t mask; 190Sstevel@tonic-gate 200Sstevel@tonic-gate if (nbits < 0) 210Sstevel@tonic-gate return -1; 220Sstevel@tonic-gate 230Sstevel@tonic-gate switch (v) 240Sstevel@tonic-gate { 250Sstevel@tonic-gate case 4 : 260Sstevel@tonic-gate if (nbits > 32 || use_inet6 != 0) 270Sstevel@tonic-gate return -1; 280Sstevel@tonic-gate if (nbits == 0) { 290Sstevel@tonic-gate mask = 0; 300Sstevel@tonic-gate } else { 310Sstevel@tonic-gate mask = 0xffffffff; 320Sstevel@tonic-gate mask <<= (32 - nbits); 330Sstevel@tonic-gate } 340Sstevel@tonic-gate *ap = htonl(mask); 350Sstevel@tonic-gate break; 360Sstevel@tonic-gate 370Sstevel@tonic-gate case 6 : 38*637Sml37995 if (nbits > 128) 390Sstevel@tonic-gate return -1; 400Sstevel@tonic-gate fill6bits(nbits, ap); 410Sstevel@tonic-gate break; 420Sstevel@tonic-gate 430Sstevel@tonic-gate default : 440Sstevel@tonic-gate return -1; 450Sstevel@tonic-gate } 460Sstevel@tonic-gate return 0; 470Sstevel@tonic-gate } 48