minor fix to return E_USAGE on -V instead of exit(0);
[oss-qm-packages.git] / lib / hw.c
blob49897483634997e3f9975c8de08eabec2b99fc8c
1 /*
2 * lib/hw.c This file contains the top-level part of the hardware
3 * support functions module.
5 * Version: $Id: hw.c,v 1.17 2000/05/20 13:38:10 pb Exp $
7 * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
9 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * Copyright 1993 MicroWalt Corporation
12 *980701 {1.21} Arnaldo C. Melo GNU gettext instead of catgets
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <net/if_arp.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <ctype.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include "config.h"
30 #include "net-support.h"
31 #include "pathnames.h"
32 #include "intl.h"
34 extern struct hwtype unspec_hwtype;
35 extern struct hwtype loop_hwtype;
37 extern struct hwtype slip_hwtype;
38 extern struct hwtype cslip_hwtype;
39 extern struct hwtype slip6_hwtype;
40 extern struct hwtype cslip6_hwtype;
41 extern struct hwtype adaptive_hwtype;
42 extern struct hwtype strip_hwtype;
44 extern struct hwtype ether_hwtype;
45 extern struct hwtype fddi_hwtype;
46 extern struct hwtype hippi_hwtype;
47 extern struct hwtype tr_hwtype;
48 #ifdef ARPHRD_IEEE802_TR
49 extern struct hwtype tr_hwtype1;
50 #endif
52 extern struct hwtype ax25_hwtype;
53 extern struct hwtype rose_hwtype;
54 extern struct hwtype netrom_hwtype;
55 extern struct hwtype x25_hwtype;
56 extern struct hwtype tunnel_hwtype;
58 extern struct hwtype ash_hwtype;
60 extern struct hwtype ppp_hwtype;
62 extern struct hwtype arcnet_hwtype;
64 extern struct hwtype dlci_hwtype;
65 extern struct hwtype frad_hwtype;
67 extern struct hwtype hdlc_hwtype;
68 extern struct hwtype lapb_hwtype;
70 extern struct hwtype sit_hwtype;
72 extern struct hwtype irda_hwtype;
74 extern struct hwtype ec_hwtype;
76 static struct hwtype *hwtypes[] =
79 &loop_hwtype,
81 #if HAVE_HWSLIP
82 &slip_hwtype,
83 &cslip_hwtype,
84 &slip6_hwtype,
85 &cslip6_hwtype,
86 &adaptive_hwtype,
87 #endif
88 #if HAVE_HWSTRIP
89 &strip_hwtype,
90 #endif
91 #if HAVE_HWASH
92 &ash_hwtype,
93 #endif
94 #if HAVE_HWETHER
95 &ether_hwtype,
96 #endif
97 #if HAVE_HWTR
98 &tr_hwtype,
99 #ifdef ARPHRD_IEEE802_TR
100 &tr_hwtype1,
101 #endif
102 #endif
103 #if HAVE_HWAX25
104 &ax25_hwtype,
105 #endif
106 #if HAVE_HWNETROM
107 &netrom_hwtype,
108 #endif
109 #if HAVE_HWROSE
110 &rose_hwtype,
111 #endif
112 #if HAVE_HWTUNNEL
113 &tunnel_hwtype,
114 #endif
115 #if HAVE_HWPPP
116 &ppp_hwtype,
117 #endif
118 #if HAVE_HWHDLCLAPB
119 &hdlc_hwtype,
120 &lapb_hwtype,
121 #endif
122 #if HAVE_HWARC
123 &arcnet_hwtype,
124 #endif
125 #if HAVE_HWFR
126 &dlci_hwtype,
127 &frad_hwtype,
128 #endif
129 #if HAVE_HWSIT
130 &sit_hwtype,
131 #endif
132 #if HAVE_HWFDDI
133 &fddi_hwtype,
134 #endif
135 #if HAVE_HWHIPPI
136 &hippi_hwtype,
137 #endif
138 #if HAVE_HWIRDA
139 &irda_hwtype,
140 #endif
141 #if HAVE_HWEC
142 &ec_hwtype,
143 #endif
144 #if HAVE_HWX25
145 &x25_hwtype,
146 #endif
147 &unspec_hwtype,
148 NULL
151 static short sVhwinit = 0;
153 void hwinit()
155 loop_hwtype.title = _("Local Loopback");
156 unspec_hwtype.title = _("UNSPEC");
157 #if HAVE_HWSLIP
158 slip_hwtype.title = _("Serial Line IP");
159 cslip_hwtype.title = _("VJ Serial Line IP");
160 slip6_hwtype.title = _("6-bit Serial Line IP");
161 cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
162 adaptive_hwtype.title = _("Adaptive Serial Line IP");
163 #endif
164 #if HAVE_HWETHER
165 ether_hwtype.title = _("Ethernet");
166 #endif
167 #if HAVE_HWASH
168 ash_hwtype.title = _("Ash");
169 #endif
170 #if HAVE_HWFDDI
171 fddi_hwtype.title = _("Fiber Distributed Data Interface");
172 #endif
173 #if HAVE_HWHIPPI
174 hippi_hwtype.title = _("HIPPI");
175 #endif
176 #if HAVE_HWAX25
177 ax25_hwtype.title = _("AMPR AX.25");
178 #endif
179 #if HAVE_HWROSE
180 rose_hwtype.title = _("AMPR ROSE");
181 #endif
182 #if HAVE_HWNETROM
183 netrom_hwtype.title = _("AMPR NET/ROM");
184 #endif
185 #if HAVE_HWX25
186 x25_hwtype.title = _("generic X.25");
187 #endif
188 #if HAVE_HWTUNNEL
189 tunnel_hwtype.title = _("IPIP Tunnel");
190 #endif
191 #if HAVE_HWPPP
192 ppp_hwtype.title = _("Point-to-Point Protocol");
193 #endif
194 #if HAVE_HWHDLCLAPB
195 hdlc_hwtype.title = _("(Cisco)-HDLC");
196 lapb_hwtype.title = _("LAPB");
197 #endif
198 #if HAVE_HWARC
199 arcnet_hwtype.title = _("ARCnet");
200 #endif
201 #if HAVE_HWFR
202 dlci_hwtype.title = _("Frame Relay DLCI");
203 frad_hwtype.title = _("Frame Relay Access Device");
204 #endif
205 #if HAVE_HWSIT
206 sit_hwtype.title = _("IPv6-in-IPv4");
207 #endif
208 #if HAVE_HWIRDA
209 irda_hwtype.title = _("IrLAP");
210 #endif
211 #if HAVE_HWTR
212 tr_hwtype.title = _("16/4 Mbps Token Ring");
213 #ifdef ARPHRD_IEEE802_TR
214 tr_hwtype1.title = _("16/4 Mbps Token Ring (New)") ;
215 #endif
216 #endif
217 #if HAVE_HWEC
218 ec_hwtype.title = _("Econet");
219 #endif
220 sVhwinit = 1;
223 /* Check our hardware type table for this type. */
224 struct hwtype *get_hwtype(const char *name)
226 struct hwtype **hwp;
228 if (!sVhwinit)
229 hwinit();
231 hwp = hwtypes;
232 while (*hwp != NULL) {
233 if (!strcmp((*hwp)->name, name))
234 return (*hwp);
235 hwp++;
237 return (NULL);
241 /* Check our hardware type table for this type. */
242 struct hwtype *get_hwntype(int type)
244 struct hwtype **hwp;
246 if (!sVhwinit)
247 hwinit();
249 hwp = hwtypes;
250 while (*hwp != NULL) {
251 if ((*hwp)->type == type)
252 return (*hwp);
253 hwp++;
255 return (NULL);
258 /* type: 0=all, 1=ARPable */
259 void print_hwlist(int type) {
260 int count = 0;
261 char * txt;
262 struct hwtype **hwp;
264 if (!sVhwinit)
265 hwinit();
267 hwp = hwtypes;
268 while (*hwp != NULL) {
269 if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
270 hwp++; continue;
272 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
273 txt = (*hwp)->name; if (!txt) txt = "..";
274 fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
275 count++;
276 hwp++;
278 fprintf(stderr,"\n");
281 /* return 1 if address is all zeros */
282 int hw_null_address(struct hwtype *hw, void *ap)
284 unsigned int i;
285 unsigned char *address = (unsigned char *)ap;
286 for (i = 0; i < hw->alen; i++)
287 if (address[i])
288 return 0;
289 return 1;