MCPcopy Create free account
hub / github.com/F-Stack/f-stack / read_bandwidth

Function read_bandwidth

tools/ipfw/dummynet.c:796–839  ·  view source on GitHub ↗

* Take as input a string describing a bandwidth value * and return the numeric bandwidth value. * set clocking interface or bandwidth value */

Source from the content-addressed store, hash-verified

794 * set clocking interface or bandwidth value
795 */
796static void
797read_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
841struct point {
842 double prob;

Callers 2

load_extra_delaysFunction · 0.85
ipfw_config_pipeFunction · 0.85

Calls 3

strtoulFunction · 0.85
_substrcmp2Function · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected