plipconfig.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. plipconfig.c: plip-ifconfig program for the Linux PLIP device driver
  3. Copyright (c) 1994 John Paul Morrison (VE7JPM).
  4. version 0.2
  5. Changed by Alan Cox, to reflect the way SIOCDEVPRIVATE is meant to work
  6. and for the extra parameter added by Niibe.
  7. plipconfig is a quick hack to set PLIP parameters by using driver
  8. ioctls. plipconfig will no doubt be revised many times as the Linux
  9. PLIP driver and Linux 1.1 mutates.
  10. */
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License version 2, as
  14. published by the Free Software Foundation.
  15. This program is distributed in the hope that it will be useful, but
  16. WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software Foundation,
  21. Inc., 675 Mass Ave, Cambridge MA 02139, USA.
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <unistd.h>
  27. #include <sys/socket.h>
  28. #include <sys/ioctl.h>
  29. #include <net/if.h>
  30. #include <linux/if_plip.h>
  31. #include "config.h"
  32. #include "intl.h"
  33. #include "net-support.h"
  34. #include "version.h"
  35. #include "util.h"
  36. int skfd = -1;
  37. struct ifreq ifr;
  38. struct plipconf *plip;
  39. static char *Release = RELEASE, *Signature = "John Paul Morrison, Alan Cox et al.";
  40. static void version(void)
  41. {
  42. printf("%s\n%s\n", Release, Signature);
  43. exit(E_VERSION);
  44. }
  45. void usage(void)
  46. {
  47. fprintf(stderr, _("Usage: plipconfig interface [nibble NN] [trigger NN]\n"));
  48. fprintf(stderr, _(" plipconfig -V | --version\n"));
  49. fprintf(stderr, _(" plipconfig -h | --help\n"));
  50. exit(E_USAGE);
  51. }
  52. void print_plip(void)
  53. {
  54. printf(_("%s\tnibble %lu trigger %lu\n"), ifr.ifr_name, plip->nibble, plip->trigger);
  55. }
  56. int main(int argc, char **argv)
  57. {
  58. int ret = 0;
  59. char **spp;
  60. #if I18N
  61. setlocale (LC_ALL, "");
  62. bindtextdomain("net-tools", "/usr/share/locale");
  63. textdomain("net-tools");
  64. #endif
  65. if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  66. perror("socket");
  67. exit(-1);
  68. }
  69. /* Find any options. */
  70. argc--;
  71. argv++;
  72. while (argv[0] && *argv[0] == '-') {
  73. if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version"))
  74. version();
  75. else
  76. usage();
  77. argv++;
  78. argc--;
  79. }
  80. if (argc == 0)
  81. usage();
  82. spp = argv;
  83. safe_strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
  84. plip=(struct plipconf *)&ifr.ifr_data;
  85. plip->pcmd = PLIP_GET_TIMEOUT; /* get current settings for device */
  86. if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0) {
  87. perror("ioctl");
  88. exit(-1);
  89. }
  90. if (*spp == (char *) NULL) {
  91. print_plip();
  92. (void) close(skfd);
  93. exit(0);
  94. }
  95. while (*spp != (char *) NULL) {
  96. if (!strcmp(*spp, "nibble")) {
  97. if (*++spp == NULL)
  98. usage();
  99. plip->nibble = atoi(*spp);
  100. spp++;
  101. continue;
  102. }
  103. if (!strcmp(*spp, "trigger")) {
  104. if (*++spp == NULL)
  105. usage();
  106. plip->trigger = atoi(*spp);
  107. spp++;
  108. continue;
  109. }
  110. usage();
  111. }
  112. plip->pcmd = PLIP_SET_TIMEOUT;
  113. if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0)
  114. perror("ioctl");
  115. print_plip();
  116. /* Close the socket. */
  117. (void) close(skfd);
  118. return (ret);
  119. }