summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/probing.c
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-12-12 22:29:02 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-12-12 22:29:02 +0000
commit5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae (patch)
tree949b3db0333eb77755db60fbd212f1062a3ca28d /mdk-stage1/probing.c
parentb8a6765874054e3f3966896a8763f7352d9ff8f1 (diff)
downloaddrakx-5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae.tar
drakx-5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae.tar.gz
drakx-5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae.tar.bz2
drakx-5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae.tar.xz
drakx-5f740e74b9e2f27b2f3d500c75d9b4986a0a53ae.zip
network devices detection and insmod on user input
Diffstat (limited to 'mdk-stage1/probing.c')
-rw-r--r--mdk-stage1/probing.c59
1 files changed, 58 insertions, 1 deletions
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#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;
+}