Yow. This is net-tools completely reindented.
[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.8 1998/11/15 20:10:13 freitag 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 static struct hwtype *hwtypes[] =
67 {
68
69     &loop_hwtype,
70
71 #if HAVE_HWSLIP
72     &slip_hwtype,
73     &cslip_hwtype,
74     &slip6_hwtype,
75     &cslip6_hwtype,
76     &adaptive_hwtype,
77 #endif
78 #if HAVE_HWASH
79     &ash_hwtype,
80 #endif
81 #if HAVE_HWETHER
82     &ether_hwtype,
83 #endif
84 #if HAVE_HWTR
85     &tr_hwtype,
86 #endif
87 #if HAVE_HWAX25
88     &ax25_hwtype,
89 #endif
90 #if HAVE_HWNETROM
91     &netrom_hwtype,
92 #endif
93 #if HAVE_HWTUNNEL
94     &tunnel_hwtype,
95 #endif
96 #if HAVE_HWPPP
97     &ppp_hwtype,
98 #endif
99 #if HAVE_HWHDLCLAPB
100     &hdlc_hwtype,
101     &lapb_hwtype,
102 #endif
103 #if HAVE_HWARC
104     &arcnet_hwtype,
105 #endif
106 #if HAVE_HWFR
107     &dlci_hwtype,
108     &frad_hwtype,
109 #endif
110 #if HAVE_HWSIT
111     &sit_hwtype,
112 #endif
113 #if HAVE_HWROSE
114     &rose_hwtype,
115 #endif
116 #if HAVE_HWFDDI
117     &fddi_hwtype,
118 #endif
119 #if HAVE_HWHIPPI
120     &hippi_hwtype,
121 #endif
122     &unspec_hwtype,
123     NULL
124 };
125
126 static short sVhwinit = 0;
127
128 void hwinit()
129 {
130     loop_hwtype.title = _("Local Loopback");
131     unspec_hwtype.title = _("UNSPEC");
132 #if HAVE_HWSLIP
133     slip_hwtype.title = _("Serial Line IP");
134     cslip_hwtype.title = _("VJ Serial Line IP");
135     slip6_hwtype.title = _("6-bit Serial Line IP");
136     cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
137     adaptive_hwtype.title = _("Adaptive Serial Line IP");
138 #endif
139 #if HAVE_HWETHER
140     ether_hwtype.title = _("Ethernet");
141 #endif
142 #if HAVE_HWASH
143     ash_hwtype.title = _("Ash");
144 #endif
145 #if HAVE_HWFDDI
146     fddi_hwtype.title = _("Fiber Distributed Data Interface");
147 #endif
148 #if HAVE_HWHIPPI
149     hippi_hwtype.title = _("HIPPI");
150 #endif
151 #if HAVE_HWAX25
152     ax25_hwtype.title = _("AMPR AX.25");
153 #endif
154 #if HAVE_HWROSE
155     rose_hwtype.title = _("AMPR ROSE");
156 #endif
157 #if HAVE_HWNETROM
158     netrom_hwtype.title = _("AMPR NET/ROM");
159 #endif
160 #if HAVE_HWTUNNEL
161     tunnel_hwtype.title = _("IPIP Tunnel");
162 #endif
163 #if HAVE_HWPPP
164     ppp_hwtype.title = _("Point-to-Point Protocol");
165 #endif
166 #if HAVE_HWHDLCLAPB
167     hdlc_hwtype.title = _("(Cisco)-HDLC");
168     lapb_hwtype.title = _("LAPB");
169 #endif
170 #if HAVE_HWARC
171     arcnet_hwtype.title = _("1.5Mbps ARCnet");
172 #endif
173 #if HAVE_HWFR
174     dlci_hwtype.title = _("Frame Relay DLCI");
175     frad_hwtype.title = _("Frame Relay Access Device");
176 #endif
177 #if HAVE_HWSIT
178     sit_hwtype.title = _("IPv6-in-IPv4");
179 #endif
180     sVhwinit = 1;
181 }
182
183 /* Check our hardware type table for this type. */
184 struct hwtype *get_hwtype(const char *name)
185 {
186     struct hwtype **hwp;
187
188     if (!sVhwinit)
189         hwinit();
190
191     hwp = hwtypes;
192     while (*hwp != NULL) {
193         if (!strcmp((*hwp)->name, name))
194             return (*hwp);
195         hwp++;
196     }
197     return (NULL);
198 }
199
200
201 /* Check our hardware type table for this type. */
202 struct hwtype *get_hwntype(int type)
203 {
204     struct hwtype **hwp;
205
206     if (!sVhwinit)
207         hwinit();
208
209     hwp = hwtypes;
210     while (*hwp != NULL) {
211         if ((*hwp)->type == type)
212             return (*hwp);
213         hwp++;
214     }
215     return (NULL);
216 }