summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2012-02-19 05:32:36 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-02-19 05:32:36 +0100
commitd3ad9490749fe330bea91c0027a0c8319476cac0 (patch)
treeab934f835e432500e5a18c8efbc94753c3a3e560
parentcada30c0b184d5d532fc484c9b07844183007468 (diff)
Make pfinet try both a filepath and kernel device
pfinet/ethernet.c (ethernet_open): Try to file_name_lookup() the device as filepath before opening the Mach device.
-rw-r--r--pfinet/ethernet.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/pfinet/ethernet.c b/pfinet/ethernet.c
index dab5c56f..f3669190 100644
--- a/pfinet/ethernet.c
+++ b/pfinet/ethernet.c
@@ -166,14 +166,33 @@ ethernet_open (struct device *dev)
mach_port_set_qlimit (mach_task_self (), edev->readptname, MACH_PORT_QLIMIT_MAX);
- err = get_privileged_ports (0, &master_device);
- if (err)
- error (2, err, "cannot get device master port");
-
- err = device_open (master_device, D_WRITE | D_READ, dev->name, &edev->ether_port);
- mach_port_deallocate (mach_task_self (), master_device);
- if (err)
- error (2, err, "%s", dev->name);
+ master_device = file_name_lookup (dev->name, O_READ | O_WRITE, 0);
+ if (master_device != MACH_PORT_NULL)
+ {
+ /* The device name here is the path of a device file. */
+ err = device_open (master_device, D_WRITE | D_READ, "eth", &edev->ether_port);
+ mach_port_deallocate (mach_task_self (), master_device);
+ if (err)
+ error (2, err, "%s", dev->name);
+ }
+ else
+ {
+ /* No, perhaps a Mach device? */
+ int file_errno = errno;
+ err = get_privileged_ports (0, &master_device);
+ if (err)
+ {
+ error (0, errno, "file_name_lookup %s", dev->name);
+ error (2, err, "and cannot get device master port");
+ }
+ err = device_open (master_device, D_WRITE | D_READ, dev->name, &edev->ether_port);
+ mach_port_deallocate (mach_task_self (), master_device);
+ if (err)
+ {
+ error (0, errno, "file_name_lookup %s", dev->name);
+ error (2, err, "%s", dev->name);
+ }
+ }
err = device_set_filter (edev->ether_port, ports_get_right (edev->readpt),
MACH_MSG_TYPE_MAKE_SEND, 0,