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/probing.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'mdk-stage1/probing.c') 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; +} -- cgit v1.2.1