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
;
34 newtComponent dhcpforcemtuentry
;
36 /* acceptable character filter for IP and netmaks entry boxes */
37 static int ip_input_filter(newtComponent entry
, void * data
, int ch
, int cursor
)
39 if ((ch
>= '0' && ch
<= '9') || ch
== '.' || ch
== '\r' || ch
>= NEWT_KEY_EXTRA_BASE
)
44 /* This is a groovie dialog for showing network info. Takes a keyvalue list,
45 * a colour and a dhcp flag. Shows the current settings, and rewrites them
46 * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
47 int changeaddress(struct keyvalue
*kv
, char *colour
, int typeflag
,
48 char *defaultdhcphostname
)
52 char *dhcphostnameresult
;
53 char *dhcpforcemturesult
;
54 struct newtExitStruct es
;
56 newtComponent addresslabel
;
57 newtComponent netmasklabel
;
58 newtComponent dhcphostnamelabel
;
59 newtComponent dhcpforcemtulabel
;
60 newtComponent ok
, cancel
;
62 char temp
[STRING_SIZE
];
63 char addressfield
[STRING_SIZE
];
64 char netmaskfield
[STRING_SIZE
];
65 char typefield
[STRING_SIZE
];
66 char dhcphostnamefield
[STRING_SIZE
];
67 char dhcpforcemtufield
[STRING_SIZE
];
70 char type
[STRING_SIZE
];
71 int startstatictype
= 0;
72 int startdhcptype
= 0;
73 int startpppoetype
= 0;
75 /* Build some key strings. */
76 sprintf(addressfield
, "%s_ADDRESS", colour
);
77 sprintf(netmaskfield
, "%s_NETMASK", colour
);
78 sprintf(typefield
, "%s_TYPE", colour
);
79 sprintf(dhcphostnamefield
, "%s_DHCP_HOSTNAME", colour
);
80 sprintf(dhcpforcemtufield
, "%s_DHCP_FORCE_MTU", colour
);
82 sprintf(message
, ctr
[TR_INTERFACE
], colour
);
83 newtCenteredWindow(44, (typeflag
? 18 : 12), message
);
85 networkform
= newtForm(NULL
, NULL
, 0);
87 sprintf(message
, ctr
[TR_ENTER_THE_IP_ADDRESS_INFORMATION
], colour
);
88 header
= newtTextboxReflowed(1, 1, message
, 42, 0, 0, 0);
89 newtFormAddComponent(networkform
, header
);
91 /* See if we need a dhcp checkbox. If we do, then we shift the contents
92 * of the window down two rows to make room. */
95 strcpy(temp
, "STATIC"); findkey(kv
, typefield
, temp
);
96 if (strcmp(temp
, "STATIC") == 0) startstatictype
= 1;
97 if (strcmp(temp
, "DHCP") == 0) startdhcptype
= 1;
98 if (strcmp(temp
, "PPPOE") == 0) startpppoetype
= 1;
99 statictyperadio
= newtRadiobutton(2, 4, ctr
[TR_STATIC
], startstatictype
, NULL
);
100 dhcptyperadio
= newtRadiobutton(2, 5, ctr
[TR_DHCP
], startdhcptype
, statictyperadio
);
101 pppoetyperadio
= newtRadiobutton(2, 6, ctr
[TR_PPP_DIALUP
], startpppoetype
, dhcptyperadio
);
102 newtFormAddComponents(networkform
, statictyperadio
, dhcptyperadio
,
103 pppoetyperadio
, NULL
);
104 newtComponentAddCallback(statictyperadio
, networkdialogcallbacktype
, NULL
);
105 newtComponentAddCallback(dhcptyperadio
, networkdialogcallbacktype
, NULL
);
106 newtComponentAddCallback(pppoetyperadio
, networkdialogcallbacktype
, NULL
);
107 dhcphostnamelabel
= newtTextbox(2, 8, 18, 1, 0);
108 newtTextboxSetText(dhcphostnamelabel
, ctr
[TR_DHCP_HOSTNAME
]);
109 dhcpforcemtulabel
= newtTextbox(2, 9, 18, 1, 0);
110 newtTextboxSetText(dhcpforcemtulabel
, ctr
[TR_DHCP_FORCE_MTU
]);
111 strcpy(temp
, defaultdhcphostname
);
112 findkey(kv
, dhcphostnamefield
, temp
);
113 dhcphostnameentry
= newtEntry(20, 8, temp
, 20, &dhcphostnameresult
, 0);
115 findkey(kv
, dhcpforcemtufield
, temp
);
116 dhcpforcemtuentry
= newtEntry(20, 9, temp
, 20, &dhcpforcemturesult
, 0);
117 newtFormAddComponent(networkform
, dhcphostnamelabel
);
118 newtFormAddComponent(networkform
, dhcphostnameentry
);
119 newtFormAddComponent(networkform
, dhcpforcemtulabel
);
120 newtFormAddComponent(networkform
, dhcpforcemtuentry
);
121 if (startdhcptype
== 0)
123 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
124 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
128 addresslabel
= newtTextbox(2, (typeflag
? 11 : 4) + 0, 18, 1, 0);
129 newtTextboxSetText(addresslabel
, ctr
[TR_IP_ADDRESS_PROMPT
]);
131 findkey(kv
, addressfield
, temp
);
132 addressentry
= newtEntry(20, (typeflag
? 11 : 4) + 0, temp
, 20, &addressresult
, 0);
133 newtEntrySetFilter(addressentry
, ip_input_filter
, NULL
);
134 if (typeflag
== 1 && startstatictype
== 0)
135 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
136 newtFormAddComponent(networkform
, addresslabel
);
137 newtFormAddComponent(networkform
, addressentry
);
140 netmasklabel
= newtTextbox(2, (typeflag
? 11 : 4) + 1, 18, 1, 0);
141 newtTextboxSetText(netmasklabel
, ctr
[TR_NETMASK_PROMPT
]);
142 strcpy(temp
, "255.255.255.0"); findkey(kv
, netmaskfield
, temp
);
143 netmaskentry
= newtEntry(20, (typeflag
? 11 : 4) + 1, temp
, 20, &netmaskresult
, 0);
144 newtEntrySetFilter(netmaskentry
, ip_input_filter
, NULL
);
145 if (typeflag
== 1 && startstatictype
== 0)
146 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
148 newtFormAddComponent(networkform
, netmasklabel
);
149 newtFormAddComponent(networkform
, netmaskentry
);
152 ok
= newtButton(8, (typeflag
? 14 : 7), ctr
[TR_OK
]);
153 cancel
= newtButton(26, (typeflag
? 14 : 7), ctr
[TR_CANCEL
]);
155 newtFormAddComponents(networkform
, ok
, cancel
, NULL
);
158 newtDrawForm(networkform
);
163 newtFormRun(networkform
, &es
);
167 /* OK was pressed; verify the contents of each entry. */
168 strcpy(message
, ctr
[TR_INVALID_FIELDS
]);
170 strcpy(type
, "STATIC");
173 if (strcmp(type
, "STATIC") == 0)
175 if (inet_addr(addressresult
) == INADDR_NONE
)
177 strcat(message
, ctr
[TR_IP_ADDRESS_CR
]);
180 if (inet_addr(netmaskresult
) == INADDR_NONE
)
182 strcat(message
, ctr
[TR_NETWORK_MASK_CR
]);
186 if (strcmp(type
, "DHCP") == 0)
188 if (!strlen(dhcphostnameresult
))
190 strcat(message
, ctr
[TR_DHCP_HOSTNAME_CR
]);
198 /* No errors! Set new values, depending on dhcp flag etc. */
201 replacekeyvalue(kv
, dhcphostnamefield
, dhcphostnameresult
);
202 replacekeyvalue(kv
, dhcpforcemtufield
, dhcpforcemturesult
);
203 if (strcmp(type
, "STATIC") != 0)
205 replacekeyvalue(kv
, addressfield
, "0.0.0.0");
206 replacekeyvalue(kv
, netmaskfield
, "0.0.0.0");
210 replacekeyvalue(kv
, addressfield
, addressresult
);
211 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
213 replacekeyvalue(kv
, typefield
, type
);
217 replacekeyvalue(kv
, addressfield
, addressresult
);
218 replacekeyvalue(kv
, netmaskfield
, netmaskresult
);
221 setnetaddress(kv
, colour
);
228 newtFormDestroy(networkform
);
234 /* for pppoe: return string thats type STATIC, DHCP or PPPOE */
235 int gettype(char *type
)
237 newtComponent selected
= newtRadioGetCurrent(statictyperadio
);
239 if (selected
== statictyperadio
)
240 strcpy(type
, "STATIC");
241 else if (selected
== dhcptyperadio
)
242 strcpy(type
, "DHCP");
243 else if (selected
== pppoetyperadio
)
244 strcpy(type
, "PPPOE");
246 strcpy(type
, "ERROR");
251 /* 0.9.9: calculates broadcast too. */
252 int setnetaddress(struct keyvalue
*kv
, char *colour
)
254 char addressfield
[STRING_SIZE
];
255 char netaddressfield
[STRING_SIZE
];
256 char netmaskfield
[STRING_SIZE
];
257 char broadcastfield
[STRING_SIZE
];
258 char address
[STRING_SIZE
];
259 char netmask
[STRING_SIZE
];
260 unsigned long int intaddress
;
261 unsigned long int intnetaddress
;
262 unsigned long int intnetmask
;
263 unsigned long int intbroadcast
;
268 /* Build some key strings. */
269 sprintf(addressfield
, "%s_ADDRESS", colour
);
270 sprintf(netaddressfield
, "%s_NETADDRESS", colour
);
271 sprintf(netmaskfield
, "%s_NETMASK", colour
);
272 sprintf(broadcastfield
, "%s_BROADCAST", colour
);
274 strcpy(address
, ""); findkey(kv
, addressfield
, address
);
275 strcpy(netmask
, ""); findkey(kv
, netmaskfield
, netmask
);
277 /* Calculate netaddress. Messy.. */
278 intaddress
= inet_addr(address
);
279 intnetmask
= inet_addr(netmask
);
281 intnetaddress
= intaddress
& intnetmask
;
282 temp
.s_addr
= intnetaddress
;
283 netaddress
= inet_ntoa(temp
);
285 replacekeyvalue(kv
, netaddressfield
, netaddress
);
287 intbroadcast
= intnetaddress
| ~intnetmask
;
288 temp
.s_addr
= intbroadcast
;
289 broadcast
= inet_ntoa(temp
);
291 replacekeyvalue(kv
, broadcastfield
, broadcast
);
296 /* Called when dhcp flag is toggled. Toggle disabled state of other 3
298 void networkdialogcallbacktype(newtComponent cm
, void *data
)
300 char type
[STRING_SIZE
];
304 if (strcmp(type
, "STATIC") != 0)
306 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
307 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
311 newtEntrySetFlags(addressentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
312 newtEntrySetFlags(netmaskentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
314 if (strcmp(type
, "DHCP") == 0)
316 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
317 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_RESET
);
321 newtEntrySetFlags(dhcphostnameentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
322 newtEntrySetFlags(dhcpforcemtuentry
, NEWT_FLAG_DISABLED
, NEWT_FLAGS_SET
);
325 newtDrawForm(networkform
);
328 int interfacecheck(struct keyvalue
*kv
, char *colour
)
330 char temp
[STRING_SIZE
];
331 char colourfields
[NETCHANGE_TOTAL
][STRING_SIZE
];
334 sprintf(colourfields
[ADDRESS
], "%s_ADDRESS", colour
);
335 sprintf(colourfields
[NETADDRESS
], "%s_NETADDRESS", colour
);
336 sprintf(colourfields
[NETMASK
], "%s_NETMASK", colour
);
338 for (c
= 0; c
< 3; c
++)
340 strcpy(temp
, ""); findkey(kv
, colourfields
[c
], temp
);
341 if (!(strlen(temp
))) return 0;
346 /* Funky routine for loading all drivers (cept those are already loaded.). */
347 int probecards(char *driver
, char *driveroptions
)
352 int get_knic(int card
) //returns "0" for zero cards or error and "1" card is found.
354 struct keyvalue
*kv
= initkeyvalues();
355 char temp
[STRING_SIZE
], searchstr
[STRING_SIZE
];
358 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
361 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
365 sprintf(searchstr
, "%s_MACADDR", ucolourcard
[card
]);
366 strcpy(temp
, ""); findkey(kv
, searchstr
, temp
);
368 strcpy(knics
[ card
].macaddr
, temp
);
369 strcpy(knics
[ card
].colour
, ucolourcard
[card
]);
371 sprintf(searchstr
, "%s_DESCRIPTION", ucolourcard
[card
]);
372 findkey(kv
, searchstr
, temp
);
373 strcpy(knics
[ card
].description
, temp
);
375 sprintf(searchstr
, "%s_DRIVER", ucolourcard
[card
]);
376 findkey(kv
, searchstr
, temp
);
377 strcpy(knics
[ card
].driver
, temp
);
380 strcpy(knics
[ card
].description
, ctr
[TR_UNSET
]);
391 found
+= get_knic(_GREEN_CARD_
);
392 found
+= get_knic(_RED_CARD_
);
393 found
+= get_knic(_ORANGE_CARD_
);
394 found
+= get_knic(_BLUE_CARD_
);
399 int fmt_exists(const char *fname
) { /* Check if it is any file or directory */
401 if (stat(fname
, &st
) == -1) return 0;
405 int is_interface_up(char *card
) { /* Check if the interface is UP */
406 char temp
[STRING_SIZE
];
408 sprintf(temp
,"ip link show dev %s | grep -q UP", card
);
409 if (mysystem(temp
)) return 0; else return 1;
412 int rename_device(char *old_name
, char *new_name
) {
413 char temp
[STRING_SIZE
];
415 sprintf(temp
,SYSDIR
"/%s", old_name
);
416 if (!(fmt_exists(temp
))) {
417 fprintf(flog
,"Device not found: %s\n",old_name
);
420 sprintf(temp
,"/sbin/ip link set dev %s name %s",old_name
,new_name
);
426 char g_temp
[STRING_SIZE
]="";
427 char* readmac(char *card
) {
429 char temp
[STRING_SIZE
], mac
[20];
431 sprintf(temp
,"/sys/class/net/%s/address",card
);
432 if( (fp
= fopen(temp
, "r")) == NULL
) {
433 fprintf(flog
,"Couldn't open: %s\n",temp
);
443 char* find_nic4mac(char *findmac
) {
445 struct dirent
*dirzeiger
;
446 char temp
[STRING_SIZE
], temp2
[STRING_SIZE
];
448 if((dir
=opendir(SYSDIR
)) == NULL
) {
449 fprintf(flog
,"Fehler bei opendir (find_name4nic) ...\n");
454 while((dirzeiger
=readdir(dir
)) != NULL
) {
455 if(*((*dirzeiger
).d_name
) != '.' & strcmp(((*dirzeiger
).d_name
), "lo") != 0) {
456 sprintf(temp2
, "%s", readmac((*dirzeiger
).d_name
) );
457 if (strcmp(findmac
, temp2
) == 0) {
458 sprintf(temp
,"%s", (*dirzeiger
).d_name
);
464 if(closedir(dir
) == -1) fprintf(flog
,"Fehler beim schliessen von %s\n", SYSDIR
);
465 strcpy(g_temp
, temp
);
469 int nic_shutdown(char *nic
) {
470 char temp
[STRING_SIZE
];
472 sprintf(temp
,"ip link set %s down", nic
);
476 int nic_startup(char *nic
) {
477 char temp
[STRING_SIZE
];
479 sprintf(temp
,"ip link set %s up", nic
);
484 int rename_nics(void) {
486 int fnics
= scan_network_cards();
487 char nic2find
[STRING_SIZE
], temp
[STRING_SIZE
];
490 if (strcmp(knics
[i
].macaddr
, ""))
491 for(j
=0; j
<fnics
; j
++)
492 if(strcmp(knics
[i
].macaddr
, nics
[j
].macaddr
) == 0) {
493 sprintf(nic2find
,"%s0",lcolourcard
[i
]);
494 if(strcmp(nic2find
, nics
[j
].nic
)) {
495 if(is_interface_up(nics
[j
].nic
)) {
496 nic_shutdown(nics
[j
].nic
);
498 sprintf(temp
,SYSDIR
"/%s", nic2find
);
499 if(fmt_exists(temp
)) {
500 for(k
=0; k
<fnics
; k
++)
501 if (strcmp(nics
[k
].nic
, nic2find
) == 0 ) {
502 if(is_interface_up(nics
[k
].nic
)) {
503 nic_shutdown(nics
[k
].nic
);
505 sprintf(temp
,"dummy%i",k
);
506 if (rename_device(nics
[k
].nic
, temp
)) strcpy(nics
[k
].nic
, temp
);
509 if (rename_device(nics
[j
].nic
, nic2find
)) strcpy(nics
[j
].nic
, nic2find
);
514 int create_udev(void)
516 #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
520 if ( (fp
= fopen(UDEV_NET_CONF
, "w")) == NULL
) {
521 fprintf(stderr
,"Couldn't open" UDEV_NET_CONF
);
525 for (i
= 0 ; i
< 4 ; i
++)
527 if (strcmp(knics
[i
].macaddr
, "")) {
528 fprintf(fp
,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{type}==\"1\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics
[i
].macaddr
, lcolourcard
[i
], knics
[i
].description
);
535 int write_configs_netudev(int card
, int colour
)
537 char commandstring
[STRING_SIZE
];
538 struct keyvalue
*kv
= initkeyvalues();
539 char temp1
[STRING_SIZE
], temp2
[STRING_SIZE
], temp3
[STRING_SIZE
];
540 char ucolour
[STRING_SIZE
];
542 sprintf(ucolour
, ucolourcard
[colour
]);
543 strcpy(knics
[colour
].driver
, nics
[card
].driver
);
544 strcpy(knics
[colour
].description
, nics
[card
].description
);
545 strcpy(knics
[colour
].macaddr
, nics
[card
].macaddr
);
547 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
550 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
554 sprintf(temp1
, "%s_DEV", ucolour
);
555 sprintf(temp2
, "%s_MACADDR", ucolour
);
556 sprintf(temp3
, "%s0", lcolourcard
[colour
]);
557 replacekeyvalue(kv
, temp1
, temp3
);
558 replacekeyvalue(kv
, temp2
, nics
[card
].macaddr
);
559 sprintf(temp1
, "%s_DESCRIPTION", ucolour
);
560 replacekeyvalue(kv
, temp1
, nics
[card
].description
);
561 sprintf(temp1
, "%s_DRIVER", ucolour
);
562 replacekeyvalue(kv
, temp1
, nics
[card
].driver
);
564 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
570 int scan_network_cards(void)
573 char driver
[STRING_SIZE
], description
[STRING_SIZE
], macaddr
[STRING_SIZE
], temp_line
[STRING_SIZE
];
575 const char _driver
[]="driver: ";
576 const char _desc
[]="desc: ";
577 const char _network_hwaddr
[]="network.hwaddr: ";
579 if (!(scanned_nics_read_done
))
581 mysystem("/bin/probenic.sh");
582 if( (fp
= fopen(SCANNED_NICS
, "r")) == NULL
)
584 fprintf(stderr
,"Couldn't open "SCANNED_NICS
);
587 while (fgets(temp_line
, STRING_SIZE
, fp
) != NULL
)
589 temp_line
[strlen(temp_line
) -1] = 0;
590 if ( strncmp(temp_line
, _driver
, strlen(_driver
)) == 0 ) sprintf(nics
[count
].driver
, "%s", temp_line
+strlen(_driver
));
591 if ( strncmp(temp_line
, _desc
, strlen(_desc
)) == 0 ) sprintf(nics
[count
].description
, "%s", temp_line
+strlen(_desc
));
592 if ( strncmp(temp_line
, _network_hwaddr
, strlen(_network_hwaddr
)) == 0 ) sprintf(nics
[count
].macaddr
, "%s", temp_line
+strlen(_network_hwaddr
));
593 if (strlen(nics
[count
].macaddr
) > 15 ) {
594 sprintf(nics
[count
].nic
, "%s", find_nic4mac(nics
[count
].macaddr
));
599 scanned_nics_read_done
= count
;
600 } else fprintf(flog
,"Scan Networkcards does read.\n");
601 return scanned_nics_read_done
;
606 int nicmenu(int colour
)
608 int rc
, choise
= 0, count
= 0, kcount
= 0, mcount
= 0, i
, j
, nic_in_use
;
609 int found_NIC_as_Card
[4];
610 char message
[STRING_SIZE
];
612 char cMenuInhalt
[STRING_SIZE
];
613 char MenuInhalt
[20][180];
614 char *pMenuInhalt
[20];
616 while (strcmp(nics
[count
].macaddr
, "")) count
++; // 2 find how many nics in system
617 for ( i
=0 ; i
<4;i
++) if (strcmp(knics
[i
].macaddr
, "")) kcount
++; // loop to find all knowing nics
619 // If new nics are found...
620 if (count
> kcount
) {
621 for (i
=0 ; i
< count
; i
++)
624 for (j
=0 ; j
<= kcount
; j
++) {
625 if (strcmp(nics
[ i
].macaddr
, knics
[ j
].macaddr
) == 0 ) {
631 if ( strlen(nics
[i
].description
) < 55 )
632 sprintf(MenuInhalt
[mcount
], "%.*s", strlen(nics
[i
].description
)-2, nics
[i
].description
+1);
634 sprintf(cMenuInhalt
, "%.50s", nics
[i
].description
+ 1);
635 sprintf(MenuInhalt
[mcount
], cMenuInhalt
);
636 strcat (MenuInhalt
[mcount
], "...");
639 while ( strlen(MenuInhalt
[mcount
]) < 53) strcat(MenuInhalt
[mcount
], " "); // Fill with space.
641 strcat(MenuInhalt
[mcount
], " (");
642 strcat(MenuInhalt
[mcount
], nics
[i
].macaddr
);
643 strcat(MenuInhalt
[mcount
], ")");
644 pMenuInhalt
[mcount
] = MenuInhalt
[mcount
];
645 found_NIC_as_Card
[mcount
]=i
;
650 pMenuInhalt
[mcount
] = NULL
;
652 sprintf(message
, ctr
[TR_CHOOSE_NETCARD
], ucolourcard
[colour
]);
653 rc
= newtWinMenu( ctr
[TR_NETCARDMENU2
], message
, 50, 5, 5, 6, pMenuInhalt
, &choise
, ctr
[TR_OK
], ctr
[TR_SELECT
], ctr
[TR_CANCEL
], NULL
);
655 if ( rc
== 0 || rc
== 1) {
656 write_configs_netudev(found_NIC_as_Card
[choise
], colour
);
660 // We have to add here that you can manually add a device
661 errorbox( ctr
[TR_ERROR_INTERFACES
]);
666 int clear_card_entry(int card
)
668 struct keyvalue
*kv
= initkeyvalues();
669 char temp
[STRING_SIZE
];
671 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
674 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
678 strcpy(knics
[card
].driver
, "");
679 strcpy(knics
[card
].description
, ctr
[TR_UNSET
]);
680 strcpy(knics
[card
].macaddr
, "");
681 strcpy(knics
[card
].colour
, "");
682 sprintf(temp
, "%s_DRIVER", ucolourcard
[card
]);
683 replacekeyvalue(kv
, temp
, "");
684 sprintf(temp
, "%s_DEV", ucolourcard
[card
]);
685 replacekeyvalue(kv
, temp
, "");
686 sprintf(temp
, "%s_MACADDR", ucolourcard
[card
]);
687 replacekeyvalue(kv
, temp
, "");
688 sprintf(temp
, "%s_DESCRIPTION", ucolourcard
[card
]);
689 replacekeyvalue(kv
, temp
, "");
691 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
697 int ask_clear_card_entry(int card
)
699 char message
[STRING_SIZE
];
702 sprintf(message
, ctr
[TR_REMOVE_CARD
], ucolourcard
[card
]);
703 rc
= newtWinChoice(ctr
[TR_WARNING
], ctr
[TR_OK
], ctr
[TR_CANCEL
], message
);
705 if ( rc
= 0 || rc
== 1) {
706 clear_card_entry(card
);
712 /* Manual entry for gurus. */
713 int manualdriver(char *driver
, char *driveroptions
)
715 char *values
[] = { NULL
, NULL
}; /* pointers for the values. */
716 struct newtWinEntry entries
[] =
717 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
719 char commandstring
[STRING_SIZE
];
723 strcpy(driveroptions
, "");
725 rc
= newtWinEntries(ctr
[TR_SELECT_NETWORK_DRIVER
],
726 ctr
[TR_MODULE_PARAMETERS
], 50, 5, 5, 40, entries
,
727 ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
728 if (rc
== 0 || rc
== 1)
730 if (strlen(values
[0]))
732 sprintf(commandstring
, "/sbin/modprobe %s", values
[0]);
733 if (runcommandwithstatus(commandstring
, ctr
[TR_LOADING_MODULE
]) == 0)
735 if ((driverend
= strchr(values
[0], ' ')))
738 strcpy(driver
, values
[0]);
739 strcpy(driveroptions
, driverend
+ 1);
743 strcpy(driver
, values
[0]);
744 strcpy(driveroptions
, "");
748 errorbox(ctr
[TR_UNABLE_TO_LOAD_DRIVER_MODULE
]);
751 errorbox(ctr
[TR_MODULE_NAME_CANNOT_BE_BLANK
]);