move netstat to /usr/bin
[platform/upstream/net-tools.git] / plipconfig.c
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 <net/if.h>
39 #include <linux/if_plip.h>
40
41 #include "config.h"
42 #include "intl.h"
43 #include "net-support.h"
44 #include "version.h"
45
46 int skfd = -1;
47
48 struct ifreq ifr;
49 struct plipconf *plip;
50
51 char *Release = RELEASE,
52      *Version = "plipconfig 0.2",
53      *Signature = "John Paul Morrison, Alan Cox et al.";
54
55 static void version(void)
56 {
57     printf("%s\n%s\n%s\n", Release, Version, Signature);
58     exit(E_VERSION);
59 }
60
61 void usage(void)
62 {
63     fprintf(stderr, _("Usage: plipconfig interface [nibble NN] [trigger NN]\n"));
64     fprintf(stderr, _("       plipconfig -V | --version\n"));
65     fprintf(stderr, _("       plipconfig -h | --help\n"));
66     exit(E_USAGE);
67 }
68
69 void print_plip(void)
70 {
71     printf(_("%s\tnibble %lu  trigger %lu\n"), ifr.ifr_name, plip->nibble, plip->trigger);
72 }
73
74 int main(int argc, char **argv)
75 {
76     int ret = 0;
77     char **spp;
78
79 #if I18N
80     setlocale (LC_ALL, "");
81     bindtextdomain("net-tools", "/usr/share/locale");
82     textdomain("net-tools");
83 #endif
84
85     if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
86         perror("socket");
87         exit(-1);
88     }
89     /* Find any options. */
90     argc--;
91     argv++;
92     while (argv[0] && *argv[0] == '-') {
93         if (!strcmp(*argv, "-V") || !strcmp(*argv, "--version"))
94             version();
95         else
96             usage();
97         argv++;
98         argc--;
99     }
100
101     if (argc == 0)
102         usage();
103
104     spp = argv;
105     strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
106     plip=(struct plipconf *)&ifr.ifr_data;
107
108     plip->pcmd = PLIP_GET_TIMEOUT;      /* get current settings for device */
109     if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0) {
110         perror("ioctl");
111         exit(-1);
112     }
113     if (*spp == (char *) NULL) {
114         print_plip();
115         (void) close(skfd);
116         exit(0);
117     }
118     while (*spp != (char *) NULL) {
119         if (!strcmp(*spp, "nibble")) {
120             if (*++spp == NULL)
121                 usage();
122             plip->nibble = atoi(*spp);
123             spp++;
124             continue;
125         }
126         if (!strcmp(*spp, "trigger")) {
127             if (*++spp == NULL)
128                 usage();
129             plip->trigger = atoi(*spp);
130             spp++;
131             continue;
132         }
133         usage();
134     }
135
136     plip->pcmd = PLIP_SET_TIMEOUT;
137     if (ioctl(skfd, SIOCDEVPLIP, &ifr) < 0)
138         perror("ioctl");
139
140     print_plip();
141
142     /* Close the socket. */
143     (void) close(skfd);
144
145     return (ret);
146 }