]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/install+setup/install/nic.c
Kleiner netter neuer Versuch.
[people/pmueller/ipfire-2.x.git] / src / install+setup / install / nic.c
CommitLineData
d6aaa55d
MT
1/* SmoothWall install program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Contains stuff related to firing up the network card, including a crude
8 * autodector.
9 *
d6aaa55d
MT
10 */
11
12#include "install.h"
13
14#include <sys/socket.h>
15#include <netinet/in.h>
16#include <arpa/inet.h>
17
18extern FILE *flog;
19extern char *mylog;
10bc6f06 20
d6aaa55d 21extern char **ctr;
10bc6f06 22
d6aaa55d
MT
23extern struct nic nics[];
24
25int networkmenu(struct keyvalue *ethernetkv)
26{
27 int rc;
28 char driver[STRING_SIZE] = "";
29 char driveroptions[STRING_SIZE] = "";
10bc6f06 30 struct keyvalue *kv = initkeyvalues();
d6aaa55d
MT
31 int result = 0;
32 char commandstring[STRING_SIZE];
33 char address[STRING_SIZE], netmask[STRING_SIZE];
34 int done;
02c629b9
MT
35 FILE *handle;
36 char line[STRING_SIZE];
d6aaa55d
MT
37 char description[1000];
38 char message[1000];
39 char title[STRING_SIZE];
40 done = 0;
41
42 while (!done)
43 {
44 rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE],
45 ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]);
46
47 if (rc == 0 || rc == 1)
48 {
02c629b9
MT
49 sprintf(commandstring, "/bin/probenic.sh 1");
50 sprintf(message, ctr[TR_PROBING_FOR_NICS]);
51 runcommandwithstatus(commandstring, message);
52
53 if ((handle = fopen("/nicdriver", "r")))
d6aaa55d 54 {
02c629b9
MT
55 char *driver;
56 fgets(line, STRING_SIZE-1, handle);
57 fclose(handle);
58 line[strlen(line) - 1] = 0;
59 driver = strtok(line, ".");
60 fprintf(flog, "Detected NIC driver: %s\n",driver);
61 if (strlen(driver) > 1) {
62 strcpy(driveroptions, "");
63 findnicdescription(driver, description);
64 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
65 sprintf(message, ctr[TR_FOUND_NIC], NAME, description);
66 newtWinMessage(title, ctr[TR_OK], message);
67 } else {
68 errorbox(ctr[TR_PROBE_FAILED]);
69 }
70 }
71 }
d6aaa55d
MT
72 else if (rc == 2)
73 choosecards(driver, driveroptions);
74 else
d6aaa55d
MT
75 done = 1;
76 }
d6aaa55d
MT
77
78 /* Default is a GREEN nic only. */
79 /* Smoothie is not untarred yet, so we have to delay actually writing the
80 * settings till later. */
81 replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
82 replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
83 replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
84 replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
85 replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
86
87 if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
88 goto EXIT;
89
90 strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
91 strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);
92
93 snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up",
94 address, netmask);
95 if (mysystem(commandstring))
96 {
97 errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
98 goto EXIT;
99 }
100
101 result = 1;
102
103EXIT:
10bc6f06 104 freekeyvalues(kv);
d6aaa55d
MT
105
106 return result;
107}
108