FreeBSD/sbin/ipfw/dummynet.c
/*
 * Take as input a string describing a bandwidth value
 * and return the numeric bandwidth value.
 * set clocking interface or bandwidth value
 */
Take as input a string describing a bandwidth value
and return the numeric bandwidth value.
set clocking interface or bandwidth value
Take as input a string describing a bandwidth value and return the numeric bandwidth value . set clocking interface or bandwidth value
static void
read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen)
{
	if (*bandwidth != -1)
		warnx("duplicate token, override bandwidth value!");
	if (arg[0] >= 'a' && arg[0] <= 'z') {
		if (!if_name) {
			errx(1, "no if support");
		}
		if (namelen >= IFNAMSIZ)
			warn("interface name truncated");
		namelen--;
		strncpy(if_name, arg, namelen);
		if_name[namelen] = '\0';
		*bandwidth = 0;
	} else {	
		int bw;
		char *end = NULL;
		bw = strtoul(arg, &end, 0);
		if (*end == 'K' || *end == 'k') {
			end++;
			bw *= 1000;
		} else if (*end == 'M' || *end == 'm') {
			end++;
			bw *= 1000000;
		}
		if ((*end == 'B' &&
			_substrcmp2(end, "Bi", "Bit/s") != 0) ||
		    _substrcmp2(end, "by", "bytes") == 0)
			bw *= 8;
		if (bw < 0)
			errx(EX_DATAERR, "bandwidth too large");
		*bandwidth = bw;
		if (if_name)
			if_name[0] = '\0';
	}
}
static void read_bandwidth ( char * arg , int * bandwidth , char * if_name , int namelen ) { if ( * bandwidth != -1 ) warnx ( " " ) ; if ( arg [ 0 ] >= ' ' && arg [ 0 ] <= ' ' ) { if ( ! if_name ) { errx ( 1 , " " ) ; } if ( namelen >= IFNAMSIZ ) warn ( " " ) ; namelen -- ; strncpy ( if_name , arg , namelen ) ; if_name [ namelen ] = ' \0 ' ; * bandwidth = 0 ; } else { int bw ; char * end = NULL ; bw = strtoul ( arg , & end , 0 ) ; if ( * end == ' ' || * end == ' ' ) { end ++ ; bw *= 1000 ; } else if ( * end == ' ' || * end == ' ' ) { end ++ ; bw *= 1000000 ; } if ( ( * end == ' ' && _substrcmp2 ( end , " " , " " ) != 0 ) || _substrcmp2 ( end , " " , " " ) == 0 ) bw *= 8 ; if ( bw < 0 ) errx ( EX_DATAERR , " " ) ; * bandwidth = bw ; if ( if_name ) if_name [ 0 ] = ' \0 ' ; } }
Take as input a string describing a bandwidth value
 and return the numeric bandwidth value.
Take as input a string describing a bandwidth value and return the numeric bandwidth value .
/* interface name */ /* read bandwidth value */