From 5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Tue, 12 Dec 2000 22:29:02 +0000 Subject: network devices detection and insmod on user input --- mdk-stage1/network.c | 40 +++++++++++++++++++++++++++++- mdk-stage1/probing.c | 59 ++++++++++++++++++++++++++++++++++++++++++++- mdk-stage1/probing.h | 1 + mdk-stage1/stdio-frontend.c | 7 ------ 4 files changed, 98 insertions(+), 9 deletions(-) (limited to 'mdk-stage1') diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 021a8d26a..de0e0070e 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -30,9 +30,47 @@ #include "network.h" +static char * interface_select(void) +{ + char ** interfaces, ** ptr; + char * choice; + int i, count = 0; + enum return_type results; + + interfaces = get_net_devices(); + + ptr = interfaces; + while (ptr && *ptr) { + count++; + ptr++; + } + + if (count == 0) { + error_message("No NET device found."); + i = ask_insmod(NETWORK_DEVICES); + if (i == RETURN_BACK) + return NULL; + return interface_select(); + } + + if (count == 1) + return *interfaces; + + results = ask_from_list("Please choose the NET device to use for the installation.", interfaces, &choice); + + if (results != RETURN_OK) + return NULL; + + return choice; +} + enum return_type nfs_prepare(void) { - pci_probing(NETWORK_DEVICES); + char * iface = interface_select(); + + if (iface == NULL) + return RETURN_BACK; + return RETURN_ERROR; } diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index b41500314..c61552f07 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -25,6 +25,7 @@ * (1) PCI devices * (2) IDE media * (3) SCSI media + * (4) ETH devices */ @@ -35,6 +36,10 @@ #include #include #include +#include +#include +#include +#include #include "log.h" #include "frontend.h" #include "modules.h" @@ -47,7 +52,7 @@ void pci_probing(enum driver_type type) { if (IS_EXPERT) ask_insmod(type); - else { + else { /* do it automatically */ char * mytype; FILE * f; @@ -352,3 +357,55 @@ void get_medias(enum media_type media, char *** names, char *** models) *models = (char **) malloc(sizeof(char *) * count); memcpy(*models, tmp_models, sizeof(char *) * count); } + + +int net_device_available(char * device) { + struct ifreq req; + int s; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + close(s); + log_perror(device); + return 0; + } + strcpy(req.ifr_name, device); + if (ioctl(s, SIOCGIFFLAGS, &req)) { + /* if we can't get the flags, the networking device isn't available */ + close(s); + return 0; + } + return 1; +} + + +char ** get_net_devices(void) +{ + char * devices[] = { + "eth0", "eth1", "eth2", "eth3", + "tr0", + "plip0", "plip1", "plip2", + "fddi0", + NULL + }; + char ** ptr = devices; + char * tmp[50]; + char ** results; + int i = 0; + + pci_probing(NETWORK_DEVICES); + + while (ptr && *ptr) { + if (net_device_available(*ptr)) { + log_message("NET: interface %s available", *ptr); + tmp[i++] = strdup(*ptr); + } + ptr++; + } + tmp[i++] = NULL; + + results = (char **) malloc(sizeof(char *) * i); + memcpy(results, tmp, sizeof(char *) * i); + + return results; +} diff --git a/mdk-stage1/probing.h b/mdk-stage1/probing.h index 4d29eabca..42ea2f986 100644 --- a/mdk-stage1/probing.h +++ b/mdk-stage1/probing.h @@ -40,6 +40,7 @@ enum driver_type { SCSI_ADAPTERS, NETWORK_DEVICES }; void pci_probing(enum driver_type type); void get_medias(enum media_type media, char *** names, char *** models); +char ** get_net_devices(void); #endif diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c index ec448224a..27aa3782e 100644 --- a/mdk-stage1/stdio-frontend.c +++ b/mdk-stage1/stdio-frontend.c @@ -12,13 +12,6 @@ * */ -/* - * Portions from Erik Troan (ewt@redhat.com) - * - * Copyright 1996 Red Hat Software - * - */ - /* * Each different frontend must implement all functions defined in frontend.h -- cgit v1.2.1