1995-05-01 21:56:32 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1996-06-13 17:07:41 +00:00
|
|
|
* $Id: devices.c,v 1.46 1996/06/12 17:09:31 jkh Exp $
|
1995-05-01 21:56:32 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-05-30 08:29:07 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
1995-05-01 21:56:32 +00:00
|
|
|
* point in the file.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1995-05-11 06:47:46 +00:00
|
|
|
#include <sys/fcntl.h>
|
1995-05-16 02:53:31 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-12-11 16:32:33 +00:00
|
|
|
#include <sys/errno.h>
|
1995-05-16 02:53:31 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
static Device *Devices[DEV_MAX];
|
|
|
|
static int numDevs;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
DeviceType type;
|
|
|
|
char *name;
|
|
|
|
char *description;
|
|
|
|
} device_names[] = {
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "cd0a", "SCSI CDROM drive" },
|
|
|
|
{ DEVICE_TYPE_CDROM, "mcd0a", "Mitsumi (old model) CDROM drive" },
|
|
|
|
{ DEVICE_TYPE_CDROM, "scd0a", "Sony CDROM drive - CDU31/33A type", },
|
|
|
|
{ DEVICE_TYPE_CDROM, "matcd0a", "Matsushita CDROM ('sound blaster' type)" },
|
1995-12-07 10:34:59 +00:00
|
|
|
{ DEVICE_TYPE_CDROM, "wcd0c", "ATAPI IDE CDROM" },
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_TAPE, "rst0", "SCSI tape drive" },
|
1995-12-07 10:34:59 +00:00
|
|
|
{ DEVICE_TYPE_TAPE, "rft0", "Floppy tape drive (QIC-02)" },
|
|
|
|
{ DEVICE_TYPE_TAPE, "rwt0", "Wangtek tape drive" },
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_DISK, "sd", "SCSI disk device" },
|
|
|
|
{ DEVICE_TYPE_DISK, "wd", "IDE/ESDI/MFM/ST506 disk device" },
|
1995-06-11 19:33:05 +00:00
|
|
|
{ DEVICE_TYPE_FLOPPY, "fd0", "floppy drive unit A" },
|
|
|
|
{ DEVICE_TYPE_FLOPPY, "fd1", "floppy drive unit B" },
|
1996-06-13 17:07:41 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "cuaa0", "%s on serial port 0 (COM1)" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "cuaa1", "%s on serial port 1 (COM2)" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "cuaa2", "%s on serial port 2 (COM3)" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "cuaa3", "%s on serial port 3 (COM4)" },
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "lp0", "Parallel Port IP (PLIP) using laplink cable" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "lo", "Loop-back (local) network interface" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "sl", "Serial-line IP (SLIP) interface" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ppp", "Point-to-Point Protocol (PPP) interface" },
|
1995-06-11 19:33:05 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "de", "DEC DE435 PCI NIC or other DC21040-AA based card" },
|
1996-03-18 15:28:10 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "fxp", "Intel EtherExpress Pro/100B PCI Fast Ethernet card" },
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "ed", "WD/SMC 80xx; Novell NE1000/2000; 3Com 3C503 cards" },
|
1995-05-24 17:49:20 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "ep", "3Com 3C509 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "el", "3Com 3C501 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "fe", "Fujitsu MB86960A/MB86965A ethernet card" },
|
1995-05-24 09:00:58 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" },
|
1995-05-24 17:49:20 +00:00
|
|
|
{ DEVICE_TYPE_NETWORK, "ix", "Intel Etherexpress ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 or 3 ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "ze", "IBM/National Semiconductor PCMCIA ethernet card" },
|
|
|
|
{ DEVICE_TYPE_NETWORK, "zp", "3Com Etherlink III PCMCIA ethernet card" },
|
1995-05-16 02:53:31 +00:00
|
|
|
{ NULL },
|
1995-05-08 21:39:40 +00:00
|
|
|
};
|
|
|
|
|
1995-05-20 10:33:14 +00:00
|
|
|
Device *
|
1995-05-16 02:53:31 +00:00
|
|
|
new_device(char *name)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
Device *dev;
|
|
|
|
|
|
|
|
dev = safe_malloc(sizeof(Device));
|
1995-06-11 19:33:05 +00:00
|
|
|
bzero(dev, sizeof(Device));
|
1995-05-16 02:53:31 +00:00
|
|
|
if (name)
|
|
|
|
strcpy(dev->name, name);
|
|
|
|
return dev;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
/* Stubs for unimplemented strategy routines */
|
|
|
|
Boolean
|
|
|
|
dummyInit(Device *dev)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-03-02 07:31:58 +00:00
|
|
|
dummyGet(Device *dev, char *dist, Boolean probe)
|
1995-06-11 19:33:05 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean
|
|
|
|
dummyClose(Device *dev, int fd)
|
|
|
|
{
|
|
|
|
if (!close(fd))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dummyShutdown(Device *dev)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
static int
|
1995-05-20 00:13:14 +00:00
|
|
|
deviceTry(char *name, char *try)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1995-05-16 11:37:27 +00:00
|
|
|
int fd;
|
1995-05-16 02:53:31 +00:00
|
|
|
|
|
|
|
snprintf(try, FILENAME_MAX, "/dev/%s", name);
|
|
|
|
fd = open(try, O_RDWR);
|
|
|
|
if (fd > 0)
|
|
|
|
return fd;
|
1995-12-11 16:32:33 +00:00
|
|
|
else if (errno == EACCES)
|
|
|
|
return 0;
|
1995-05-16 02:53:31 +00:00
|
|
|
snprintf(try, FILENAME_MAX, "/mnt/dev/%s", name);
|
1995-05-20 16:22:42 +00:00
|
|
|
fd = open(try, O_RDWR);
|
1995-05-16 02:53:31 +00:00
|
|
|
return fd;
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
|
1995-05-20 10:33:14 +00:00
|
|
|
/* Register a new device in the devices array */
|
|
|
|
Device *
|
|
|
|
deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
|
1995-12-07 10:34:59 +00:00
|
|
|
Boolean (*init)(Device *), int (*get)(Device *, char *, Boolean),
|
1995-06-11 19:33:05 +00:00
|
|
|
Boolean (*close)(Device *, int), void (*shutdown)(Device *), void *private)
|
1995-05-20 10:33:14 +00:00
|
|
|
{
|
1996-06-13 17:07:41 +00:00
|
|
|
Device *newdev = NULL;
|
1995-05-20 10:33:14 +00:00
|
|
|
|
|
|
|
if (numDevs == DEV_MAX)
|
|
|
|
msgFatal("Too many devices found!");
|
1996-06-12 17:09:34 +00:00
|
|
|
else {
|
|
|
|
newdev = new_device(name);
|
|
|
|
newdev->description = desc;
|
|
|
|
newdev->devname = devname;
|
|
|
|
newdev->type = type;
|
|
|
|
newdev->enabled = enabled;
|
|
|
|
newdev->init = init ? init : dummyInit;
|
|
|
|
newdev->get = get ? get : dummyGet;
|
|
|
|
newdev->close = close ? close : dummyClose;
|
|
|
|
newdev->shutdown = shutdown ? shutdown : dummyShutdown;
|
|
|
|
newdev->private = private;
|
|
|
|
Devices[numDevs] = newdev;
|
|
|
|
Devices[++numDevs] = NULL;
|
|
|
|
}
|
1995-05-20 10:33:14 +00:00
|
|
|
return newdev;
|
|
|
|
}
|
1995-05-24 09:00:58 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/* Get all device information for devices we have attached */
|
|
|
|
void
|
1995-05-16 11:37:27 +00:00
|
|
|
deviceGetAll(void)
|
1995-05-01 21:56:32 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
int i, fd, s;
|
|
|
|
struct ifconf ifc;
|
|
|
|
struct ifreq *ifptr, *end;
|
1995-05-16 11:37:27 +00:00
|
|
|
int ifflags;
|
|
|
|
char buffer[INTERFACE_MAX * sizeof(struct ifreq)];
|
|
|
|
char **names;
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 11:37:27 +00:00
|
|
|
/* Try and get the disks first */
|
|
|
|
if ((names = Disk_Names()) != NULL) {
|
|
|
|
int i;
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 11:37:27 +00:00
|
|
|
for (i = 0; names[i]; i++) {
|
1995-05-29 11:01:42 +00:00
|
|
|
Chunk *c1;
|
1995-05-20 10:33:14 +00:00
|
|
|
Disk *d;
|
|
|
|
|
|
|
|
d = Open_Disk(names[i]);
|
|
|
|
if (!d)
|
|
|
|
msgFatal("Unable to open disk %s", names[i]);
|
|
|
|
|
1995-05-29 11:01:42 +00:00
|
|
|
(void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, NULL, d);
|
1995-05-16 11:37:27 +00:00
|
|
|
msgDebug("Found a device of type disk named: %s\n", names[i]);
|
1995-05-29 11:01:42 +00:00
|
|
|
|
|
|
|
/* Look for existing DOS partitions to register */
|
|
|
|
for (c1 = d->chunks->part; c1; c1 = c1->next) {
|
1996-03-18 15:28:10 +00:00
|
|
|
if (c1->type == fat || c1->type == extended) {
|
1995-05-29 11:01:42 +00:00
|
|
|
Device *dev;
|
1995-06-11 19:33:05 +00:00
|
|
|
char devname[80];
|
1995-05-29 11:01:42 +00:00
|
|
|
|
|
|
|
/* Got one! */
|
1995-06-11 19:33:05 +00:00
|
|
|
sprintf(devname, "/dev/%s", c1->name);
|
|
|
|
dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE,
|
1995-05-29 11:01:42 +00:00
|
|
|
mediaInitDOS, mediaGetDOS, NULL, mediaShutdownDOS, NULL);
|
|
|
|
dev->private = c1;
|
|
|
|
msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name);
|
|
|
|
}
|
|
|
|
}
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
1995-05-16 11:37:27 +00:00
|
|
|
free(names);
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/*
|
|
|
|
* Try to get all the types of devices it makes sense to get at the
|
|
|
|
* second stage of the installation.
|
|
|
|
*/
|
|
|
|
for (i = 0; device_names[i].name; i++) {
|
1995-05-20 00:13:14 +00:00
|
|
|
char try[FILENAME_MAX];
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
switch(device_names[i].type) {
|
|
|
|
case DEVICE_TYPE_CDROM:
|
1995-05-20 00:13:14 +00:00
|
|
|
fd = deviceTry(device_names[i].name, try);
|
1996-03-18 15:28:10 +00:00
|
|
|
if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */
|
|
|
|
if (fd >= 0) close(fd);
|
1995-05-20 10:33:14 +00:00
|
|
|
(void)deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
1995-05-24 09:00:58 +00:00
|
|
|
DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, NULL,
|
|
|
|
mediaShutdownCDROM, NULL);
|
1995-05-20 10:33:14 +00:00
|
|
|
msgDebug("Found a device of type CDROM named: %s\n", device_names[i].name);
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
case DEVICE_TYPE_TAPE:
|
1995-05-20 00:13:14 +00:00
|
|
|
fd = deviceTry(device_names[i].name, try);
|
|
|
|
if (fd >= 0) {
|
1995-12-11 16:32:33 +00:00
|
|
|
if (fd) close(fd);
|
1995-05-20 10:33:14 +00:00
|
|
|
deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
1995-05-24 09:00:58 +00:00
|
|
|
DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, NULL, mediaShutdownTape, NULL);
|
1995-05-17 14:40:00 +00:00
|
|
|
msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name);
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
break;
|
1995-05-16 11:37:27 +00:00
|
|
|
|
|
|
|
case DEVICE_TYPE_FLOPPY:
|
1995-05-20 00:13:14 +00:00
|
|
|
fd = deviceTry(device_names[i].name, try);
|
|
|
|
if (fd >= 0) {
|
1995-12-11 16:32:33 +00:00
|
|
|
if (fd) close(fd);
|
1995-05-20 10:33:14 +00:00
|
|
|
deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
1995-05-24 09:00:58 +00:00
|
|
|
DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, NULL,
|
|
|
|
mediaShutdownFloppy, NULL);
|
1995-05-20 16:22:42 +00:00
|
|
|
msgDebug("Found a device of type floppy named: %s\n", device_names[i].name);
|
1995-05-17 14:40:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-19 02:31:13 +00:00
|
|
|
case DEVICE_TYPE_NETWORK:
|
1995-05-20 00:13:14 +00:00
|
|
|
fd = deviceTry(device_names[i].name, try);
|
1996-06-13 17:07:41 +00:00
|
|
|
/* The only network devices that you can open this way are serial ones */
|
1995-05-20 00:13:14 +00:00
|
|
|
if (fd >= 0) {
|
1996-06-13 17:07:41 +00:00
|
|
|
char *newdesc, *cp;
|
|
|
|
|
|
|
|
if (fd)
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* Serial devices get a slip and ppp device each */
|
|
|
|
cp = device_names[i].description;
|
|
|
|
newdesc = safe_malloc(strlen(cp) + 40);
|
|
|
|
sprintf(newdesc, cp, "SLIP interface");
|
|
|
|
deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
|
|
|
NULL, NULL, mediaShutdownNetwork, NULL);
|
|
|
|
newdesc = safe_malloc(strlen(cp) + 50);
|
|
|
|
sprintf(newdesc, cp, "PPP interface");
|
|
|
|
deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
|
|
|
NULL, NULL, mediaShutdownNetwork, NULL);
|
1995-05-19 02:31:13 +00:00
|
|
|
msgDebug("Found a device of type network named: %s\n", device_names[i].name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-05-16 11:37:27 +00:00
|
|
|
default:
|
|
|
|
break;
|
1995-05-08 01:27:07 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-19 02:31:13 +00:00
|
|
|
/* Now go for the (other) network interfaces dynamically. Stolen shamelessly from ifconfig! */
|
1995-05-16 02:53:31 +00:00
|
|
|
ifc.ifc_len = sizeof(buffer);
|
|
|
|
ifc.ifc_buf = buffer;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
msgConfirm("ifconfig: socket");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
|
|
|
msgConfirm("ifconfig (SIOCGIFCONF)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifflags = ifc.ifc_req->ifr_flags;
|
|
|
|
end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
|
1995-05-16 11:37:27 +00:00
|
|
|
for (ifptr = ifc.ifc_req; ifptr < end; ifptr++) {
|
1996-06-13 17:07:41 +00:00
|
|
|
char *descr;
|
|
|
|
|
1995-05-17 14:40:00 +00:00
|
|
|
/* If it's not a link entry, forget it */
|
1995-05-30 08:29:07 +00:00
|
|
|
if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK)
|
1995-05-16 11:37:27 +00:00
|
|
|
continue;
|
1995-05-17 14:40:00 +00:00
|
|
|
/* Eliminate network devices that don't make sense */
|
|
|
|
if (!strncmp(ifptr->ifr_name, "tun", 3)
|
|
|
|
|| !strncmp(ifptr->ifr_name, "lo0", 3))
|
|
|
|
continue;
|
1996-06-13 17:07:41 +00:00
|
|
|
descr = NULL;
|
|
|
|
for (i = 0; device_names[i].name; i++) {
|
|
|
|
int len = strlen(device_names[i].name);
|
|
|
|
|
|
|
|
if (!strncmp(ifptr->ifr_name, device_names[i].name, len)) {
|
|
|
|
descr = device_names[i].description;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!descr)
|
|
|
|
descr = "<unknown network interface type>";
|
|
|
|
deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE,
|
1995-05-24 17:49:20 +00:00
|
|
|
mediaInitNetwork, NULL, NULL, mediaShutdownNetwork, NULL);
|
1995-05-17 14:40:00 +00:00
|
|
|
msgDebug("Found a device of type network named: %s\n", ifptr->ifr_name);
|
1995-05-16 02:53:31 +00:00
|
|
|
close(s);
|
1995-05-16 11:37:27 +00:00
|
|
|
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
1995-05-16 02:53:31 +00:00
|
|
|
msgConfirm("ifconfig: socket");
|
|
|
|
continue;
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
1995-05-20 10:33:14 +00:00
|
|
|
if (ifptr->ifr_addr.sa_len) /* I'm not sure why this is here - it's inherited */
|
|
|
|
ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr));
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find all devices that match the criteria, allowing "wildcarding" as well
|
1995-05-20 10:33:14 +00:00
|
|
|
* by allowing NULL or ANY values to match all. The array returned is static
|
|
|
|
* and may be used until the next invocation of deviceFind().
|
1995-05-16 02:53:31 +00:00
|
|
|
*/
|
|
|
|
Device **
|
|
|
|
deviceFind(char *name, DeviceType class)
|
|
|
|
{
|
|
|
|
static Device *found[DEV_MAX];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < numDevs; i++) {
|
1995-05-17 14:40:00 +00:00
|
|
|
if ((!name || !strcmp(Devices[i]->name, name))
|
|
|
|
&& (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
|
1995-05-16 02:53:31 +00:00
|
|
|
found[j++] = Devices[i];
|
1995-05-04 23:36:23 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
found[j] = NULL;
|
|
|
|
return j ? found : NULL;
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
|
|
|
|
1995-05-20 00:13:14 +00:00
|
|
|
int
|
|
|
|
deviceCount(Device **devs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!devs)
|
|
|
|
return 0;
|
|
|
|
for (i = 0; devs[i]; i++);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
1995-05-04 03:51:22 +00:00
|
|
|
/*
|
1995-05-16 02:53:31 +00:00
|
|
|
* Create a menu listing all the devices of a certain type in the system.
|
|
|
|
* The passed-in menu is expected to be a "prototype" from which the new
|
|
|
|
* menu is cloned.
|
1995-05-04 03:51:22 +00:00
|
|
|
*/
|
|
|
|
DMenu *
|
1996-04-13 13:32:15 +00:00
|
|
|
deviceCreateMenu(DMenu *menu, DeviceType type, int (*hook)(dialogMenuItem *d), int (*check)(dialogMenuItem *d))
|
1995-05-04 03:51:22 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
Device **devs;
|
1995-05-16 11:37:27 +00:00
|
|
|
int numdevs;
|
|
|
|
DMenu *tmp = NULL;
|
|
|
|
int i, j;
|
1995-05-04 03:51:22 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
devs = deviceFind(NULL, type);
|
1996-06-13 17:07:41 +00:00
|
|
|
numdevs = deviceCount(devs);
|
|
|
|
if (!numdevs)
|
1995-05-16 11:37:27 +00:00
|
|
|
return NULL;
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp = (DMenu *)safe_malloc(sizeof(DMenu) + (sizeof(dialogMenuItem) * (numdevs + 1)));
|
1995-05-16 11:37:27 +00:00
|
|
|
bcopy(menu, tmp, sizeof(DMenu));
|
|
|
|
for (i = 0; devs[i]; i++) {
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp->items[i].prompt = devs[i]->name;
|
1996-06-13 17:07:41 +00:00
|
|
|
for (j = 0; j < numDevs; j++) {
|
|
|
|
if (devs[i] == Devices[j]) {
|
|
|
|
tmp->items[i].title = Devices[j]->description;
|
1995-05-16 11:37:27 +00:00
|
|
|
break;
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1995-05-04 03:51:22 +00:00
|
|
|
}
|
1996-06-13 17:07:41 +00:00
|
|
|
if (j == numDevs)
|
1996-04-07 03:52:36 +00:00
|
|
|
tmp->items[i].title = "<unknown device type>";
|
|
|
|
tmp->items[i].fire = hook;
|
1996-04-13 13:32:15 +00:00
|
|
|
tmp->items[i].checked = check;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|
1995-05-16 11:37:27 +00:00
|
|
|
tmp->items[i].title = NULL;
|
|
|
|
return tmp;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|