summaryrefslogtreecommitdiff
path: root/pfinet/main.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2000-10-04 01:59:03 +0000
committerMarcus Brinkmann <marcus@gnu.org>2000-10-04 01:59:03 +0000
commit898424326fc1188384f67963ab6789f18dd57fd3 (patch)
treea4085609a66d34f0f0a59647ed236e64d3aa9bfc /pfinet/main.c
parentb81d9ec23532ba8b2519ba3b8bf68fcfeb0260c5 (diff)
2000-10-04 Marcus Brinkmann <marcus@gnu.org>
* Makefile (SRCS): Add dummy.c * dummy.c: New file. * ethernet.c: Moved ETHER_PORT, READPT, READPTNAME to ... (struct ether_device): ... here. New struct. ETHER_DEV is now a pointer to a struct ether_device. (ethernet_demuxer): New variables edev, dev. Iterate over linked list ETHER_DEV to find correct readptname. Use dev instead ETHER_DEV for socket buffer manipulation. (ethernet_open): New variable edev. Use dev->priv to find correct edev. Use members of edev instead global variables. (ethernet_xmit): New variable edev. Use dev->priv to find correct edev.Use member of edev instead global variable ETHER_PORT. (setup_ethernet_device): New output argument DEVICE. New variables edev and dev. Allocate memory for edev, add it to the head of ETHER_DEV. Use dev instead ETHER_DEV. Use members of edev instead global variables. * main.c: ALREADY_OPEN removed. (find_device): Fix comment. Redone to work with multiple devices by iterating over DEV_BASE. (enumerate_device): Likewise. * pfinet.h: Add new argument to prototype of setup_ethernet_device. Add prototype for setup_dummy_device. Remove prototype for ETHER_DEV. Add prototype for DEV_BASE.
Diffstat (limited to 'pfinet/main.c')
-rw-r--r--pfinet/main.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/pfinet/main.c b/pfinet/main.c
index d85b5ff1..591192ac 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -126,48 +126,73 @@ arrange_shutdown_notification ()
mach_port_deallocate (mach_task_self (), initport);
}
-static char *already_open = 0;
-/* Return an open device called NAME. If NMAE is 0, and there is a single
- active device, it is returned, otherwise an error.
- XXX hacky single-interface version. */
+/* Return an open device called NAME. If NAME is 0, and there is a single
+ active device, it is returned, otherwise an error. */
error_t
find_device (char *name, struct device **device)
{
- if (already_open)
- if (!name || strcmp (already_open, (*device)->name) == 0)
+ struct device *dev = dev_base;
+
+ /* Skip loopback interface. */
+ assert (dev);
+ dev = dev->next;
+
+ if (!name)
+ {
+ if (dev)
+ {
+ if (dev->next)
+ return EBUSY; /* XXXACK */
+ else
+ {
+ *device = dev;
+ return 0;
+ }
+ }
+ else
+ return ENXIO; /* XXX */
+ }
+
+ for (; dev; dev = dev->next)
+ if (strcmp (dev->name, name) == 0)
{
- *device = &ether_dev;
+ *device = dev;
return 0;
}
- else
- return EBUSY; /* XXXACK */
- else if (! name)
- return ENXIO; /* XXX */
- name = already_open = strdup (name);
-
- setup_ethernet_device (name);
+ if (strncmp(name, "dummy", 5) == 0)
+ setup_dummy_device (name, device);
+ else
+ setup_ethernet_device (name, device);
/* Turn on device. */
- dev_open (&ether_dev);
-
- *device = &ether_dev;
+ dev_open (*device);
return 0;
}
/* Call FUN with each active device. If a call to FUN returns a
non-zero value, this function will return immediately. Otherwise 0 is
- returned.
- XXX hacky single-interface version. */
+ returned. */
error_t
enumerate_devices (error_t (*fun) (struct device *dev))
{
- if (already_open)
- return (*fun) (&ether_dev);
- else
- return 0;
+ error_t err;
+ struct device *dev = dev_base;
+
+ /* Skip loopback device. */
+ assert (dev);
+ dev = dev->next;
+
+ for (; dev; dev = dev->next)
+ {
+ err = (*fun) (dev);
+ if (err)
+ return err;
+ }
+
+ return 0;
}
extern void sk_init (void), skb_init (void);