
6 changed files with 384 additions and 96 deletions
@ -1,13 +1,9 @@ |
|||
* menutest : check for existance and size, of conf files (any other checks?) |
|||
* search for network interfaces and allow the user to choose which one they want to configure |
|||
* put in checks so the user can't enter data that is clearly invalid (perhaps this will be done through debconf. |
|||
* dhcp: either another module, or in here |
|||
* fall back to safe defaults if the user doesn't enter a particular value (ex. gateway) |
|||
* create config dirs if they don't exist |
|||
* do other sorts of network configurations (pcmcia) |
|||
* inderstand the target_path() thing, and do it properly |
|||
* what do we do differently if it is a CD filesystem? |
|||
* make sure the gateway (if any) is reachable (i.e. is on the system's network) |
|||
* clear any DNS entries the user doesn't enter |
|||
* fix the strtok() DNS clumsyness |
|||
* decide what numbers you will actually present the user with for confirmation (you have overkill now) |
|||
* fix the note about what the user should do if we don't find any network interfaces. Since I don't now know what the flow of the installer is going to be I can't suggest what they should do, I've got the test in there from the old installer now. |
|||
* currently we get an internal error if the user has lots of network interfaces, find a better way of handling that. |
|||
|
@ -0,0 +1,170 @@ |
|||
/*
|
|||
* file: util.c |
|||
* These functions were taken mostly untouched from dbootstrap |
|||
* |
|||
* */ |
|||
|
|||
#include <unistd.h> |
|||
#include <ctype.h> |
|||
#include <string.h> |
|||
#include <net/if.h> |
|||
#include <sys/types.h> |
|||
#include <sys/socket.h> |
|||
#include <sys/ioctl.h> |
|||
#include <stdio.h> |
|||
|
|||
#include "util.h" |
|||
|
|||
int |
|||
is_interface_up (char *inter) |
|||
{ |
|||
struct ifreq ifr; |
|||
int sfd = -1, ret = -1; |
|||
|
|||
if ((sfd = socket (AF_INET, SOCK_DGRAM, 0)) == -1) |
|||
goto int_up_done; |
|||
|
|||
strncpy (ifr.ifr_name, inter, sizeof (ifr.ifr_name)); |
|||
|
|||
if (ioctl (sfd, SIOCGIFFLAGS, &ifr) < 0) |
|||
goto int_up_done; |
|||
|
|||
ret = (ifr.ifr_flags & IFF_UP) ? 1 : 0; |
|||
|
|||
int_up_done: |
|||
if (sfd != -1) |
|||
close (sfd); |
|||
return ret; |
|||
} |
|||
|
|||
static FILE *ifs = NULL; |
|||
static char ibuf[512]; |
|||
|
|||
void |
|||
getif_start (void) |
|||
{ |
|||
if (ifs != NULL) |
|||
{ |
|||
fclose (ifs); |
|||
ifs = NULL; |
|||
} |
|||
if ((ifs = fopen ("/proc/net/dev", "r")) != NULL) |
|||
{ |
|||
fgets (ibuf, sizeof (ibuf), ifs); /* eat header */ |
|||
fgets (ibuf, sizeof (ibuf), ifs); /* ditto */ |
|||
} |
|||
return; |
|||
} |
|||
|
|||
void |
|||
getif_end (void) |
|||
{ |
|||
if (ifs != NULL) |
|||
{ |
|||
fclose (ifs); |
|||
ifs = NULL; |
|||
} |
|||
return; |
|||
} |
|||
|
|||
char * |
|||
getif (int all) |
|||
{ |
|||
char rbuf[512]; |
|||
if (ifs == NULL) |
|||
return NULL; |
|||
|
|||
if (fgets (rbuf, sizeof (rbuf), ifs) != NULL) |
|||
{ |
|||
get_name (ibuf, rbuf); |
|||
if (!strcmp (ibuf, "lo")) /* ignore the loopback */ |
|||
return getif (all); /* seriously doubt there is an infinite number of lo devices */ |
|||
if (all || is_interface_up (ibuf) == 1) |
|||
return ibuf; |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
void |
|||
get_name (char *name, char *p) |
|||
{ |
|||
while (isspace (*p)) |
|||
p++; |
|||
while (*p) |
|||
{ |
|||
if (isspace (*p)) |
|||
break; |
|||
if (*p == ':') |
|||
{ /* could be an alias */ |
|||
char *dot = p, *dotname = name; |
|||
*name++ = *p++; |
|||
while (isdigit (*p)) |
|||
*name++ = *p++; |
|||
if (*p != ':') |
|||
{ /* it wasn't, backup */ |
|||
p = dot; |
|||
name = dotname; |
|||
} |
|||
if (*p == '\0') |
|||
return; |
|||
p++; |
|||
break; |
|||
} |
|||
*name++ = *p++; |
|||
} |
|||
*name++ = '\0'; |
|||
return; |
|||
} |
|||
|
|||
|
|||
|
|||
/*
|
|||
* Get a description for an interface (i.e. "Ethernet" for ethX). |
|||
*/ |
|||
char * |
|||
get_ifdsc (const char *ifp) |
|||
{ |
|||
int i; |
|||
struct if_alist_struct |
|||
{ |
|||
char *interface; |
|||
char *description; |
|||
} |
|||
interface_alist[] = |
|||
{ |
|||
/*
|
|||
* A _("string") is an element of a char *[], and the linker will |
|||
* know where to find the elements. This works with `pointerize'; |
|||
* perhaps that's different with `gettext'... though if it expands |
|||
* to a function call, this initializer should still work fine. |
|||
* Also see the 1.66 version of choose_cdrom(), which uses the |
|||
* similar technique. If it works there, it will work here. |
|||
*/ |
|||
{ |
|||
"eth", "Ethernet or Fast Ethernet"} |
|||
, |
|||
{ |
|||
"pcmcia", "PC-Card (PCMCIA) Ethernet or Token Ring"} |
|||
, |
|||
{ |
|||
"tr", "Token Ring"} |
|||
, |
|||
{ |
|||
"arc", "Arcnet"} |
|||
, |
|||
{ |
|||
"slip", "Serial-line IP"} |
|||
, |
|||
{ |
|||
"plip", "Parallel-line IP"} |
|||
, |
|||
{ |
|||
NULL, NULL} |
|||
}; |
|||
|
|||
for (i = 0; interface_alist[i].interface != NULL; i++) |
|||
if (!strncmp (ifp, interface_alist[i].interface, |
|||
strlen (interface_alist[i].interface))) |
|||
return interface_alist[i].description; |
|||
return NULL; |
|||
} |
@ -0,0 +1,39 @@ |
|||
#ifndef __UTIL_H |
|||
#define __UTIL_H |
|||
#define MAXLINE 1024 |
|||
|
|||
|
|||
|
|||
/*
|
|||
* Get a description for an interface (i.e. "Ethernet" for ethX). |
|||
*/ |
|||
extern char *get_ifdsc (const char *ifp); |
|||
|
|||
|
|||
/* Checks to see if any network interfaces are active (excepting the
|
|||
* loopback interface "lo" - Returns the number of active interfaces. If |
|||
* all is non-zero, all interfaces are counted, even if not up */ |
|||
int is_network_up (int all); |
|||
|
|||
/* Checks to see if the named interface, "inter", is up - Returns 1 if it
|
|||
* is, 0 if it is down. -1 is returned if the interface does not exist. */ |
|||
int is_interface_up (char *inter); |
|||
|
|||
/* Takes the buffer "p" and reads the interface name from it. "p" must be
|
|||
* a full line read in from /proc/net/dev. The interface name is places |
|||
* into the "name" buffer (which must already be allocated) */ |
|||
void get_name (char *name, char *p); |
|||
|
|||
/* Get listing of interfaces on the system. getif_start() must be called
|
|||
* first in order to initialize the setup. After which, each successive |
|||
* call get getif() will return a pointer to the next interface, ending |
|||
* with NULL, when no more interfaces are available. If you call getif and |
|||
* all is non-zero, it will return all interfaces, even ones that are not |
|||
* active. Finally when done, call getif_end(). |
|||
*/ |
|||
void getif_start (void); |
|||
char *getif (int all); |
|||
void getif_end (void); |
|||
|
|||
|
|||
#endif /* __UTIL_H */ |
Loading…
Reference in new issue