MCPcopy Index your code
hub / github.com/F-Stack/f-stack / parse_range

Function parse_range

tools/ipfw/dummynet.c:1860–1903  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

1858 * in the array v of size len.
1859 */
1860static int
1861parse_range(int ac, char *av[], uint32_t *v, int len)
1862{
1863 int n = 0;
1864 char *endptr, *s;
1865 uint32_t base[2];
1866
1867 if (v == NULL || len < 2) {
1868 v = base;
1869 len = 2;
1870 }
1871
1872 for (s = *av; s != NULL; av++, ac--) {
1873 v[0] = strtoul(s, &endptr, 10);
1874 v[1] = (*endptr != '-') ? v[0] :
1875 strtoul(endptr+1, &endptr, 10);
1876 if (*endptr == '\0') { /* prepare for next round */
1877 s = (ac > 0) ? *(av+1) : NULL;
1878 } else {
1879 if (*endptr != ',') {
1880 warn("invalid number: %s", s);
1881 s = ++endptr;
1882 continue;
1883 }
1884 /* continue processing from here */
1885 s = ++endptr;
1886 ac++;
1887 av--;
1888 }
1889 if (v[1] < v[0] ||
1890 v[0] >= DN_MAX_ID-1 ||
1891 v[1] >= DN_MAX_ID-1) {
1892 continue; /* invalid entry */
1893 }
1894 n++;
1895 /* translate if 'pipe list' */
1896 if (g_co.do_pipe == 1) {
1897 v[0] += DN_MAX_ID;
1898 v[1] += DN_MAX_ID;
1899 }
1900 v = (n*2 < len) ? v + 2 : base;
1901 }
1902 return n;
1903}
1904
1905/* main entry point for dummynet list functions. co.do_pipe indicates
1906 * which function we want to support.

Callers 1

dummynet_listFunction · 0.70

Calls 1

strtoulFunction · 0.85

Tested by

no test coverage detected