Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jun 2009 14:43:56 +0000
From:      Alexey Dokuchaev <danfe@FreeBSD.org>
To:        Luigi Rizzo <luigi@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r193715 - head/sbin/ipfw
Message-ID:  <20090608144355.GA3555@FreeBSD.org>
In-Reply-To: <200906081432.n58EWTs8032013@svn.freebsd.org>
References:  <200906081432.n58EWTs8032013@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Luigi Rizzo wrote:
> Author: luigi
> Date: Mon Jun  8 14:32:29 2009
> New Revision: 193715
> URL: http://svn.freebsd.org/changeset/base/193715
> 
> Log:
>   Permit the specification of bandwidth values within
>   "profile" files (bandwidth is mandatory when using a
>   profile, so it makes sense to have everything in one place).
>   
>   Update the manpage accordingly.
>   
> +/*
> + * Take as input a string describing a bandwidth value
> + * and return the numeric bandwidth value.
> + * set clocking interface or bandwidth value
> + */
> +void
> +read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen)
> +{
> +	if (*bandwidth != -1)
> +		warn("duplicate token, override bandwidth value!");
> +
> +	if (arg[0] >= 'a' && arg[0] <= 'z') {
> +		if (namelen >= IFNAMSIZ)
> +			warn("interface name truncated");
> +		namelen--;
> +		/* interface name */
> +		strncpy(if_name, arg, namelen);
> +		if_name[namelen] = '\0';
> +		*bandwidth = 0;
> +	} else {	/* read bandwidth value */
> +		int bw;
> +		char *end = NULL;
> +
> +		bw = strtoul(arg, &end, 0);
> +		if (*end == 'K' || *end == 'k') {
> +			end++;
> +			bw *= 1000;
> +		} else if (*end == 'M') {
> +			end++;
> +			bw *= 1000000;
> +		}

Couldn't expand_number(3) be used for that?

./danfe



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090608144355.GA3555>