From d3ad9490749fe330bea91c0027a0c8319476cac0 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 19 Feb 2012 05:32:36 +0100 Subject: 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. --- pfinet/ethernet.c | 35 +++++++++++++++++++++++++++-------- 1 file 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, -- cgit v1.2.3