Add support for Econet hardware; internationalize Token Ring.
[platform/upstream/net-tools.git] / lib / hw.c
1 /*
2  * lib/hw.c   This file contains the top-level part of the hardware
3  *              support functions module.
4  *
5  * Version:     $Id: hw.c,v 1.14 1999/05/16 16:41:12 philip Exp $
6  *
7  * Maintainer:  Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
8  *
9  * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10  *              Copyright 1993 MicroWalt Corporation
11  *
12  *980701 {1.21}  Arnaldo C. Melo       GNU gettext instead of catgets
13  *
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.
19  */
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <errno.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include "config.h"
29 #include "net-support.h"
30 #include "pathnames.h"
31 #include "intl.h"
32
33 extern struct hwtype unspec_hwtype;
34 extern struct hwtype loop_hwtype;
35
36 extern struct hwtype slip_hwtype;
37 extern struct hwtype cslip_hwtype;
38 extern struct hwtype slip6_hwtype;
39 extern struct hwtype cslip6_hwtype;
40 extern struct hwtype adaptive_hwtype;
41
42 extern struct hwtype ether_hwtype;
43 extern struct hwtype fddi_hwtype;
44 extern struct hwtype hippi_hwtype;
45 extern struct hwtype tr_hwtype;
46
47 extern struct hwtype ax25_hwtype;
48 extern struct hwtype rose_hwtype;
49 extern struct hwtype netrom_hwtype;
50 extern struct hwtype tunnel_hwtype;
51
52 extern struct hwtype ash_hwtype;
53
54 extern struct hwtype ppp_hwtype;
55
56 extern struct hwtype arcnet_hwtype;
57
58 extern struct hwtype dlci_hwtype;
59 extern struct hwtype frad_hwtype;
60
61 extern struct hwtype hdlc_hwtype;
62 extern struct hwtype lapb_hwtype;
63
64 extern struct hwtype sit_hwtype;
65
66 extern struct hwtype irda_hwtype;
67
68 extern struct hwtype ec_hwtype;
69
70 static struct hwtype *hwtypes[] =
71 {
72
73     &loop_hwtype,
74
75 #if HAVE_HWSLIP
76     &slip_hwtype,
77     &cslip_hwtype,
78     &slip6_hwtype,
79     &cslip6_hwtype,
80     &adaptive_hwtype,
81 #endif
82 #if HAVE_HWASH
83     &ash_hwtype,
84 #endif
85 #if HAVE_HWETHER
86     &ether_hwtype,
87 #endif
88 #if HAVE_HWTR
89     &tr_hwtype,
90 #endif
91 #if HAVE_HWAX25
92     &ax25_hwtype,
93 #endif
94 #if HAVE_HWNETROM
95     &netrom_hwtype,
96 #endif
97 #if HAVE_HWROSE
98     &rose_hwtype,
99 #endif
100 #if HAVE_HWTUNNEL
101     &tunnel_hwtype,
102 #endif
103 #if HAVE_HWPPP
104     &ppp_hwtype,
105 #endif
106 #if HAVE_HWHDLCLAPB
107     &hdlc_hwtype,
108     &lapb_hwtype,
109 #endif
110 #if HAVE_HWARC
111     &arcnet_hwtype,
112 #endif
113 #if HAVE_HWFR
114     &dlci_hwtype,
115     &frad_hwtype,
116 #endif
117 #if HAVE_HWSIT
118     &sit_hwtype,
119 #endif
120 #if HAVE_HWFDDI
121     &fddi_hwtype,
122 #endif
123 #if HAVE_HWHIPPI
124     &hippi_hwtype,
125 #endif
126 #if HAVE_HWIRDA
127     &irda_hwtype,
128 #endif
129 #if HAVE_HWEC
130     &ec_hwtype,
131 #endif
132     &unspec_hwtype,
133     NULL
134 };
135
136 static short sVhwinit = 0;
137
138 void hwinit()
139 {
140     loop_hwtype.title = _("Local Loopback");
141     unspec_hwtype.title = _("UNSPEC");
142 #if HAVE_HWSLIP
143     slip_hwtype.title = _("Serial Line IP");
144     cslip_hwtype.title = _("VJ Serial Line IP");
145     slip6_hwtype.title = _("6-bit Serial Line IP");
146     cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
147     adaptive_hwtype.title = _("Adaptive Serial Line IP");
148 #endif
149 #if HAVE_HWETHER
150     ether_hwtype.title = _("Ethernet");
151 #endif
152 #if HAVE_HWASH
153     ash_hwtype.title = _("Ash");
154 #endif
155 #if HAVE_HWFDDI
156     fddi_hwtype.title = _("Fiber Distributed Data Interface");
157 #endif
158 #if HAVE_HWHIPPI
159     hippi_hwtype.title = _("HIPPI");
160 #endif
161 #if HAVE_HWAX25
162     ax25_hwtype.title = _("AMPR AX.25");
163 #endif
164 #if HAVE_HWROSE
165     rose_hwtype.title = _("AMPR ROSE");
166 #endif
167 #if HAVE_HWNETROM
168     netrom_hwtype.title = _("AMPR NET/ROM");
169 #endif
170 #if HAVE_HWTUNNEL
171     tunnel_hwtype.title = _("IPIP Tunnel");
172 #endif
173 #if HAVE_HWPPP
174     ppp_hwtype.title = _("Point-to-Point Protocol");
175 #endif
176 #if HAVE_HWHDLCLAPB
177     hdlc_hwtype.title = _("(Cisco)-HDLC");
178     lapb_hwtype.title = _("LAPB");
179 #endif
180 #if HAVE_HWARC
181     arcnet_hwtype.title = _("ARCnet");
182 #endif
183 #if HAVE_HWFR
184     dlci_hwtype.title = _("Frame Relay DLCI");
185     frad_hwtype.title = _("Frame Relay Access Device");
186 #endif
187 #if HAVE_HWSIT
188     sit_hwtype.title = _("IPv6-in-IPv4");
189 #endif
190 #if HAVE_HWIRDA
191     irda_hwtype.title = _("IrLAP");
192 #endif
193 #if HAVE_HWTR
194     tr_hwtype.title = _("16/4 Mbps Token Ring");
195 #endif
196 #if HAVE_HWEC
197     ec_hwtype.title = _("Econet");
198 #endif
199     sVhwinit = 1;
200 }
201
202 /* Check our hardware type table for this type. */
203 struct hwtype *get_hwtype(const char *name)
204 {
205     struct hwtype **hwp;
206
207     if (!sVhwinit)
208         hwinit();
209
210     hwp = hwtypes;
211     while (*hwp != NULL) {
212         if (!strcmp((*hwp)->name, name))
213             return (*hwp);
214         hwp++;
215     }
216     return (NULL);
217 }
218
219
220 /* Check our hardware type table for this type. */
221 struct hwtype *get_hwntype(int type)
222 {
223     struct hwtype **hwp;
224
225     if (!sVhwinit)
226         hwinit();
227
228     hwp = hwtypes;
229     while (*hwp != NULL) {
230         if ((*hwp)->type == type)
231             return (*hwp);
232         hwp++;
233     }
234     return (NULL);
235 }
236
237 /* type: 0=all, 1=ARPable */
238 void print_hwlist(int type) {
239     int count = 0;
240     char * txt;
241     struct hwtype **hwp;
242
243     if (!sVhwinit)
244         hwinit();
245
246     hwp = hwtypes;
247     while (*hwp != NULL) {
248         if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
249                 hwp++; continue;
250         }
251         if ((count % 3) == 0) fprintf(stderr,count?"\n    ":"    "); 
252         txt = (*hwp)->name; if (!txt) txt = "..";
253         fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
254         count++;
255         hwp++;
256     }
257     fprintf(stderr,"\n");
258 }
259
260 /* return 1 if address is all zeros */
261 int hw_null_address(struct hwtype *hw, void *ap)
262 {
263     unsigned int i;
264     unsigned char *address = (unsigned char *)ap;
265     for (i = 0; i < hw->alen; i++)
266         if (address[i])
267             return 0;
268     return 1;
269 }