]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | /* SmoothWall libsmooth.\r |
2 | *\r | |
3 | * This program is distributed under the terms of the GNU General Public\r | |
4 | * Licence. See the file COPYING for details.\r | |
5 | *\r | |
6 | * (c) Lawrence Manning, 2001\r | |
7 | * Contains network library functions.\r | |
8 | * \r | |
9 | * $Id: netstuff.c,v 1.19.2.7 2004/11/05 23:40:17 alanh Exp $\r | |
10 | * \r | |
11 | */\r | |
12 | \r | |
13 | #include "libsmooth.h"\r | |
14 | #include <signal.h>\r | |
15 | \r | |
16 | extern FILE *flog;\r | |
17 | extern char *mylog;\r | |
18 | \r | |
19 | extern char **ctr;\r | |
20 | \r | |
21 | newtComponent networkform;\r | |
22 | newtComponent addressentry;\r | |
23 | newtComponent netmaskentry;\r | |
24 | newtComponent statictyperadio;\r | |
25 | newtComponent dhcptyperadio;\r | |
26 | newtComponent pppoetyperadio;\r | |
27 | newtComponent pptptyperadio;\r | |
28 | newtComponent dhcphostnameentry;\r | |
29 | \r | |
30 | /* acceptable character filter for IP and netmaks entry boxes */\r | |
31 | static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)\r | |
32 | {\r | |
33 | if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE)\r | |
34 | return ch;\r | |
35 | return 0;\r | |
36 | }\r | |
37 | \r | |
38 | /* This is a groovie dialog for showing network info. Takes a keyvalue list,\r | |
39 | * a colour and a dhcp flag. Shows the current settings, and rewrites them\r | |
40 | * if necessary. DHCP flag sets wether to show the dhcp checkbox. */\r | |
41 | int changeaddress(struct keyvalue *kv, char *colour, int typeflag,\r | |
42 | char *defaultdhcphostname)\r | |
43 | {\r | |
44 | char *addressresult;\r | |
45 | char *netmaskresult;\r | |
46 | char *dhcphostnameresult;\r | |
47 | struct newtExitStruct es;\r | |
48 | newtComponent header;\r | |
49 | newtComponent addresslabel;\r | |
50 | newtComponent netmasklabel;\r | |
51 | newtComponent dhcphostnamelabel;\r | |
52 | newtComponent ok, cancel; \r | |
53 | char message[1000];\r | |
54 | char temp[STRING_SIZE];\r | |
55 | char addressfield[STRING_SIZE];\r | |
56 | char netmaskfield[STRING_SIZE];\r | |
57 | char typefield[STRING_SIZE];\r | |
58 | char dhcphostnamefield[STRING_SIZE];\r | |
59 | int error;\r | |
60 | int result = 0;\r | |
61 | char type[STRING_SIZE];\r | |
62 | int startstatictype = 0;\r | |
63 | int startdhcptype = 0;\r | |
64 | int startpppoetype = 0;\r | |
65 | int startpptptype = 0;\r | |
66 | \r | |
67 | /* Build some key strings. */\r | |
68 | sprintf(addressfield, "%s_ADDRESS", colour);\r | |
69 | sprintf(netmaskfield, "%s_NETMASK", colour);\r | |
70 | sprintf(typefield, "%s_TYPE", colour);\r | |
71 | sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);\r | |
72 | \r | |
73 | sprintf(message, ctr[TR_INTERFACE], colour);\r | |
74 | newtCenteredWindow(44, (typeflag ? 18 : 12), message);\r | |
75 | \r | |
76 | networkform = newtForm(NULL, NULL, 0);\r | |
77 | \r | |
78 | sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour);\r | |
79 | header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);\r | |
80 | newtFormAddComponent(networkform, header);\r | |
81 | \r | |
82 | /* See if we need a dhcp checkbox. If we do, then we shift the contents\r | |
83 | * of the window down two rows to make room. */\r | |
84 | if (typeflag)\r | |
85 | {\r | |
86 | strcpy(temp, "STATIC"); findkey(kv, typefield, temp);\r | |
87 | if (strcmp(temp, "STATIC") == 0) startstatictype = 1;\r | |
88 | if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;\r | |
89 | if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;\r | |
90 | if (strcmp(temp, "PPTP") == 0) startpptptype = 1;\r | |
91 | statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);\r | |
92 | dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);\r | |
93 | pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);\r | |
94 | pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);\r | |
95 | newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, \r | |
96 | pppoetyperadio, pptptyperadio, NULL);\r | |
97 | newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);\r | |
98 | newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);\r | |
99 | newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);\r | |
100 | newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);\r | |
101 | dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);\r | |
102 | newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);\r | |
103 | strcpy(temp, defaultdhcphostname);\r | |
104 | findkey(kv, dhcphostnamefield, temp);\r | |
105 | dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0);\r | |
106 | newtFormAddComponent(networkform, dhcphostnamelabel); \r | |
107 | newtFormAddComponent(networkform, dhcphostnameentry); \r | |
108 | if (startdhcptype == 0)\r | |
109 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r | |
110 | }\r | |
111 | /* Address */\r | |
112 | addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);\r | |
113 | newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]);\r | |
114 | strcpy(temp, "");\r | |
115 | findkey(kv, addressfield, temp);\r | |
116 | addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);\r | |
117 | newtEntrySetFilter(addressentry, ip_input_filter, NULL);\r | |
118 | if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )\r | |
119 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r | |
120 | newtFormAddComponent(networkform, addresslabel);\r | |
121 | newtFormAddComponent(networkform, addressentry);\r | |
122 | \r | |
123 | /* Netmask */\r | |
124 | netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);\r | |
125 | newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]);\r | |
126 | strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);\r | |
127 | netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);\r | |
128 | newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);\r | |
129 | if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 ) \r | |
130 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r | |
131 | \r | |
132 | newtFormAddComponent(networkform, netmasklabel);\r | |
133 | newtFormAddComponent(networkform, netmaskentry);\r | |
134 | \r | |
135 | /* Buttons. */\r | |
136 | ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]);\r | |
137 | cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]);\r | |
138 | \r | |
139 | newtFormAddComponents(networkform, ok, cancel, NULL);\r | |
140 | \r | |
141 | newtRefresh();\r | |
142 | newtDrawForm(networkform);\r | |
143 | \r | |
144 | do\r | |
145 | {\r | |
146 | error = 0;\r | |
147 | newtFormRun(networkform, &es);\r | |
148 | \r | |
149 | if (es.u.co == ok)\r | |
150 | {\r | |
151 | /* OK was pressed; verify the contents of each entry. */\r | |
152 | strcpy(message, ctr[TR_INVALID_FIELDS]);\r | |
153 | \r | |
154 | strcpy(type, "STATIC");\r | |
155 | if (typeflag)\r | |
156 | gettype(type);\r | |
157 | if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )\r | |
158 | { \r | |
159 | if (inet_addr(addressresult) == INADDR_NONE)\r | |
160 | {\r | |
161 | strcat(message, ctr[TR_IP_ADDRESS_CR]);\r | |
162 | error = 1;\r | |
163 | }\r | |
164 | if (inet_addr(netmaskresult) == INADDR_NONE)\r | |
165 | {\r | |
166 | strcat(message, ctr[TR_NETWORK_MASK_CR]);\r | |
167 | error = 1;\r | |
168 | }\r | |
169 | }\r | |
170 | if (strcmp(type, "DHCP") == 0)\r | |
171 | {\r | |
172 | if (!strlen(dhcphostnameresult))\r | |
173 | {\r | |
174 | strcat(message, ctr[TR_DHCP_HOSTNAME_CR]);\r | |
175 | error = 1;\r | |
176 | }\r | |
177 | }\r | |
178 | if (error)\r | |
179 | errorbox(message);\r | |
180 | else\r | |
181 | {\r | |
182 | /* No errors! Set new values, depending on dhcp flag etc. */\r | |
183 | if (typeflag)\r | |
184 | {\r | |
185 | replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);\r | |
186 | if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)\r | |
187 | {\r | |
188 | replacekeyvalue(kv, addressfield, "0.0.0.0");\r | |
189 | replacekeyvalue(kv, netmaskfield, "0.0.0.0");\r | |
190 | }\r | |
191 | else\r | |
192 | {\r | |
193 | replacekeyvalue(kv, addressfield, addressresult);\r | |
194 | replacekeyvalue(kv, netmaskfield, netmaskresult);\r | |
195 | }\r | |
196 | replacekeyvalue(kv, typefield, type); \r | |
197 | }\r | |
198 | else\r | |
199 | {\r | |
200 | replacekeyvalue(kv, addressfield, addressresult);\r | |
201 | replacekeyvalue(kv, netmaskfield, netmaskresult);\r | |
202 | }\r | |
203 | \r | |
204 | setnetaddress(kv, colour);\r | |
205 | result = 1;\r | |
206 | }\r | |
207 | } \r | |
208 | }\r | |
209 | while (error);\r | |
210 | \r | |
211 | newtFormDestroy(networkform);\r | |
212 | newtPopWindow();\r | |
213 | \r | |
214 | return result;\r | |
215 | }\r | |
216 | \r | |
217 | /* for pppoe: return string thats type STATIC, DHCP or PPPOE */\r | |
218 | int gettype(char *type)\r | |
219 | {\r | |
220 | newtComponent selected = newtRadioGetCurrent(statictyperadio);\r | |
221 | \r | |
222 | if (selected == statictyperadio)\r | |
223 | strcpy(type, "STATIC");\r | |
224 | else if (selected == dhcptyperadio)\r | |
225 | strcpy(type, "DHCP");\r | |
226 | else if (selected == pppoetyperadio)\r | |
227 | strcpy(type, "PPPOE");\r | |
228 | else if (selected == pptptyperadio)\r | |
229 | strcpy(type, "PPTP");\r | |
230 | else\r | |
231 | strcpy(type, "ERROR");\r | |
232 | \r | |
233 | return 0;\r | |
234 | }\r | |
235 | \r | |
236 | /* 0.9.9: calculates broadcast too. */\r | |
237 | int setnetaddress(struct keyvalue *kv, char *colour)\r | |
238 | {\r | |
239 | char addressfield[STRING_SIZE];\r | |
240 | char netaddressfield[STRING_SIZE]; \r | |
241 | char netmaskfield[STRING_SIZE];\r | |
242 | char broadcastfield[STRING_SIZE];\r | |
243 | char address[STRING_SIZE];\r | |
244 | char netmask[STRING_SIZE];\r | |
245 | unsigned long int intaddress;\r | |
246 | unsigned long int intnetaddress;\r | |
247 | unsigned long int intnetmask;\r | |
248 | unsigned long int intbroadcast;\r | |
249 | struct in_addr temp;\r | |
250 | char *netaddress;\r | |
251 | char *broadcast;\r | |
252 | \r | |
253 | /* Build some key strings. */\r | |
254 | sprintf(addressfield, "%s_ADDRESS", colour);\r | |
255 | sprintf(netaddressfield, "%s_NETADDRESS", colour);\r | |
256 | sprintf(netmaskfield, "%s_NETMASK", colour);\r | |
257 | sprintf(broadcastfield, "%s_BROADCAST", colour);\r | |
258 | \r | |
259 | strcpy(address, ""); findkey(kv, addressfield, address); \r | |
260 | strcpy(netmask, ""); findkey(kv, netmaskfield, netmask); \r | |
261 | \r | |
262 | /* Calculate netaddress. Messy.. */\r | |
263 | intaddress = inet_addr(address);\r | |
264 | intnetmask = inet_addr(netmask);\r | |
265 | \r | |
266 | intnetaddress = intaddress & intnetmask;\r | |
267 | temp.s_addr = intnetaddress; \r | |
268 | netaddress = inet_ntoa(temp);\r | |
269 | \r | |
270 | replacekeyvalue(kv, netaddressfield, netaddress);\r | |
271 | \r | |
272 | intbroadcast = intnetaddress | ~intnetmask;\r | |
273 | temp.s_addr = intbroadcast;\r | |
274 | broadcast = inet_ntoa(temp); \r | |
275 | \r | |
276 | replacekeyvalue(kv, broadcastfield, broadcast);\r | |
277 | \r | |
278 | return 1;\r | |
279 | } \r | |
280 | \r | |
281 | /* Called when dhcp flag is toggled. Toggle disabled state of other 3\r | |
282 | * controls. */\r | |
283 | void networkdialogcallbacktype(newtComponent cm, void *data)\r | |
284 | {\r | |
285 | char type[STRING_SIZE];\r | |
286 | \r | |
287 | gettype(type);\r | |
288 | \r | |
289 | if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 )\r | |
290 | {\r | |
291 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r | |
292 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r | |
293 | }\r | |
294 | else\r | |
295 | {\r | |
296 | newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r | |
297 | newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r | |
298 | }\r | |
299 | if (strcmp(type, "DHCP") == 0)\r | |
300 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r | |
301 | else\r | |
302 | newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); \r | |
303 | \r | |
304 | newtRefresh();\r | |
305 | newtDrawForm(networkform); \r | |
306 | }\r | |
307 | \r | |
308 | int interfacecheck(struct keyvalue *kv, char *colour)\r | |
309 | {\r | |
310 | char temp[STRING_SIZE];\r | |
311 | char colourfields[NETCHANGE_TOTAL][STRING_SIZE];\r | |
312 | int c;\r | |
313 | \r | |
314 | sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour);\r | |
315 | sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour);\r | |
316 | sprintf(colourfields[NETMASK], "%s_NETMASK", colour);\r | |
317 | \r | |
318 | for (c = 0; c < 3; c++)\r | |
319 | {\r | |
320 | strcpy(temp, ""); findkey(kv, colourfields[c], temp);\r | |
321 | if (!(strlen(temp))) return 0;\r | |
322 | }\r | |
323 | return 1;\r | |
324 | }\r | |
325 | \r | |
326 | /* Network probing! */\r | |
327 | struct nic nics[] = {\r | |
328 | { "100VG-AnyLan Network Adapters, HP J2585B, J2585A, etc", "hp100" },\r | |
329 | { "3Com EtherLink III", "3c509" },\r | |
330 | { "3Com 3c501", "3c501" },\r | |
331 | { "3Com ISA EtherLink XL", "3c515" },\r | |
332 | { "3Com 3c503 and 3c503/16", "3c503" },\r | |
333 | { "3Com EtherLink MC (3c523)", "3c523" },\r | |
334 | { "3Com EtherLink MC/32 (3c527)", "3c527" },\r | |
335 | { "3Com EtherLink Plus (3c505)", "3c505" },\r | |
336 | { "3Com EtherLink 16", "3c507" },\r | |
337 | { "3Com \"Corkscrew\" EtherLink PCI III/XL, etc.", "3c59x" },\r | |
338 | { "3Com Typhoon Family (3C990, 3CR990, and variants)", "typhoon" },\r | |
339 | { "Adaptec Starfire/DuraLAN", "starfire" },\r | |
340 | { "Alteon AceNIC/3Com 3C985/Netgear GA620 Gigabit", "acenic" },\r | |
341 | { "AMD8111 based 10/100 Ethernet Controller", "amd8111e" },\r | |
342 | { "AMD LANCE/PCnetAllied Telesis AT1500, J2405A, etc", "lance" },\r | |
343 | { "AMD PCnet32 and AMD PCnetPCI", "pcnet32" },\r | |
344 | { "Ansel Communications EISA 3200", "ac3200" },\r | |
345 | { "Apricot 680x0 VME, 82596 chipset", "82596" },\r | |
346 | { "AT1700/1720", "at1700" },\r | |
347 | { "Broadcom 4400", "b44" },\r | |
348 | { "Broadcom Tigon3", "tg3" },\r | |
349 | { "Cabletron E2100 series ethercards", "e2100" },\r | |
350 | { "CATC USB NetMate-based Ethernet", "catc" },\r | |
351 | { "CDC USB Ethernet", "CDCEther" },\r | |
352 | { "Crystal LAN CS8900/CS8920", "cs89x0" },\r | |
353 | { "Compaq Netelligent 10/100 TX PCI UTP, etc", "tlan" },\r | |
354 | { "D-Link DL2000-based Gigabit Ethernet", "dl2k" },\r | |
355 | { "Digi Intl. RightSwitch SE-X EISA and PCI", "dgrs" },\r | |
356 | { "Digital 21x4x Tulip PCI ethernet cards, etc.", "tulip" },\r | |
357 | { "Digital DEPCA & EtherWORKS,DEPCA, DE100, etc", "depca" },\r | |
358 | { "DM9102 PCI Fast Ethernet Adapter", "dmfe", },\r | |
359 | { "Dummy Network Card (testing)", "dummy", },\r | |
360 | { "EtherWORKS DE425 TP/COAX EISA, DE434 TP PCI, etc.", "de4x5" },\r | |
361 | { "EtherWORKS 3 (DE203, DE204 and DE205)", "ewrk3" },\r | |
362 | { "HP PCLAN/plus", "hp-plus" },\r | |
363 | { "HP LAN ethernet", "hp" },\r | |
364 | { "IBM LANA", "ibmlana" },\r | |
365 | { "ICL EtherTeam 16i/32" ,"eth16i" },\r | |
366 | { "Intel i82557/i82558 PCI EtherExpressPro", "e100" },\r | |
367 | { "Intel EtherExpress Cardbus Ethernet", "eepro100_cb" },\r | |
368 | { "Intel i82595 ISA EtherExpressPro10/10+ driver" ,"eepro" },\r | |
369 | { "Intel EtherExpress 16 (i82586)", "eexpress" },\r | |
370 | { "Intel Panther onboard i82596 driver", "lp486e" },\r | |
371 | { "Intel PRO/1000 Gigabit Ethernet", "e1000" },\r | |
372 | { "KLSI USB KL5USB101-based", "kaweth" },\r | |
373 | { "MiCom-Interlan NI5010 ethercard", "ni5010" },\r | |
374 | { "Mylex EISA LNE390A/B", "lne390", },\r | |
375 | { "Myson MTD-8xx PCI Ethernet", "fealnx" },\r | |
376 | { "National Semiconductor DP8381x" , "natsemi" },\r | |
377 | { "National Semiconductor DP83820" , "ns83820" },\r | |
378 | { "NE/2 MCA", "ne2" },\r | |
379 | { "NE2000 PCI cards, RealTEk RTL-8029, etc", "ne2k-pci" },\r | |
380 | { "NE1000 / NE2000 (non-pci)", "ne" },\r | |
381 | { "NI50 card (i82586 Ethernet chip)", "ni52" },\r | |
382 | { "NI6510, ni6510 EtherBlaster", "ni65" },\r | |
383 | { "Novell/Eagle/Microdyne NE3210 EISA", "ne3210" },\r | |
384 | { "NVidia Nforce2 Driver", "forcedeth" },\r | |
385 | { "Packet Engines Hamachi GNIC-II", "hamachi" },\r | |
386 | { "Packet Engines Yellowfin Gigabit-NIC", "yellowfin" },\r | |
387 | { "Pegasus/Pegasus-II USB ethernet", "pegasus" },\r | |
388 | { "PureData PDUC8028,WD8003 and WD8013 compatibles", "wd" },\r | |
389 | { "Racal-Interlan EISA ES3210", "es3210" },\r | |
390 | { "RealTek RTL-8139 Fast Ethernet", "8139too" },\r | |
391 | { "RealTek RTL-8139C+ series 10/100 PCI Ethernet", "8139cp" },\r | |
392 | { "RealTek RTL-8150 USB ethernet", "rtl8150" },\r | |
393 | { "RealTek RTL-8169 Gigabit Ethernet", "r8169" },\r | |
394 | { "SiS 900 PCI", "sis900" },\r | |
395 | { "SKnet MCA", "sk_mca" },\r | |
396 | { "SMC 9000 series of ethernet cards", "smc9194" },\r | |
397 | { "SMC EtherPower II", "epic100" },\r | |
398 | { "SMC Ultra/EtherEZ ISA/PnP Ethernet", "smc-ultra" },\r | |
399 | { "SMC Ultra32 EISA Ethernet", "smc-ultra32" },\r | |
400 | { "SMC Ultra MCA Ethernet", "smc-mca" },\r | |
401 | { "Sundance Alta", "sundance" },\r | |
402 | { "SysKonnect SK-98xx", "sk98lin" },\r | |
403 | { "Toshiba TC35815 Ethernet", "tc35815" },\r | |
404 | { "Tulip chipset Cardbus Ethernet", "tulip_cb" },\r | |
405 | { "USB Ethernet", "usbnet" },\r | |
406 | { "VIA Rhine PCI Fast Ethernet, etc", "via-rhine" },\r | |
407 | { "Winbond W89c840 Ethernet", "winbond-840" },\r | |
408 | { "Xircom Cardbus Ethernet", "xircom_cb" },\r | |
409 | { "Xircom (tulip-like) Cardbus Ethernet", "xircom_tulip_cb" },\r | |
410 | { NULL, NULL }\r | |
411 | };\r | |
412 | \r | |
413 | /* Funky routine for loading all drivers (cept those are already loaded.). */\r | |
414 | int probecards(char *driver, char *driveroptions)\r | |
415 | {\r | |
416 | int c = 0;\r | |
417 | int n = 0;\r | |
418 | char message[1000];\r | |
419 | char commandstring[STRING_SIZE];\r | |
420 | \r | |
421 | n = countcards();\r | |
422 | \r | |
423 | /* PCMCIA Detection */\r | |
424 | runcommandwithstatus("cardmgr -o", \r | |
425 | ctr[TR_LOADING_PCMCIA]);\r | |
426 | \r | |
427 | if (countcards() > n) \r | |
428 | {\r | |
429 | strcpy(driver, "pcmcia");\r | |
430 | strcpy(driveroptions,"");\r | |
431 | return 1;\r | |
432 | }\r | |
433 | \r | |
434 | /* Regular module detection */\r | |
435 | while (nics[c].modulename)\r | |
436 | {\r | |
437 | /* Skip dummy driver during autoprobe as it always succeeds */\r | |
438 | if (strncmp(nics[c].modulename, "dummy", strlen("dummy")))\r | |
439 | {\r | |
440 | if (!checkformodule(nics[c].modulename)) {\r | |
441 | sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);\r | |
442 | sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);\r | |
443 | if (runcommandwithstatus(commandstring, message) == 0)\r | |
444 | {\r | |
445 | if (countcards() > n) {\r | |
446 | strcpy(driver, nics[c].modulename);\r | |
447 | strcpy(driveroptions, "");\r | |
448 | return 1;\r | |
449 | }\r | |
450 | }\r | |
451 | }\r | |
452 | }\r | |
453 | c++;\r | |
454 | }\r | |
455 | strcpy(driver, "");\r | |
456 | strcpy(driveroptions, "");\r | |
457 | \r | |
458 | return 0;\r | |
459 | }\r | |
460 | \r | |
461 | /* A listbox for selected the card... with a * MANUAL * entry at top for\r | |
462 | * manual module names. */\r | |
463 | int choosecards(char *driver, char *driveroptions)\r | |
464 | {\r | |
465 | int c;\r | |
466 | char **sections;\r | |
467 | int drivercount;\r | |
468 | int rc;\r | |
469 | int choice;\r | |
470 | char commandstring[STRING_SIZE];\r | |
471 | char message[STRING_SIZE];\r | |
472 | int done = 0;\r | |
473 | \r | |
474 | /* Count 'em */\r | |
475 | c = 0; drivercount = 0;\r | |
476 | while (nics[c].modulename)\r | |
477 | {\r | |
478 | drivercount++;\r | |
479 | c++;\r | |
480 | }\r | |
481 | drivercount++;\r | |
482 | sections = malloc((drivercount + 1) * sizeof(char *));\r | |
483 | \r | |
484 | /* Copy 'em. */\r | |
485 | c = 0;\r | |
486 | sections[c] = ctr[TR_MANUAL];\r | |
487 | c++;\r | |
488 | while (nics[c - 1].modulename)\r | |
489 | {\r | |
490 | sections[c] = nics[c - 1].description;\r | |
491 | c++;\r | |
492 | }\r | |
493 | sections[c] = NULL;\r | |
494 | \r | |
495 | strcpy(driver, "");\r | |
496 | strcpy(driveroptions, "");\r | |
497 | \r | |
498 | done = 0; choice = 1;\r | |
499 | while (!done)\r | |
500 | {\r | |
501 | rc = newtWinMenu(ctr[TR_SELECT_NETWORK_DRIVER],\r | |
502 | ctr[TR_SELECT_NETWORK_DRIVER_LONG], 50, 5, 5, 6,\r | |
503 | sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r | |
504 | if (rc == 0 || rc == 1)\r | |
505 | {\r | |
506 | if (choice > 0)\r | |
507 | {\r | |
508 | /* Find module number, load module. */\r | |
509 | c = choice - 1; \r | |
510 | \r | |
511 | if (!checkformodule(nics[c].modulename))\r | |
512 | {\r | |
513 | sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);\r | |
514 | sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);\r | |
515 | if (runcommandwithstatus(commandstring, message) == 0)\r | |
516 | {\r | |
517 | strcpy(driver, nics[c].modulename);\r | |
518 | strcpy(driveroptions, "");\r | |
519 | done = 1;\r | |
520 | }\r | |
521 | else\r | |
522 | errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);\r | |
523 | }\r | |
524 | else\r | |
525 | errorbox(ctr[TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED]);\r | |
526 | }\r | |
527 | else\r | |
528 | {\r | |
529 | manualdriver(driver, driveroptions);\r | |
530 | if (strlen(driver))\r | |
531 | done = 1;\r | |
532 | }\r | |
533 | }\r | |
534 | else\r | |
535 | done = 1; \r | |
536 | }\r | |
537 | \r | |
538 | return 1;\r | |
539 | }\r | |
540 | \r | |
541 | /* Manual entry for gurus. */\r | |
542 | int manualdriver(char *driver, char *driveroptions)\r | |
543 | {\r | |
544 | char *values[] = { NULL, NULL }; /* pointers for the values. */\r | |
545 | struct newtWinEntry entries[] =\r | |
546 | { { "", &values[0], 0,}, { NULL, NULL, 0 } };\r | |
547 | int rc;\r | |
548 | char commandstring[STRING_SIZE];\r | |
549 | char *driverend;\r | |
550 | \r | |
551 | strcpy(driver, "");\r | |
552 | strcpy(driveroptions, "");\r | |
553 | \r | |
554 | rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER], \r | |
555 | ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries, \r | |
556 | ctr[TR_OK], ctr[TR_CANCEL], NULL); \r | |
557 | if (rc == 0 || rc == 1)\r | |
558 | {\r | |
559 | if (strlen(values[0]))\r | |
560 | {\r | |
561 | sprintf(commandstring, "/sbin/modprobe %s", values[0]);\r | |
562 | if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0)\r | |
563 | {\r | |
564 | if ((driverend = strchr(values[0], ' ')))\r | |
565 | {\r | |
566 | *driverend = '\0';\r | |
567 | strcpy(driver, values[0]);\r | |
568 | strcpy(driveroptions, driverend + 1);\r | |
569 | } \r | |
570 | else\r | |
571 | {\r | |
572 | strcpy(driver, values[0]);\r | |
573 | strcpy(driveroptions, "");\r | |
574 | }\r | |
575 | }\r | |
576 | else\r | |
577 | errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);\r | |
578 | }\r | |
579 | else\r | |
580 | errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]);\r | |
581 | }\r | |
582 | free(values[0]);\r | |
583 | \r | |
584 | return 1;\r | |
585 | }\r | |
586 | \r | |
587 | /* Returns the total number of nics current available as ethX devices. */\r | |
588 | int countcards(void)\r | |
589 | {\r | |
590 | FILE *file;\r | |
591 | char buffer[STRING_SIZE];\r | |
592 | char *start;\r | |
593 | int niccount = 0;\r | |
594 | \r | |
595 | if (!(file = fopen("/proc/net/dev", "r")))\r | |
596 | {\r | |
597 | fprintf(flog, "Unable to open /proc/net/dev in countnics()\n");\r | |
598 | return 0;\r | |
599 | }\r | |
600 | \r | |
601 | while (fgets(buffer, STRING_SIZE, file))\r | |
602 | {\r | |
603 | start = buffer;\r | |
604 | while (*start == ' ') start++;\r | |
605 | if (strncmp(start, "eth", strlen("eth")) == 0)\r | |
606 | niccount++;\r | |
607 | if (strncmp(start, "dummy", strlen("dummy")) == 0)\r | |
608 | niccount++;\r | |
609 | }\r | |
610 | \r | |
611 | fclose(file);\r | |
612 | \r | |
613 | return niccount;\r | |
614 | }\r | |
615 | \r | |
616 | /* Finds the listed module name and copies the card description back. */\r | |
617 | int findnicdescription(char *modulename, char *description)\r | |
618 | {\r | |
619 | int c = 0;\r | |
620 | \r | |
621 | if (strcmp(modulename, "pcmcia") == 0) {\r | |
622 | strcpy(description, "PCMCIA Ethernet card");\r | |
623 | return 0;\r | |
624 | }\r | |
625 | \r | |
626 | while (nics[c].description)\r | |
627 | {\r | |
628 | if (strcmp(nics[c].modulename, modulename) == 0)\r | |
629 | {\r | |
630 | strcpy(description, nics[c].description);\r | |
631 | return 1;\r | |
632 | }\r | |
633 | c++;\r | |
634 | }\r | |
635 | \r | |
636 | strcpy(description, "UNKNOWN");\r | |
637 | return 0;\r | |
638 | }\r |