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>
16 #define _(x) dgettext("setup", x)
23 extern struct nic nics
[];
24 extern struct knic knics
[];
26 char *ucolourcard
[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL
};
27 char *lcolourcard
[] = { "green", "red", "orange", "blue", NULL
};
29 int scanned_nics_read_done
= 0;
31 newtComponent networkform
;
32 newtComponent addressentry
;
33 newtComponent netmaskentry
;
34 newtComponent statictyperadio
;
35 newtComponent dhcptyperadio
;
36 newtComponent pppoetyperadio
;
37 newtComponent dhcphostnameentry
;
38 newtComponent dhcpforcemtuentry
;
40 /* acceptable character filter for IP and netmaks entry boxes */
41 static int ip_input_filter(newtComponent entry
, void * data
, int ch
, int cursor
)
43 if ((ch
>= '0' && ch
<= '9') || ch
== '.' || ch
== '\r' || ch
>= NEWT_KEY_EXTRA_BASE
)
48 /* This is a groovie dialog for showing network info. Takes a keyvalue list,
49 * a colour and a dhcp flag. Shows the current settings, and rewrites them
50 * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
51 int changeaddress(struct keyvalue
*kv
, char *colour
, int typeflag
,
52 char *defaultdhcphostname
)
56 char *dhcphostnameresult
;
57 char *dhcpforcemturesult
;
58 struct newtExitStruct es
;
60 newtComponent addresslabel
;
61 newtComponent netmasklabel
;
62 newtComponent dhcphostnamelabel
;
63 newtComponent dhcpforcemtulabel
;
64 newtComponent ok
, cancel
;
66 char temp
[STRING_SIZE
];
67 char addressfield
[STRING_SIZE
];
68 char netmaskfield
[STRING_SIZE
];
69 char typefield
[STRING_SIZE
];
70 char dhcphostnamefield
[STRING_SIZE
];
71 char dhcpforcemtufield
[STRING_SIZE
];
74 char type
[STRING_SIZE
];
75 int startstatictype
= 0;
76 int startdhcptype
= 0;
77 int startpppoetype
= 0;
78 unsigned char buffer
[sizeof(struct in_addr
)];
80 /* Build some key strings. */
81 sprintf(addressfield
, "%s_ADDRESS", colour
);
82 sprintf(netmaskfield
, "%s_NETMASK", colour
);
83 sprintf(typefield
, "%s_TYPE", colour
);
84 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
85 sprintf(dhcpforcemtufield
, "%s_DHCP_FORCE_MTU", colour
);
87 sprintf(message
, _("Interface - %s"), colour
);
88 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
90 networkform
= newtForm(NULL
, NULL
, 0);
92 sprintf(message
, _("Enter the IP address information for the %s interface."), colour
);
93 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
94 newtFormAddComponent(networkform
, header
);
96 /* See if we need a dhcp checkbox. If we do, then we shift the contents
97 * of the window down two rows to make room. */
100 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
101 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
102 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
103 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
104 statictyperadio
= newtRadiobutton(2, 4, _("Static"), startstatictype
, NULL
);
105 dhcptyperadio
= newtRadiobutton(2, 5, _("DHCP"), startdhcptype
, statictyperadio
);
106 pppoetyperadio
= newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"),
107 startpppoetype
, dhcptyperadio
);
108 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
109 pppoetyperadio
, NULL
);
110 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
111 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
112 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
113 dhcphostnamelabel
= newtTextbox(2, 8, 18, 1, 0);
114 newtTextboxSetText(dhcphostnamelabel
, _("DHCP Hostname:"));
115 dhcpforcemtulabel
= newtTextbox(2, 9, 18, 1, 0);
116 newtTextboxSetText(dhcpforcemtulabel
, _("Force DHCP MTU:"));
117 strcpy(temp
, defaultdhcphostname
);
118 findkey(kv
, dhcphostnamefield
, temp
);
119 dhcphostnameentry
= newtEntry(20, 8, temp
, 20, &dhcphostnameresult
, 0);
121 findkey(kv
, dhcpforcemtufield
, temp
);
122 dhcpforcemtuentry
= newtEntry(20, 9, temp
, 20, &dhcpforcemturesult
, 0);
123 newtFormAddComponent(networkform
, dhcphostnamelabel
);
124 newtFormAddComponent(networkform
, dhcphostnameentry
);
125 newtFormAddComponent(networkform
, dhcpforcemtulabel
);
126 newtFormAddComponent(networkform
, dhcpforcemtuentry
);
127 if (startdhcptype
== 0)
129 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
130 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
134 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
135 newtTextboxSetText(addresslabel
, _("IP address:"));
137 findkey(kv
, addressfield
, temp
);
138 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
139 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
140 if (typeflag
== 1 && startstatictype
== 0)
141 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
142 newtFormAddComponent(networkform
, addresslabel
);
143 newtFormAddComponent(networkform
, addressentry
);
146 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
147 newtTextboxSetText(netmasklabel
, _("Network mask:"));
148 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
149 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
150 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
151 if (typeflag
== 1 && startstatictype
== 0)
152 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
154 newtFormAddComponent(networkform
, netmasklabel
);
155 newtFormAddComponent(networkform
, netmaskentry
);
158 ok
= newtButton(8, (typeflag
? 14 : 7), _("OK"));
159 cancel
= newtButton(26, (typeflag
? 14 : 7), _("Cancel"));
161 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
164 newtDrawForm(networkform
);
169 newtFormRun(networkform
, &es
);
173 /* OK was pressed; verify the contents of each entry. */
174 strcpy(message
, _("The following fields are invalid:"));
175 strcat(message
, "\n\n");
177 strcpy(type
, "STATIC");
180 if (strcmp(type
, "STATIC") == 0)
182 if (inet_addr(addressresult
) == INADDR_NONE
)
184 strcat(message
, _("IP address"));
185 strcat(message
, "\n");
188 if (inet_pton(AF_INET
, netmaskresult
, &buffer
) == 0)
190 strcat(message
, _("Network mask"));
191 strcat(message
, "\n");
195 if (strcmp(type
, "DHCP") == 0)
197 if (!strlen(dhcphostnameresult
))
199 strcat(message
, _("DHCP hostname"));
200 strcat(message
, "\n");
208 /* No errors! Set new values, depending on dhcp flag etc. */
211 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
212 replacekeyvalue(kv
, dhcpforcemtufield
, dhcpforcemturesult
);
213 if (strcmp(type
, "STATIC") != 0)
215 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
216 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
220 replacekeyvalue(kv
, addressfield
, addressresult
);
221 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
223 replacekeyvalue(kv
, typefield
, type
);
227 replacekeyvalue(kv
, addressfield
, addressresult
);
228 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
231 setnetaddress(kv
, colour
);
235 /* Workaround for a bug that dhcp radiobutton also end the dialog at arm
238 if (es
.u
.co
!= cancel
) {
245 newtFormDestroy(networkform
);
251 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
252 int gettype(char *type
)
254 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
256 if (selected
== statictyperadio
)
257 strcpy(type
, "STATIC");
258 else if (selected
== dhcptyperadio
)
259 strcpy(type
, "DHCP");
260 else if (selected
== pppoetyperadio
)
261 strcpy(type
, "PPPOE");
263 strcpy(type
, "ERROR");
268 int setnetaddress(struct keyvalue
*kv
, char *colour
)
270 char addressfield
[STRING_SIZE
];
271 char netaddressfield
[STRING_SIZE
];
272 char netmaskfield
[STRING_SIZE
];
273 char address
[STRING_SIZE
];
274 char netmask
[STRING_SIZE
];
275 unsigned long int intaddress
;
276 unsigned long int intnetaddress
;
277 unsigned long int intnetmask
;
281 /* Build some key strings. */
282 sprintf(addressfield
, "%s_ADDRESS", colour
);
283 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
284 sprintf(netmaskfield
, "%s_NETMASK", colour
);
286 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
287 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
289 /* Calculate netaddress. Messy.. */
290 intaddress
= inet_addr(address
);
291 intnetmask
= inet_addr(netmask
);
293 intnetaddress
= intaddress
& intnetmask
;
294 temp
.s_addr
= intnetaddress
;
295 netaddress
= inet_ntoa(temp
);
297 replacekeyvalue(kv
, netaddressfield
, netaddress
);
302 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
304 void networkdialogcallbacktype(newtComponent cm
, void *data
)
306 char type
[STRING_SIZE
];
310 if (strcmp(type
, "STATIC") != 0)
312 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
313 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
317 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
318 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
320 if (strcmp(type
, "DHCP") == 0)
322 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
323 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
327 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
328 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
331 newtDrawForm(networkform
);
334 int interfacecheck(struct keyvalue
*kv
, char *colour
)
336 char temp
[STRING_SIZE
];
337 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
340 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
341 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
342 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
344 for (c
= 0; c
< 3; c
++)
346 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
347 if (!(strlen(temp
))) return 0;
352 /* Funky routine for loading all drivers (cept those are already loaded.). */
353 int probecards(char *driver
, char *driveroptions
)
358 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
360 struct keyvalue
*kv
= initkeyvalues();
361 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
364 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
367 errorbox(_("Unable to open settings file"));
371 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
372 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
374 strcpy(knics
[ card
].macaddr
, temp
);
375 strcpy(knics
[ card
].colour
, ucolourcard
[card
]);
377 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
378 findkey(kv
, searchstr
, temp
);
379 strcpy(knics
[ card
].description
, temp
);
381 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
382 findkey(kv
, searchstr
, temp
);
383 strcpy(knics
[ card
].driver
, temp
);
386 strcpy(knics
[ card
].description
, _("Unset"));
397 found
+= get_knic(_GREEN_CARD_
);
398 found
+= get_knic(_RED_CARD_
);
399 found
+= get_knic(_ORANGE_CARD_
);
400 found
+= get_knic(_BLUE_CARD_
);
405 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
407 if (stat(fname
, &st
) == -1) return 0;
411 int is_interface_up(char *card
) { /* Check if the interface is UP */
412 char temp
[STRING_SIZE
];
414 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
415 if (mysystem(NULL
, temp
)) return 0; else return 1;
418 int rename_device(char *old_name
, char *new_name
) {
419 char temp
[STRING_SIZE
];
421 sprintf(temp
,SYSDIR
"/%s", old_name
);
422 if (!(fmt_exists(temp
))) {
423 fprintf(flog
,"Device not found: %s\n",old_name
);
426 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
427 mysystem(NULL
, temp
);
432 char g_temp
[STRING_SIZE
]="";
433 char* readmac(char *card
) {
435 char temp
[STRING_SIZE
], mac
[20];
437 sprintf(temp
,"/sys/class/net/%s/address",card
);
438 if( (fp
= fopen(temp
, "r")) == NULL
) {
439 fprintf(flog
,"Couldn't open: %s\n",temp
);
449 char* find_nic4mac(char *findmac
) {
451 struct dirent
*dirzeiger
;
452 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
454 if((dir
=opendir(SYSDIR
)) == NULL
) {
455 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
460 while((dirzeiger
=readdir(dir
)) != NULL
) {
461 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
462 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
463 if (strcmp(findmac
, temp2
) == 0) {
464 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
470 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
471 strcpy(g_temp
, temp
);
475 int nic_shutdown(char *nic
) {
476 char temp
[STRING_SIZE
];
478 sprintf(temp
,"ip link set %s down", nic
);
479 mysystem(NULL
, temp
);
482 int nic_startup(char *nic
) {
483 char temp
[STRING_SIZE
];
485 sprintf(temp
,"ip link set %s up", nic
);
486 mysystem(NULL
, temp
);
490 int rename_nics(void) {
492 int fnics
= scan_network_cards();
493 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
496 if (strcmp(knics
[i
].macaddr
, ""))
497 for(j
=0; j
<fnics
; j
++)
498 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
499 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
500 if(strcmp(nic2find
, nics
[j
].nic
)) {
501 if(is_interface_up(nics
[j
].nic
)) {
502 nic_shutdown(nics
[j
].nic
);
504 sprintf(temp
,SYSDIR
"/%s", nic2find
);
505 if(fmt_exists(temp
)) {
506 for(k
=0; k
<fnics
; k
++)
507 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
508 if(is_interface_up(nics
[k
].nic
)) {
509 nic_shutdown(nics
[k
].nic
);
511 sprintf(temp
,"dummy%i",k
);
512 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
515 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
520 int write_configs_netudev(int card
, int colour
)
522 char commandstring
[STRING_SIZE
];
523 struct keyvalue
*kv
= initkeyvalues();
524 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
525 char ucolour
[STRING_SIZE
];
527 sprintf(ucolour
, ucolourcard
[colour
]);
528 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
529 strcpy(knics
[colour
].description
, nics
[card
].description
);
530 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
532 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
535 errorbox(_("Unable to open settings file"));
539 sprintf(temp1
, "%s_DEV", ucolour
);
540 sprintf(temp2
, "%s_MACADDR", ucolour
);
541 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
542 replacekeyvalue(kv
, temp1
, temp3
);
543 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
544 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
545 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
546 sprintf(temp1
, "%s_DRIVER", ucolour
);
547 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
549 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
555 int scan_network_cards(void)
558 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
560 const char _driver
[]="driver: ";
561 const char _desc
[]="desc: ";
562 const char _network_hwaddr
[]="network.hwaddr: ";
564 if (!(scanned_nics_read_done
))
566 mysystem(NULL
, "/usr/bin/probenic.sh");
567 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
569 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
572 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
574 temp_line
[strlen(temp_line
) -1] = 0;
575 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
576 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
577 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
578 if (strlen(nics
[count
].macaddr
) > 15 ) {
579 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
584 scanned_nics_read_done
= count
;
585 } else fprintf(flog
,"Scan Networkcards does read.\n");
586 return scanned_nics_read_done
;
591 int nicmenu(int colour
)
593 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
594 int found_NIC_as_Card
[MAX_NICS
];
595 char message
[STRING_SIZE
];
596 char temp
[STRING_SIZE
];
598 char cMenuInhalt
[STRING_SIZE
];
599 char MenuInhalt
[MAX_NICS
][STRING_SIZE
];
600 char *pMenuInhalt
[MAX_NICS
];
602 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
603 for (i
=0; i
<MAX_NICS
; i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
605 // If new nics are found...
606 if (count
> kcount
) {
607 for (i
=0 ; i
< count
; i
++)
610 for (j
=0 ; j
<= kcount
; j
++) {
611 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
617 if ( strlen(nics
[i
].description
) < 55 )
618 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
620 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
621 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
622 strcat (MenuInhalt
[mcount
], "...");
625 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
627 strcat(MenuInhalt
[mcount
], " (");
628 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
629 strcat(MenuInhalt
[mcount
], ")");
630 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
631 found_NIC_as_Card
[mcount
]=i
;
636 pMenuInhalt
[mcount
] = NULL
;
638 sprintf(message
, _("Please choose a networkcard for the following interface - %s."), ucolourcard
[colour
]);
641 rc
= newtWinMenu(_("Extended Network Menu"), message
, 50, 5, 5, mcount
, pMenuInhalt
, &choise
,
642 _("Select"), _("Identify"), _("Cancel"), NULL
);
644 sprintf(temp
, "/sbin/ip link set %s up", nics
[found_NIC_as_Card
[choise
]].nic
);
645 mysystem(NULL
, temp
);
646 sprintf(temp
, "/usr/sbin/ethtool -p %s 10", nics
[found_NIC_as_Card
[choise
]].nic
);
647 if (runcommandwithstatus(temp
, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds..."), NULL
) != 0) {
648 errorbox(_("Identification is not supported by this interface."));
649 sprintf(temp
, "/sbin/ip link set %s down", nics
[found_NIC_as_Card
[choise
]].nic
);
650 mysystem(NULL
, temp
);
654 if ( rc
== 0 || rc
== 1) {
655 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
659 // We have to add here that you can manually add a device
660 errorbox(_("There are no unassigned interfaces on your system."));
665 int clear_card_entry(int card
)
667 struct keyvalue
*kv
= initkeyvalues();
668 char temp
[STRING_SIZE
];
670 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
673 errorbox(_("Unable to open settings file"));
677 strcpy(knics
[card
].driver
, "");
678 strcpy(knics
[card
].description
, _("Unset"));
679 strcpy(knics
[card
].macaddr
, "");
680 strcpy(knics
[card
].colour
, "");
681 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
682 replacekeyvalue(kv
, temp
, "");
683 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
684 replacekeyvalue(kv
, temp
, "");
685 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
686 replacekeyvalue(kv
, temp
, "");
687 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
688 replacekeyvalue(kv
, temp
, "");
690 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
696 int ask_clear_card_entry(int card
)
698 char message
[STRING_SIZE
];
701 sprintf(message
, _("Do you really want to remove the assigned %s interface?"), ucolourcard
[card
]);
702 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
704 if ( rc
= 0 || rc
== 1) {
705 clear_card_entry(card
);
711 /* Manual entry for gurus. */
712 int manualdriver(char *driver
, char *driveroptions
)
714 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
715 struct newtWinEntry entries
[] =
716 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
718 char commandstring
[STRING_SIZE
];
722 strcpy(driveroptions
, "");
724 rc
= newtWinEntries(_("Select network driver"), _("Set additional module parameters"),
725 50, 5, 5, 40, entries
, _("OK"), _("Cancel"), NULL
);
726 if (rc
== 0 || rc
== 1)
728 if (strlen(values
[0]))
730 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
731 if (runcommandwithstatus(commandstring
, _("Loading module..."), _("Loading module..."), NULL
) == 0)
733 if ((driverend
= strchr(values
[0], ' ')))
736 strcpy(driver
, values
[0]);
737 strcpy(driveroptions
, driverend
+ 1);
741 strcpy(driver
, values
[0]);
742 strcpy(driveroptions
, "");
746 errorbox(_("Unable to load driver module."));
749 errorbox(_("Module name cannot be blank."));