- change columns of netstat -i/ifconfig -s to avoid run-into (Stefan Illner)
[oss-qm-packages.git] / plipconfig.c
blob1f972a7aaf2af1523ab29f3a7970bec14b1a0066
1 /*
3 plipconfig.c: plip-ifconfig program for the Linux PLIP device driver
4 Copyright (c) 1994 John Paul Morrison (VE7JPM).
6 version 0.2
8 Changed by Alan Cox, to reflect the way SIOCDEVPRIVATE is meant to work
9 and for the extra parameter added by Niibe.
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.
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.
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.
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.
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 <net/if.h>
39 #include <linux/if_plip.h>
41 #include "config.h"
42 #include "intl.h"
43 #include "net-support.h"
44 #include "version.h"
46 int opt_a = 0;
47 int opt_i = 0;
48 int opt_v = 0;
49 int skfd = -1;
51 struct ifreq ifr;
52 struct plipconf *plip;
54 char *Release = RELEASE,
55 *Version = "plipconfig 0.2",
56 *Signature = "John Paul Morrison, Alan Cox et al.";
58 static void version(void)
60 printf("%s\n%s\n%s\n", Release, Version, Signature);
61 exit(E_VERSION);
64 void usage(void)
66 fprintf(stderr, _("Usage: plipconfig [-a] [-i] [-v] interface\n"));
67 fprintf(stderr, _(" [nibble NN] [trigger NN]\n"));
68 fprintf(stderr, _(" plipconfig -V | --version\n"));
69 exit(-1);
72 void print_plip(void)
74 printf(_("%s\tnibble %lu trigger %lu\n"), ifr.ifr_name, plip->nibble, plip->trigger);
77 int main(int argc, char **argv)
79 int ret = 0;
80 char **spp;
82 #if I18N
83 setlocale (LC_ALL, "");
84 bindtextdomain("net-tools", "/usr/share/locale");
85 textdomain("net-tools");
86 #endif
88 if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
89 perror("socket");
90 exit(-1);
92 /* Find any options. */
93 argc--;
94 argv++;
95 while (argv[0] && *argv[0] == '-') {
96 if (!strcmp(*argv, "-a"))
97 opt_a = 1;
98 if (!strcmp(*argv, "-v"))
99 opt_v = 1;
100 if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version"))
101 version();
102 argv++;
103 argc--;
106 if (argc == 0)
107 usage();
109 spp = argv;
110 strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
111 plip=(struct plipconf *)&ifr.ifr_data;
113 plip->pcmd = PLIP_GET_TIMEOUT; /* get current settings for device */
114 if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0) {
115 perror("ioctl");
116 exit(-1);
118 if (*spp == (char *) NULL) {
119 print_plip();
120 (void) close(skfd);
121 exit(0);
123 while (*spp != (char *) NULL) {
124 if (!strcmp(*spp, "nibble")) {
125 if (*++spp == NULL)
126 usage();
127 plip->nibble = atoi(*spp);
128 spp++;
129 continue;
131 if (!strcmp(*spp, "trigger")) {
132 if (*++spp == NULL)
133 usage();
134 plip->trigger = atoi(*spp);
135 spp++;
136 continue;
138 usage();
141 plip->pcmd = PLIP_SET_TIMEOUT;
142 if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0)
143 perror("ioctl");
145 print_plip();
147 /* Close the socket. */
148 (void) close(skfd);
150 return (ret);