home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NET-TOOL.1 / NET-TOOL / net-tools / plipconfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-11  |  3.0 KB  |  135 lines

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