diff options
-rw-r--r-- | pfinet/ethernet.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/pfinet/ethernet.c b/pfinet/ethernet.c index 3b632fa6..754c9156 100644 --- a/pfinet/ethernet.c +++ b/pfinet/ethernet.c @@ -169,14 +169,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, |