simple patch from Ajax <ajax@firest0rm.org> (corrected) to print DDP
[oss-qm-packages.git] / lib / hw.c
blobc7143138687ca329cef92b43d397b4522ef5a476
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.18 2001/11/12 02:12:05 ecki 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 extern struct hwtype eui64_hwtype;
78 static struct hwtype *hwtypes[] =
81 &loop_hwtype,
83 #if HAVE_HWSLIP
84 &slip_hwtype,
85 &cslip_hwtype,
86 &slip6_hwtype,
87 &cslip6_hwtype,
88 &adaptive_hwtype,
89 #endif
90 #if HAVE_HWSTRIP
91 &strip_hwtype,
92 #endif
93 #if HAVE_HWASH
94 &ash_hwtype,
95 #endif
96 #if HAVE_HWETHER
97 &ether_hwtype,
98 #endif
99 #if HAVE_HWTR
100 &tr_hwtype,
101 #ifdef ARPHRD_IEEE802_TR
102 &tr_hwtype1,
103 #endif
104 #endif
105 #if HAVE_HWAX25
106 &ax25_hwtype,
107 #endif
108 #if HAVE_HWNETROM
109 &netrom_hwtype,
110 #endif
111 #if HAVE_HWROSE
112 &rose_hwtype,
113 #endif
114 #if HAVE_HWTUNNEL
115 &tunnel_hwtype,
116 #endif
117 #if HAVE_HWPPP
118 &ppp_hwtype,
119 #endif
120 #if HAVE_HWHDLCLAPB
121 &hdlc_hwtype,
122 &lapb_hwtype,
123 #endif
124 #if HAVE_HWARC
125 &arcnet_hwtype,
126 #endif
127 #if HAVE_HWFR
128 &dlci_hwtype,
129 &frad_hwtype,
130 #endif
131 #if HAVE_HWSIT
132 &sit_hwtype,
133 #endif
134 #if HAVE_HWFDDI
135 &fddi_hwtype,
136 #endif
137 #if HAVE_HWHIPPI
138 &hippi_hwtype,
139 #endif
140 #if HAVE_HWIRDA
141 &irda_hwtype,
142 #endif
143 #if HAVE_HWEC
144 &ec_hwtype,
145 #endif
146 #if HAVE_HWX25
147 &x25_hwtype,
148 #endif
149 #if HAVE_HWEUI64
150 &eui64_hwtype,
151 #endif
152 &unspec_hwtype,
153 NULL
156 static short sVhwinit = 0;
158 void hwinit()
160 loop_hwtype.title = _("Local Loopback");
161 unspec_hwtype.title = _("UNSPEC");
162 #if HAVE_HWSLIP
163 slip_hwtype.title = _("Serial Line IP");
164 cslip_hwtype.title = _("VJ Serial Line IP");
165 slip6_hwtype.title = _("6-bit Serial Line IP");
166 cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
167 adaptive_hwtype.title = _("Adaptive Serial Line IP");
168 #endif
169 #if HAVE_HWETHER
170 ether_hwtype.title = _("Ethernet");
171 #endif
172 #if HAVE_HWASH
173 ash_hwtype.title = _("Ash");
174 #endif
175 #if HAVE_HWFDDI
176 fddi_hwtype.title = _("Fiber Distributed Data Interface");
177 #endif
178 #if HAVE_HWHIPPI
179 hippi_hwtype.title = _("HIPPI");
180 #endif
181 #if HAVE_HWAX25
182 ax25_hwtype.title = _("AMPR AX.25");
183 #endif
184 #if HAVE_HWROSE
185 rose_hwtype.title = _("AMPR ROSE");
186 #endif
187 #if HAVE_HWNETROM
188 netrom_hwtype.title = _("AMPR NET/ROM");
189 #endif
190 #if HAVE_HWX25
191 x25_hwtype.title = _("generic X.25");
192 #endif
193 #if HAVE_HWTUNNEL
194 tunnel_hwtype.title = _("IPIP Tunnel");
195 #endif
196 #if HAVE_HWPPP
197 ppp_hwtype.title = _("Point-to-Point Protocol");
198 #endif
199 #if HAVE_HWHDLCLAPB
200 hdlc_hwtype.title = _("(Cisco)-HDLC");
201 lapb_hwtype.title = _("LAPB");
202 #endif
203 #if HAVE_HWARC
204 arcnet_hwtype.title = _("ARCnet");
205 #endif
206 #if HAVE_HWFR
207 dlci_hwtype.title = _("Frame Relay DLCI");
208 frad_hwtype.title = _("Frame Relay Access Device");
209 #endif
210 #if HAVE_HWSIT
211 sit_hwtype.title = _("IPv6-in-IPv4");
212 #endif
213 #if HAVE_HWIRDA
214 irda_hwtype.title = _("IrLAP");
215 #endif
216 #if HAVE_HWTR
217 tr_hwtype.title = _("16/4 Mbps Token Ring");
218 #ifdef ARPHRD_IEEE802_TR
219 tr_hwtype1.title = _("16/4 Mbps Token Ring (New)") ;
220 #endif
221 #endif
222 #if HAVE_HWEC
223 ec_hwtype.title = _("Econet");
224 #endif
225 #if HAVE_HWEUI64
226 eui64_hwtype.title = _("Generic EUI-64");
227 #endif
228 sVhwinit = 1;
231 /* Check our hardware type table for this type. */
232 struct hwtype *get_hwtype(const char *name)
234 struct hwtype **hwp;
236 if (!sVhwinit)
237 hwinit();
239 hwp = hwtypes;
240 while (*hwp != NULL) {
241 if (!strcmp((*hwp)->name, name))
242 return (*hwp);
243 hwp++;
245 return (NULL);
249 /* Check our hardware type table for this type. */
250 struct hwtype *get_hwntype(int type)
252 struct hwtype **hwp;
254 if (!sVhwinit)
255 hwinit();
257 hwp = hwtypes;
258 while (*hwp != NULL) {
259 if ((*hwp)->type == type)
260 return (*hwp);
261 hwp++;
263 return (NULL);
266 /* type: 0=all, 1=ARPable */
267 void print_hwlist(int type) {
268 int count = 0;
269 char * txt;
270 struct hwtype **hwp;
272 if (!sVhwinit)
273 hwinit();
275 hwp = hwtypes;
276 while (*hwp != NULL) {
277 if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
278 hwp++; continue;
280 if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
281 txt = (*hwp)->name; if (!txt) txt = "..";
282 fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
283 count++;
284 hwp++;
286 fprintf(stderr,"\n");
289 /* return 1 if address is all zeros */
290 int hw_null_address(struct hwtype *hw, void *ap)
292 unsigned int i;
293 unsigned char *address = (unsigned char *)ap;
294 for (i = 0; i < hw->alen; i++)
295 if (address[i])
296 return 0;
297 return 1;