Some small Ash changes.
[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 for the NET-2 base distribution.
4  *
5  * Version:     lib/hw.c 1.20 (1998-01-25)
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  *              This program is free software; you can redistribute it
13  *              and/or  modify it under  the terms of  the GNU General
14  *              Public  License as  published  by  the  Free  Software
15  *              Foundation;  either  version 2 of the License, or  (at
16  *              your option) any later version.
17  */
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <errno.h>
23 #include <ctype.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include "config.h"
27 #include "net-support.h"
28 #include "pathnames.h"
29 #define  EXTERN
30 #include "net-locale.h"
31
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   tr_hwtype;
45
46 extern  struct hwtype   ax25_hwtype;
47 extern  struct hwtype   rose_hwtype;
48 extern  struct hwtype   netrom_hwtype;
49 extern  struct hwtype   tunnel_hwtype;
50
51 extern  struct hwtype   ash_hwtype;
52
53 extern  struct hwtype   ppp_hwtype;
54
55 extern  struct hwtype   arcnet_hwtype;
56
57 extern  struct hwtype   dlci_hwtype;
58 extern  struct hwtype   frad_hwtype;
59
60 extern  struct hwtype   sit_hwtype;
61
62 static struct hwtype *hwtypes[] = {
63
64   &loop_hwtype,
65
66 #if HAVE_HWSLIP
67   &slip_hwtype,
68   &cslip_hwtype,
69   &slip6_hwtype,
70   &cslip6_hwtype,
71   &adaptive_hwtype,
72 #endif
73 #if HAVE_HWASH
74   &ash_hwtype,
75 #endif
76 #if HAVE_HWETHER
77   &ether_hwtype,
78 #endif
79 #if HAVE_HWTR
80   &tr_hwtype,
81 #endif
82 #if HAVE_HWAX25
83   &ax25_hwtype,
84 #endif
85 #if HAVE_HWNETROM
86   &netrom_hwtype,
87 #endif
88 #if HAVE_HWTUNNEL
89   &tunnel_hwtype,
90 #endif
91 #if HAVE_HWPPP
92   &ppp_hwtype,
93 #endif  
94 #if HAVE_HWARC
95   &arcnet_hwtype,
96 #endif  
97 #if HAVE_HWFR
98   &dlci_hwtype,
99   &frad_hwtype,
100 #endif
101 #if HAVE_HWSIT
102   &sit_hwtype,
103 #endif
104 #if HAVE_HWROSE
105   &rose_hwtype,
106 #endif
107 #if HAVE_HWFDDI
108   &fddi_hwtype,
109 #endif
110   &unspec_hwtype,
111   NULL
112 };
113
114 static short sVhwinit = 0;
115
116 void hwinit ()
117 {
118   loop_hwtype.title = NLS_CATSAVE (catfd, loopbackSet, loopback_loop, "Local Loopback");
119   unspec_hwtype.title = NLS_CATSAVE (catfd, loopbackSet, loopback_unspec, "UNSPEC");
120 #if HAVE_HWSLIP
121   slip_hwtype.title = NLS_CATSAVE (catfd, slipSet, slip_slip, "Serial Line IP");
122   cslip_hwtype.title = NLS_CATSAVE (catfd, slipSet, slip_cslip, "VJ Serial Line IP");
123   slip6_hwtype.title = NLS_CATSAVE (catfd, slipSet, slip_slip6, "6-bit Serial Line IP");
124   cslip6_hwtype.title = NLS_CATSAVE (catfd, slipSet, slip_cslip6, "VJ 6-bit Serial Line IP");
125   adaptive_hwtype.title = NLS_CATSAVE (catfd, slipSet, slip_adaptive, "Adaptive Serial Line IP");
126 #endif
127 #if HAVE_HWETHER
128   ether_hwtype.title = NLS_CATSAVE (catfd, etherSet, ether_ether, "Ethernet");
129 #endif
130 #if HAVE_HWASH
131   ash_hwtype.title = NLS_CATSAVE (catfd, ashSet, ash_hw, "Ash");
132 #endif
133 #if HAVE_HWFDDI
134   fddi_hwtype.title = NLS_CATSAVE (catfd, fddiSet, fddi_fddi, "Fiber Distributed Data Interface");
135 #endif
136 #if HAVE_HWAX25
137   ax25_hwtype.title = NLS_CATSAVE (catfd, ax25Set, ax25_hw, "AMPR AX.25");
138 #endif
139 #if HAVE_HWROSE
140   rose_hwtype.title = NLS_CATSAVE (catfd, roseSet, rose_hw, "AMPR ROSE");
141 #endif
142 #if HAVE_HWNETROM
143   netrom_hwtype.title = NLS_CATSAVE (catfd, netromSet, netrom_hw, "AMPR NET/ROM");
144 #endif
145 #if HAVE_HWTUNNEL
146   tunnel_hwtype.title = NLS_CATSAVE (catfd, tunnelSet, tunnel_hw, "IPIP Tunnel");
147 #endif
148 #if HAVE_HWPPP
149   ppp_hwtype.title = NLS_CATSAVE (catfd, pppSet, ppp_ppp, "Point-to-Point Protocol");
150 #endif  
151 #if HAVE_HWARC
152   arcnet_hwtype.title = NLS_CATSAVE (catfd, arcnetSet, arcnet_arcnet, "1.5Mbps ARCnet");
153 #endif
154 #if HAVE_HWFR
155   dlci_hwtype.title = NLS_CATSAVE(catfd, dlciSet, dlci_hw, "Frame Relay DLCI");
156   frad_hwtype.title = NLS_CATSAVE(catfd, fradSet, frad_hw, "Frame Relay Access Device");
157 #endif
158 #if HAVE_HWSIT
159   sit_hwtype.title = NLS_CATSAVE(catfd, sitSet, sit_hw, "IPv6-in-IPv4");
160 #endif
161   sVhwinit = 1;
162 }
163
164 /* Check our hardware type table for this type. */
165 struct hwtype *
166 get_hwtype(const char *name)
167 {
168   struct hwtype **hwp;
169
170   if (!sVhwinit)
171     hwinit();
172   
173   hwp = hwtypes;
174   while (*hwp != NULL) {
175         if (!strcmp((*hwp)->name, name)) return(*hwp);
176         hwp++;
177   }
178   return(NULL);
179 }
180
181
182 /* Check our hardware type table for this type. */
183 struct hwtype *
184 get_hwntype(int type)
185 {
186   struct hwtype **hwp;
187
188   if (!sVhwinit)
189     hwinit();
190
191   hwp = hwtypes;
192   while (*hwp != NULL) {
193         if ((*hwp)->type == type) return(*hwp);
194         hwp++;
195   }
196   return(NULL);
197 }