FreeBSD/sbin/ipfw/dummynet.c
/* Parse input for 'ipfw [pipe|sched|queue] show [range list]'
 * Returns the number of ranges, and possibly stores them
 * in the array v of size len.
 */
Parse input for 'ipfw [pipe|sched|queue] show [range list]'
Returns the number of ranges, and possibly stores them
in the array v of size len.
Parse input for ' ipfw [ pipe|sched|queue ] show [ range list ] ' Returns the number of ranges and possibly stores them in the array v of size len .
static int
parse_range(int ac, char *av[], uint32_t *v, int len)
{
	int n = 0;
	char *endptr, *s;
	uint32_t base[2];
	if (v == NULL || len < 2) {
		v = base;
		len = 2;
	}
	for (s = *av; s != NULL; av++, ac--) {
		v[0] = strtoul(s, &endptr, 10);
		v[1] = (*endptr != '-') ? v[0] :
			 strtoul(endptr+1, &endptr, 10);
		if (*endptr == '\0') { 
			s = (ac > 0) ? *(av+1) : NULL;
		} else {
			if (*endptr != ',') {
				warn("invalid number: %s", s);
				s = ++endptr;
				continue;
			}
			s = ++endptr;
			ac++;
			av--;
		}
		if (v[1] < v[0] ||
			v[1] >= DN_MAX_ID-1 ||
			v[1] >= DN_MAX_ID-1) {
			continue; 
		}
		n++;
		if (co.do_pipe == 1) {
			v[0] += DN_MAX_ID;
			v[1] += DN_MAX_ID;
		}
		v = (n*2 < len) ? v + 2 : base;
	}
	return n;
}
static int parse_range ( int ac , char * av [ ] , uint32_t * v , int len ) { int n = 0 ; char * endptr , * s ; uint32_t base [ 2 ] ; if ( v == NULL || len < 2 ) { v = base ; len = 2 ; } for ( s = * av ; s != NULL ; av ++ , ac -- ) { v [ 0 ] = strtoul ( s , & endptr , 10 ) ; v [ 1 ] = ( * endptr != ' ' ) ? v [ 0 ] : strtoul ( endptr + 1 , & endptr , 10 ) ; if ( * endptr == ' \0 ' ) { s = ( ac > 0 ) ? * ( av + 1 ) : NULL ; } else { if ( * endptr != ' ' ) { warn ( " " , s ) ; s = ++ endptr ; continue ; } s = ++ endptr ; ac ++ ; av -- ; } if ( v [ 1 ] < v [ 0 ] || v [ 1 ] >= DN_MAX_ID - 1 || v [ 1 ] >= DN_MAX_ID - 1 ) { continue ; } n ++ ; if ( co . do_pipe == 1 ) { v [ 0 ] += DN_MAX_ID ; v [ 1 ] += DN_MAX_ID ; } v = ( n * 2 < len ) ? v + 2 : base ; } return n ; }
Parse input for 'ipfw [pipe|sched|queue] show [range list]'
 Returns the number of ranges, and possibly stores them
 in the array v of size len.
Parse input for ' ipfw [ pipe|sched|queue ] show [ range list ] ' Returns the number of ranges and possibly stores them in the array v of size len .
/* prepare for next round */ /* continue processing from here */ /* invalid entry */ /* translate if 'pipe list' */