* Take as input a string describing a bandwidth value * and return the numeric bandwidth value. * set clocking interface or bandwidth value */
| 794 | * set clocking interface or bandwidth value |
| 795 | */ |
| 796 | static void |
| 797 | read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen) |
| 798 | { |
| 799 | if (*bandwidth != -1) |
| 800 | warnx("duplicate token, override bandwidth value!"); |
| 801 | |
| 802 | if (arg[0] >= 'a' && arg[0] <= 'z') { |
| 803 | if (!if_name) { |
| 804 | errx(1, "no if support"); |
| 805 | } |
| 806 | if (namelen >= IFNAMSIZ) |
| 807 | warn("interface name truncated"); |
| 808 | namelen--; |
| 809 | /* interface name */ |
| 810 | strlcpy(if_name, arg, namelen); |
| 811 | *bandwidth = 0; |
| 812 | } else { /* read bandwidth value */ |
| 813 | int bw; |
| 814 | char *end = NULL; |
| 815 | |
| 816 | bw = strtoul(arg, &end, 0); |
| 817 | if (*end == 'K' || *end == 'k') { |
| 818 | end++; |
| 819 | bw *= 1000; |
| 820 | } else if (*end == 'M' || *end == 'm') { |
| 821 | end++; |
| 822 | bw *= 1000000; |
| 823 | } else if (*end == 'G' || *end == 'g') { |
| 824 | end++; |
| 825 | bw *= 1000000000; |
| 826 | } |
| 827 | if ((*end == 'B' && |
| 828 | _substrcmp2(end, "Bi", "Bit/s") != 0) || |
| 829 | _substrcmp2(end, "by", "bytes") == 0) |
| 830 | bw *= 8; |
| 831 | |
| 832 | if (bw < 0) |
| 833 | errx(EX_DATAERR, "bandwidth too large"); |
| 834 | |
| 835 | *bandwidth = bw; |
| 836 | if (if_name) |
| 837 | if_name[0] = '\0'; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | struct point { |
| 842 | double prob; |
no test coverage detected