A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

rate.c 1.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "btcli.h"
  2. void
  3. usage_rate(void)
  4. {
  5. printf(
  6. "Set upload and download rate.\n"
  7. "\n"
  8. "Usage: rate <up> <down>\n"
  9. "\n"
  10. "Arguments:\n"
  11. "<up> <down>\n"
  12. "\tThe up/down rate in KB/s\n"
  13. "\n"
  14. );
  15. exit(1);
  16. }
  17. static struct option start_opts [] = {
  18. { "help", no_argument, NULL, 'H' },
  19. {NULL, 0, NULL, 0}
  20. };
  21. static unsigned
  22. parse_rate(char *rate)
  23. {
  24. unsigned out;
  25. char *end;
  26. out = strtol(rate, &end, 10);
  27. if (end == rate)
  28. usage_rate();
  29. if ((end[0] != '\0') && (end[1] != '\0'))
  30. usage_rate();
  31. switch(end[0]) {
  32. case 'g':
  33. case 'G':
  34. out <<= 30;
  35. break;
  36. case 'm':
  37. case 'M':
  38. out <<= 20;
  39. break;
  40. case '\0': /* default is 'k' */
  41. case 'k':
  42. case 'K':
  43. out <<= 10;
  44. break;
  45. case 'b':
  46. case 'B':
  47. break;
  48. default:
  49. usage_rate();
  50. }
  51. return out;
  52. }
  53. void
  54. cmd_rate(int argc, char **argv)
  55. {
  56. int ch;
  57. unsigned up, down;
  58. while ((ch = getopt_long(argc, argv, "", start_opts, NULL)) != -1)
  59. usage_rate();
  60. argc -= optind;
  61. argv += optind;
  62. if (argc < 2)
  63. usage_rate();
  64. up = parse_rate(argv[0]);
  65. down = parse_rate(argv[1]);
  66. btpd_connect();
  67. handle_ipc_res(btpd_rate(ipc, up, down), "rate", argv[1]);
  68. }