ip_parse_common_args.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * ip.c "ip" utility frontend.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  11. *
  12. *
  13. * Changes:
  14. *
  15. * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
  16. */
  17. #include <string.h>
  18. #include "libbb.h"
  19. #include "utils.h"
  20. #include "ip_common.h"
  21. int preferred_family = AF_UNSPEC;
  22. int oneline = 0;
  23. char * _SL_ = NULL;
  24. void ip_parse_common_args(int *argcp, char ***argvp)
  25. {
  26. int argc = *argcp;
  27. char **argv = *argvp;
  28. while (argc > 1) {
  29. char *opt = argv[1];
  30. if (strcmp(opt,"--") == 0) {
  31. argc--;
  32. argv++;
  33. break;
  34. }
  35. if (opt[0] != '-')
  36. break;
  37. if (opt[1] == '-')
  38. opt++;
  39. if (matches(opt, "-family") == 0) {
  40. argc--;
  41. argv++;
  42. if (!argv[1])
  43. bb_show_usage();
  44. if (strcmp(argv[1], "inet") == 0)
  45. preferred_family = AF_INET;
  46. else if (strcmp(argv[1], "inet6") == 0)
  47. preferred_family = AF_INET6;
  48. else if (strcmp(argv[1], "link") == 0)
  49. preferred_family = AF_PACKET;
  50. else
  51. invarg(argv[1], "protocol family");
  52. } else if (strcmp(opt, "-4") == 0) {
  53. preferred_family = AF_INET;
  54. } else if (strcmp(opt, "-6") == 0) {
  55. preferred_family = AF_INET6;
  56. } else if (strcmp(opt, "-0") == 0) {
  57. preferred_family = AF_PACKET;
  58. } else if (matches(opt, "-oneline") == 0) {
  59. ++oneline;
  60. } else {
  61. bb_show_usage();
  62. }
  63. argc--;
  64. argv++;
  65. }
  66. _SL_ = oneline ? "\\" : "\n" ;
  67. *argcp = argc;
  68. *argvp = argv;
  69. }