1 /* SmoothWall libsmooth.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains network library functions.
11 #include "libsmooth.h"
19 extern struct nic nics
[];
20 extern struct knic knics
[];
22 char *ucolourcard
[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL
};
23 char *lcolourcard
[] = { "green", "red", "orange", "blue", NULL
};
25 int scanned_nics_read_done
= 0;
27 newtComponent networkform
;
28 newtComponent addressentry
;
29 newtComponent netmaskentry
;
30 newtComponent statictyperadio
;
31 newtComponent dhcptyperadio
;
32 newtComponent pppoetyperadio
;
33 newtComponent dhcphostnameentry
;
35 /* acceptable character filter for IP and netmaks entry boxes */
36 static int ip_input_filter(newtComponent entry
, void * data
, int ch
, int cursor
)
38 if ((ch
>= '0' && ch
<= '9') || ch
== '.' || ch
== '\r' || ch
>= NEWT_KEY_EXTRA_BASE
)
43 /* This is a groovie dialog for showing network info. Takes a keyvalue list,
44 * a colour and a dhcp flag. Shows the current settings, and rewrites them
45 * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
46 int changeaddress(struct keyvalue
*kv
, char *colour
, int typeflag
,
47 char *defaultdhcphostname
)
51 char *dhcphostnameresult
;
52 struct newtExitStruct es
;
54 newtComponent addresslabel
;
55 newtComponent netmasklabel
;
56 newtComponent dhcphostnamelabel
;
57 newtComponent ok
, cancel
;
59 char temp
[STRING_SIZE
];
60 char addressfield
[STRING_SIZE
];
61 char netmaskfield
[STRING_SIZE
];
62 char typefield
[STRING_SIZE
];
63 char dhcphostnamefield
[STRING_SIZE
];
66 char type
[STRING_SIZE
];
67 int startstatictype
= 0;
68 int startdhcptype
= 0;
69 int startpppoetype
= 0;
71 /* Build some key strings. */
72 sprintf(addressfield
, "%s_ADDRESS", colour
);
73 sprintf(netmaskfield
, "%s_NETMASK", colour
);
74 sprintf(typefield
, "%s_TYPE", colour
);
75 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
77 sprintf(message
, ctr
[TR_INTERFACE
], colour
);
78 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
80 networkform
= newtForm(NULL
, NULL
, 0);
82 sprintf(message
, ctr
[TR_ENTER_THE_IP_ADDRESS_INFORMATION
], colour
);
83 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
84 newtFormAddComponent(networkform
, header
);
86 /* See if we need a dhcp checkbox. If we do, then we shift the contents
87 * of the window down two rows to make room. */
90 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
91 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
92 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
93 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
94 statictyperadio
= newtRadiobutton(2, 4, ctr
[TR_STATIC
], startstatictype
, NULL
);
95 dhcptyperadio
= newtRadiobutton(2, 5, "DHCP", startdhcptype
, statictyperadio
);
96 pppoetyperadio
= newtRadiobutton(2, 6, "PPPOE", startpppoetype
, dhcptyperadio
);
97 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
98 pppoetyperadio
, NULL
);
99 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
100 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
101 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
102 dhcphostnamelabel
= newtTextbox(2, 9, 18, 1, 0);
103 newtTextboxSetText(dhcphostnamelabel
, ctr
[TR_DHCP_HOSTNAME
]);
104 strcpy(temp
, defaultdhcphostname
);
105 findkey(kv
, dhcphostnamefield
, temp
);
106 dhcphostnameentry
= newtEntry(20, 9, temp
, 20, &dhcphostnameresult
, 0);
107 newtFormAddComponent(networkform
, dhcphostnamelabel
);
108 newtFormAddComponent(networkform
, dhcphostnameentry
);
109 if (startdhcptype
== 0)
110 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
113 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
114 newtTextboxSetText(addresslabel
, ctr
[TR_IP_ADDRESS_PROMPT
]);
116 findkey(kv
, addressfield
, temp
);
117 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
118 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
119 if (typeflag
== 1 && startstatictype
== 0)
120 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
121 newtFormAddComponent(networkform
, addresslabel
);
122 newtFormAddComponent(networkform
, addressentry
);
125 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
126 newtTextboxSetText(netmasklabel
, ctr
[TR_NETMASK_PROMPT
]);
127 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
128 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
129 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
130 if (typeflag
== 1 && startstatictype
== 0)
131 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
133 newtFormAddComponent(networkform
, netmasklabel
);
134 newtFormAddComponent(networkform
, netmaskentry
);
137 ok
= newtButton(8, (typeflag
? 14 : 7), ctr
[TR_OK
]);
138 cancel
= newtButton(26, (typeflag
? 14 : 7), ctr
[TR_CANCEL
]);
140 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
143 newtDrawForm(networkform
);
148 newtFormRun(networkform
, &es
);
152 /* OK was pressed; verify the contents of each entry. */
153 strcpy(message
, ctr
[TR_INVALID_FIELDS
]);
155 strcpy(type
, "STATIC");
158 if (strcmp(type
, "STATIC") == 0)
160 if (inet_addr(addressresult
) == INADDR_NONE
)
162 strcat(message
, ctr
[TR_IP_ADDRESS_CR
]);
165 if (inet_addr(netmaskresult
) == INADDR_NONE
)
167 strcat(message
, ctr
[TR_NETWORK_MASK_CR
]);
171 if (strcmp(type
, "DHCP") == 0)
173 if (!strlen(dhcphostnameresult
))
175 strcat(message
, ctr
[TR_DHCP_HOSTNAME_CR
]);
183 /* No errors! Set new values, depending on dhcp flag etc. */
186 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
187 if (strcmp(type
, "STATIC") != 0)
189 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
190 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
194 replacekeyvalue(kv
, addressfield
, addressresult
);
195 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
197 replacekeyvalue(kv
, typefield
, type
);
201 replacekeyvalue(kv
, addressfield
, addressresult
);
202 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
205 setnetaddress(kv
, colour
);
212 newtFormDestroy(networkform
);
218 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
219 int gettype(char *type
)
221 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
223 if (selected
== statictyperadio
)
224 strcpy(type
, "STATIC");
225 else if (selected
== dhcptyperadio
)
226 strcpy(type
, "DHCP");
227 else if (selected
== pppoetyperadio
)
228 strcpy(type
, "PPPOE");
230 strcpy(type
, "ERROR");
235 /* 0.9.9: calculates broadcast too. */
236 int setnetaddress(struct keyvalue
*kv
, char *colour
)
238 char addressfield
[STRING_SIZE
];
239 char netaddressfield
[STRING_SIZE
];
240 char netmaskfield
[STRING_SIZE
];
241 char broadcastfield
[STRING_SIZE
];
242 char address
[STRING_SIZE
];
243 char netmask
[STRING_SIZE
];
244 unsigned long int intaddress
;
245 unsigned long int intnetaddress
;
246 unsigned long int intnetmask
;
247 unsigned long int intbroadcast
;
252 /* Build some key strings. */
253 sprintf(addressfield
, "%s_ADDRESS", colour
);
254 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
255 sprintf(netmaskfield
, "%s_NETMASK", colour
);
256 sprintf(broadcastfield
, "%s_BROADCAST", colour
);
258 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
259 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
261 /* Calculate netaddress. Messy.. */
262 intaddress
= inet_addr(address
);
263 intnetmask
= inet_addr(netmask
);
265 intnetaddress
= intaddress
& intnetmask
;
266 temp
.s_addr
= intnetaddress
;
267 netaddress
= inet_ntoa(temp
);
269 replacekeyvalue(kv
, netaddressfield
, netaddress
);
271 intbroadcast
= intnetaddress
| ~intnetmask
;
272 temp
.s_addr
= intbroadcast
;
273 broadcast
= inet_ntoa(temp
);
275 replacekeyvalue(kv
, broadcastfield
, broadcast
);
280 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
282 void networkdialogcallbacktype(newtComponent cm
, void *data
)
284 char type
[STRING_SIZE
];
288 if (strcmp(type
, "STATIC") != 0)
290 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
291 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
295 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
296 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
298 if (strcmp(type
, "DHCP") == 0)
299 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
301 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
304 newtDrawForm(networkform
);
307 int interfacecheck(struct keyvalue
*kv
, char *colour
)
309 char temp
[STRING_SIZE
];
310 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
313 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
314 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
315 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
317 for (c
= 0; c
< 3; c
++)
319 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
320 if (!(strlen(temp
))) return 0;
325 /* Funky routine for loading all drivers (cept those are already loaded.). */
326 int probecards(char *driver
, char *driveroptions
)
331 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
333 struct keyvalue
*kv
= initkeyvalues();
334 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
337 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
340 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
344 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
345 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
347 strcpy(knics
[ card
].macaddr
, temp
);
348 strcpy(knics
[ card
].colour
, "GREEN");
350 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
351 findkey(kv
, searchstr
, temp
);
352 strcpy(knics
[ card
].description
, temp
);
354 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
355 findkey(kv
, searchstr
, temp
);
356 strcpy(knics
[ card
].driver
, temp
);
359 strcpy(knics
[ card
].description
, ctr
[TR_UNSET
]);
369 found
+= get_knic(_GREEN_CARD_
);
370 found
+= get_knic(_RED_CARD_
);
371 found
+= get_knic(_ORANGE_CARD_
);
372 found
+= get_knic(_BLUE_CARD_
);
377 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
379 if (stat(fname
, &st
) == -1) return 0;
383 int is_interface_up(char *card
) { /* Check if the interface is UP */
384 char temp
[STRING_SIZE
];
386 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
387 if (mysystem(temp
)) return 0; else return 1;
390 int rename_device(char *old_name
, char *new_name
) {
391 char temp
[STRING_SIZE
];
393 sprintf(temp
,SYSDIR
"/%s", old_name
);
394 if (!(fmt_exists(temp
))) {
395 fprintf(flog
,"Device not found: %s\n",old_name
);
398 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
404 char g_temp
[STRING_SIZE
]="";
405 char* readmac(char *card
) {
407 char temp
[STRING_SIZE
], mac
[20];
409 sprintf(temp
,"/sys/class/net/%s/address",card
);
410 if( (fp
= fopen(temp
, "r")) == NULL
) {
411 fprintf(flog
,"Couldn't open: %s\n",temp
);
421 char* find_nic4mac(char *findmac
) {
423 struct dirent
*dirzeiger
;
424 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
426 if((dir
=opendir(SYSDIR
)) == NULL
) {
427 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
432 while((dirzeiger
=readdir(dir
)) != NULL
) {
433 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
434 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
435 if (strcmp(findmac
, temp2
) == 0) {
436 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
442 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
443 strcpy(g_temp
, temp
);
447 int nic_shutdown(char *nic
) {
448 char temp
[STRING_SIZE
];
450 sprintf(temp
,"ip link set %s down", nic
);
454 int nic_startup(char *nic
) {
455 char temp
[STRING_SIZE
];
457 sprintf(temp
,"ip link set %s up", nic
);
462 int rename_nics(void) {
464 int fnics
= scan_network_cards();
465 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
468 if (strcmp(knics
[i
].macaddr
, ""))
469 for(j
=0; j
<fnics
; j
++)
470 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
471 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
472 if(strcmp(nic2find
, nics
[j
].nic
)) {
473 if(is_interface_up(nics
[j
].nic
)) {
474 nic_shutdown(nics
[j
].nic
);
476 sprintf(temp
,SYSDIR
"/%s", nic2find
);
477 if(fmt_exists(temp
)) {
478 for(k
=0; k
<fnics
; k
++)
479 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
480 if(is_interface_up(nics
[k
].nic
)) {
481 nic_shutdown(nics
[k
].nic
);
483 sprintf(temp
,"dummy%i",k
);
484 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
487 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
492 int create_udev(void)
494 #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
498 if ( (fp
= fopen(UDEV_NET_CONF
, "w")) == NULL
) {
499 fprintf(stderr
,"Couldn't open" UDEV_NET_CONF
);
503 for (i
= 0 ; i
< 4 ; i
++)
505 if (strcmp(knics
[i
].macaddr
, "")) {
506 fprintf(fp
,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics
[i
].macaddr
, lcolourcard
[i
], knics
[i
].description
);
513 int write_configs_netudev(int card
, int colour
)
515 char commandstring
[STRING_SIZE
];
516 struct keyvalue
*kv
= initkeyvalues();
517 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
518 char ucolour
[STRING_SIZE
];
520 sprintf(ucolour
, ucolourcard
[colour
]);
521 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
522 strcpy(knics
[colour
].description
, nics
[card
].description
);
523 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
525 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
528 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
532 sprintf(temp1
, "%s_DEV", ucolour
);
533 sprintf(temp2
, "%s_MACADDR", ucolour
);
534 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
535 replacekeyvalue(kv
, temp1
, temp3
);
536 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
537 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
538 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
539 sprintf(temp1
, "%s_DRIVER", ucolour
);
540 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
542 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
548 int scan_network_cards(void)
551 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
553 const char _driver
[]="driver: ";
554 const char _desc
[]="desc: ";
555 const char _network_hwaddr
[]="network.hwaddr: ";
557 if (!(scanned_nics_read_done
))
559 mysystem("/bin/probenic.sh");
560 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
562 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
565 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
567 temp_line
[strlen(temp_line
) -1] = 0;
568 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
569 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
570 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
571 if (strlen(nics
[count
].macaddr
) > 15 ) {
572 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
577 scanned_nics_read_done
= count
;
578 } else fprintf(flog
,"Scan Networkcards does read.\n");
579 return scanned_nics_read_done
;
584 int nicmenu(int colour
)
586 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
587 int found_NIC_as_Card
[4];
588 char message
[STRING_SIZE
];
590 char cMenuInhalt
[STRING_SIZE
];
591 char MenuInhalt
[20][180];
592 char *pMenuInhalt
[20];
594 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
595 for ( i
=0 ; i
<4;i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
597 // If new nics are found...
598 if (count
> kcount
) {
599 for (i
=0 ; i
< count
; i
++)
602 for (j
=0 ; j
<= kcount
; j
++) {
603 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
609 if ( strlen(nics
[i
].description
) < 55 )
610 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
612 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
613 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
614 strcat (MenuInhalt
[mcount
], "...");
617 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
619 strcat(MenuInhalt
[mcount
], " (");
620 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
621 strcat(MenuInhalt
[mcount
], ")");
622 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
623 found_NIC_as_Card
[mcount
]=i
;
628 pMenuInhalt
[mcount
] = NULL
;
630 sprintf(message
, ctr
[TR_CHOOSE_NETCARD
], ucolourcard
[colour
]);
631 rc
= newtWinMenu( ctr
[TR_NETCARDMENU2
], message
, 50, 5, 5, 6, pMenuInhalt
, &choise
, ctr
[TR_OK
], ctr
[TR_SELECT
], ctr
[TR_CANCEL
], NULL
);
633 if ( rc
== 0 || rc
== 1) {
634 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
638 // We have to add here that you can manually add a device
639 errorbox( ctr
[TR_ERROR_INTERFACES
]);
644 int clear_card_entry(int card
)
646 struct keyvalue
*kv
= initkeyvalues();
647 char temp
[STRING_SIZE
];
649 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
652 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
656 strcpy(knics
[card
].driver
, "");
657 strcpy(knics
[card
].description
, ctr
[TR_UNSET
]);
658 strcpy(knics
[card
].macaddr
, "");
659 strcpy(knics
[card
].colour
, "");
660 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
661 replacekeyvalue(kv
, temp
, "");
662 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
663 replacekeyvalue(kv
, temp
, "");
664 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
665 replacekeyvalue(kv
, temp
, "");
666 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
667 replacekeyvalue(kv
, temp
, "");
669 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
675 int ask_clear_card_entry(int card
)
677 char message
[STRING_SIZE
];
680 sprintf(message
, ctr
[TR_REMOVE_CARD
], ucolourcard
[card
]);
681 rc
= newtWinChoice(ctr
[TR_WARNING
], ctr
[TR_OK
], ctr
[TR_CANCEL
], message
);
683 if ( rc
= 0 || rc
== 1) {
684 clear_card_entry(card
);
690 /* Manual entry for gurus. */
691 int manualdriver(char *driver
, char *driveroptions
)
693 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
694 struct newtWinEntry entries
[] =
695 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
697 char commandstring
[STRING_SIZE
];
701 strcpy(driveroptions
, "");
703 rc
= newtWinEntries(ctr
[TR_SELECT_NETWORK_DRIVER
],
704 ctr
[TR_MODULE_PARAMETERS
], 50, 5, 5, 40, entries
,
705 ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
706 if (rc
== 0 || rc
== 1)
708 if (strlen(values
[0]))
710 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
711 if (runcommandwithstatus(commandstring
, ctr
[TR_LOADING_MODULE
]) == 0)
713 if ((driverend
= strchr(values
[0], ' ')))
716 strcpy(driver
, values
[0]);
717 strcpy(driveroptions
, driverend
+ 1);
721 strcpy(driver
, values
[0]);
722 strcpy(driveroptions
, "");
726 errorbox(ctr
[TR_UNABLE_TO_LOAD_DRIVER_MODULE
]);
729 errorbox(ctr
[TR_MODULE_NAME_CANNOT_BE_BLANK
]);