svn commit: r193715 - head/sbin/ipfw

Alexey Dokuchaev danfe at FreeBSD.org
Mon Jun 8 14:43:56 UTC 2009


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


More information about the svn-src-head mailing list