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, ctr
[TR_DHCP
], startdhcptype
, statictyperadio
);
96 pppoetyperadio
= newtRadiobutton(2, 6, ctr
[TR_PPP_DIALUP
], 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
, ucolourcard
[card
]);
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
]);
370 found
+= get_knic(_GREEN_CARD_
);
371 found
+= get_knic(_RED_CARD_
);
372 found
+= get_knic(_ORANGE_CARD_
);
373 found
+= get_knic(_BLUE_CARD_
);
378 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
380 if (stat(fname
, &st
) == -1) return 0;
384 int is_interface_up(char *card
) { /* Check if the interface is UP */
385 char temp
[STRING_SIZE
];
387 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
388 if (mysystem(temp
)) return 0; else return 1;
391 int rename_device(char *old_name
, char *new_name
) {
392 char temp
[STRING_SIZE
];
394 sprintf(temp
,SYSDIR
"/%s", old_name
);
395 if (!(fmt_exists(temp
))) {
396 fprintf(flog
,"Device not found: %s\n",old_name
);
399 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
405 char g_temp
[STRING_SIZE
]="";
406 char* readmac(char *card
) {
408 char temp
[STRING_SIZE
], mac
[20];
410 sprintf(temp
,"/sys/class/net/%s/address",card
);
411 if( (fp
= fopen(temp
, "r")) == NULL
) {
412 fprintf(flog
,"Couldn't open: %s\n",temp
);
422 char* find_nic4mac(char *findmac
) {
424 struct dirent
*dirzeiger
;
425 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
427 if((dir
=opendir(SYSDIR
)) == NULL
) {
428 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
433 while((dirzeiger
=readdir(dir
)) != NULL
) {
434 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
435 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
436 if (strcmp(findmac
, temp2
) == 0) {
437 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
443 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
444 strcpy(g_temp
, temp
);
448 int nic_shutdown(char *nic
) {
449 char temp
[STRING_SIZE
];
451 sprintf(temp
,"ip link set %s down", nic
);
455 int nic_startup(char *nic
) {
456 char temp
[STRING_SIZE
];
458 sprintf(temp
,"ip link set %s up", nic
);
463 int rename_nics(void) {
465 int fnics
= scan_network_cards();
466 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
469 if (strcmp(knics
[i
].macaddr
, ""))
470 for(j
=0; j
<fnics
; j
++)
471 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
472 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
473 if(strcmp(nic2find
, nics
[j
].nic
)) {
474 if(is_interface_up(nics
[j
].nic
)) {
475 nic_shutdown(nics
[j
].nic
);
477 sprintf(temp
,SYSDIR
"/%s", nic2find
);
478 if(fmt_exists(temp
)) {
479 for(k
=0; k
<fnics
; k
++)
480 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
481 if(is_interface_up(nics
[k
].nic
)) {
482 nic_shutdown(nics
[k
].nic
);
484 sprintf(temp
,"dummy%i",k
);
485 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
488 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
493 int create_udev(void)
495 #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
499 if ( (fp
= fopen(UDEV_NET_CONF
, "w")) == NULL
) {
500 fprintf(stderr
,"Couldn't open" UDEV_NET_CONF
);
504 for (i
= 0 ; i
< 4 ; i
++)
506 if (strcmp(knics
[i
].macaddr
, "")) {
507 fprintf(fp
,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{type}==\"1\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics
[i
].macaddr
, lcolourcard
[i
], knics
[i
].description
);
514 int write_configs_netudev(int card
, int colour
)
516 char commandstring
[STRING_SIZE
];
517 struct keyvalue
*kv
= initkeyvalues();
518 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
519 char ucolour
[STRING_SIZE
];
521 sprintf(ucolour
, ucolourcard
[colour
]);
522 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
523 strcpy(knics
[colour
].description
, nics
[card
].description
);
524 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
526 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
529 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
533 sprintf(temp1
, "%s_DEV", ucolour
);
534 sprintf(temp2
, "%s_MACADDR", ucolour
);
535 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
536 replacekeyvalue(kv
, temp1
, temp3
);
537 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
538 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
539 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
540 sprintf(temp1
, "%s_DRIVER", ucolour
);
541 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
543 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
549 int scan_network_cards(void)
552 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
554 const char _driver
[]="driver: ";
555 const char _desc
[]="desc: ";
556 const char _network_hwaddr
[]="network.hwaddr: ";
558 if (!(scanned_nics_read_done
))
560 mysystem("/bin/probenic.sh");
561 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
563 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
566 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
568 temp_line
[strlen(temp_line
) -1] = 0;
569 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
570 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
571 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
572 if (strlen(nics
[count
].macaddr
) > 15 ) {
573 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
578 scanned_nics_read_done
= count
;
579 } else fprintf(flog
,"Scan Networkcards does read.\n");
580 return scanned_nics_read_done
;
585 int nicmenu(int colour
)
587 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
588 int found_NIC_as_Card
[4];
589 char message
[STRING_SIZE
];
591 char cMenuInhalt
[STRING_SIZE
];
592 char MenuInhalt
[20][180];
593 char *pMenuInhalt
[20];
595 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
596 for ( i
=0 ; i
<4;i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
598 // If new nics are found...
599 if (count
> kcount
) {
600 for (i
=0 ; i
< count
; i
++)
603 for (j
=0 ; j
<= kcount
; j
++) {
604 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
610 if ( strlen(nics
[i
].description
) < 55 )
611 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
613 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
614 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
615 strcat (MenuInhalt
[mcount
], "...");
618 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
620 strcat(MenuInhalt
[mcount
], " (");
621 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
622 strcat(MenuInhalt
[mcount
], ")");
623 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
624 found_NIC_as_Card
[mcount
]=i
;
629 pMenuInhalt
[mcount
] = NULL
;
631 sprintf(message
, ctr
[TR_CHOOSE_NETCARD
], ucolourcard
[colour
]);
632 rc
= newtWinMenu( ctr
[TR_NETCARDMENU2
], message
, 50, 5, 5, 6, pMenuInhalt
, &choise
, ctr
[TR_OK
], ctr
[TR_SELECT
], ctr
[TR_CANCEL
], NULL
);
634 if ( rc
== 0 || rc
== 1) {
635 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
639 // We have to add here that you can manually add a device
640 errorbox( ctr
[TR_ERROR_INTERFACES
]);
645 int clear_card_entry(int card
)
647 struct keyvalue
*kv
= initkeyvalues();
648 char temp
[STRING_SIZE
];
650 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
653 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
657 strcpy(knics
[card
].driver
, "");
658 strcpy(knics
[card
].description
, ctr
[TR_UNSET
]);
659 strcpy(knics
[card
].macaddr
, "");
660 strcpy(knics
[card
].colour
, "");
661 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
662 replacekeyvalue(kv
, temp
, "");
663 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
664 replacekeyvalue(kv
, temp
, "");
665 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
666 replacekeyvalue(kv
, temp
, "");
667 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
668 replacekeyvalue(kv
, temp
, "");
670 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
676 int ask_clear_card_entry(int card
)
678 char message
[STRING_SIZE
];
681 sprintf(message
, ctr
[TR_REMOVE_CARD
], ucolourcard
[card
]);
682 rc
= newtWinChoice(ctr
[TR_WARNING
], ctr
[TR_OK
], ctr
[TR_CANCEL
], message
);
684 if ( rc
= 0 || rc
== 1) {
685 clear_card_entry(card
);
691 /* Manual entry for gurus. */
692 int manualdriver(char *driver
, char *driveroptions
)
694 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
695 struct newtWinEntry entries
[] =
696 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
698 char commandstring
[STRING_SIZE
];
702 strcpy(driveroptions
, "");
704 rc
= newtWinEntries(ctr
[TR_SELECT_NETWORK_DRIVER
],
705 ctr
[TR_MODULE_PARAMETERS
], 50, 5, 5, 40, entries
,
706 ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
707 if (rc
== 0 || rc
== 1)
709 if (strlen(values
[0]))
711 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
712 if (runcommandwithstatus(commandstring
, ctr
[TR_LOADING_MODULE
]) == 0)
714 if ((driverend
= strchr(values
[0], ' ')))
717 strcpy(driver
, values
[0]);
718 strcpy(driveroptions
, driverend
+ 1);
722 strcpy(driver
, values
[0]);
723 strcpy(driveroptions
, "");
727 errorbox(ctr
[TR_UNABLE_TO_LOAD_DRIVER_MODULE
]);
730 errorbox(ctr
[TR_MODULE_NAME_CANNOT_BE_BLANK
]);