-static void die(char *msg) {
- fprintf(stderr, msg);
- exit(1);
-}
-
-static void set_max_bandwidth(char* arg) {
- char* units;
- long long mult = 1;
- long long value;
- units = arg + strspn(arg, "0123456789");
- if(strlen(units) > 1) {
- die("Invalid units\n");
- }
- if(strlen(units) == 1) {
- if(*units == 'k' || *units == 'K') {
- mult = 1024;
- }
- else if(*units == 'm' || *units == 'M') {
- mult = 1024 * 1024;
- }
- else if(*units == 'g' || *units == 'G') {
- mult = 1024 * 1024 * 1024;
- }
- }
- *units = '\0';
- if(sscanf(arg, "%lld", &value) != 1) {
- die("Error reading max bandwidth\n");
- }
- options.max_bandwidth = value * mult;
-}
-
-static void set_net_filter(char* arg) {
- char* mask;
-
- mask = strchr(arg, '/');
- if (mask == NULL) {
- die("Could not parse net/mask\n");
- }
- *mask = '\0';
- mask++;
- if (inet_aton(arg, &options.netfilternet) == 0)
- die("Invalid network address\n");
- /* Accept a netmask like /24 or /255.255.255.0. */
- if (mask[strspn(mask, "0123456789")] == '\0') {
- /* Whole string is numeric */
- int n;
- n = atoi(mask);
- if (n > 32) {
- die("Invalid netmask");
- }
- else {
- if(n == 32) {
- /* This needs to be special cased, although I don't fully
- * understand why -pdw
- */
- options.netfiltermask.s_addr = htonl(0xffffffffl);
- }
- else {
- u_int32_t mm = 0xffffffffl;
- mm >>= n;
- options.netfiltermask.s_addr = htonl(~mm);
- }
- }
- }
- else if (inet_aton(mask, &options.netfiltermask) == 0) {
- die("Invalid netmask\n");
- }
- options.netfilternet.s_addr = options.netfilternet.s_addr & options.netfiltermask.s_addr;
-
- options.netfilter = 1;
-
-}
-