From f8f085464d26fdbb1c1a46f0d7c3f358920b35d2 Mon Sep 17 00:00:00 2001 From: JoshD Date: Tue, 19 Jul 2016 13:07:30 -0700 Subject: [PATCH] Fixed clumsy handling of network device selection. Things are more uniform now (at last). Updated readme to include VC++ 2010 redistributable requirement for raw ethernet. --- Contralto/IO/HostEthernetEncapsulation.cs | 36 +++++++---------------- Contralto/IO/UDPEncapsulation.cs | 2 +- Contralto/Program.cs | 2 +- Contralto/UI/SystemOptions.cs | 18 ++++++------ Contralto/app.manifest | 16 ++++++++++ Contralto/readme.txt | 9 ++++-- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Contralto/IO/HostEthernetEncapsulation.cs b/Contralto/IO/HostEthernetEncapsulation.cs index 324a6e3..c329c88 100644 --- a/Contralto/IO/HostEthernetEncapsulation.cs +++ b/Contralto/IO/HostEthernetEncapsulation.cs @@ -57,7 +57,7 @@ namespace Contralto.IO public override string ToString() { - return Description; + return String.Format("{0} ({1})", Name, Description); } public string Name; @@ -72,26 +72,22 @@ namespace Contralto.IO /// public class HostEthernetEncapsulation : IPacketEncapsulation { - public HostEthernetEncapsulation(EthernetInterface iface) - { - AttachInterface(iface); - } - public HostEthernetEncapsulation(string name) { // Find the specified device by name - List interfaces = EthernetInterface.EnumerateDevices(); - - foreach (EthernetInterface i in interfaces) + foreach (LivePacketDevice device in LivePacketDevice.AllLocalMachine) { - if (name == i.Description) + if (device.GetNetworkInterface().Name.ToLowerInvariant() == Configuration.HostPacketInterfaceName.ToLowerInvariant()) { - AttachInterface(i); - return; + AttachInterface(device); + break; } } - throw new InvalidOperationException("Specified ethernet interface does not exist or is not compatible with WinPCAP."); + if (_interface == null) + { + throw new InvalidOperationException("Specified ethernet interface does not exist or is not compatible with WinPCAP."); + } } public void RegisterReceiveCallback(ReceivePacketDelegate callback) @@ -205,19 +201,9 @@ namespace Contralto.IO } } - private void AttachInterface(EthernetInterface iface) + private void AttachInterface(LivePacketDevice iface) { - _interface = null; - - // Find the specified device by name - foreach (LivePacketDevice device in LivePacketDevice.AllLocalMachine) - { - if (device.Description == iface.Description) - { - _interface = device; - break; - } - } + _interface = iface; if (_interface == null) { diff --git a/Contralto/IO/UDPEncapsulation.cs b/Contralto/IO/UDPEncapsulation.cs index d27f43f..bf1face 100644 --- a/Contralto/IO/UDPEncapsulation.cs +++ b/Contralto/IO/UDPEncapsulation.cs @@ -50,7 +50,7 @@ namespace Contralto.IO IPInterfaceProperties props = null; foreach(NetworkInterface nic in nics) { - if (nic.Description == interfaceName) + if (nic.Name == interfaceName) { props = nic.GetIPProperties(); break; diff --git a/Contralto/Program.cs b/Contralto/Program.cs index 59dd112..7800e5e 100644 --- a/Contralto/Program.cs +++ b/Contralto/Program.cs @@ -112,7 +112,7 @@ namespace Contralto } catch { - Configuration.HostRawEthernetInterfacesAvailable = false; + Configuration.HostRawEthernetInterfacesAvailable = false; } } diff --git a/Contralto/UI/SystemOptions.cs b/Contralto/UI/SystemOptions.cs index 055aab9..f348dca 100644 --- a/Contralto/UI/SystemOptions.cs +++ b/Contralto/UI/SystemOptions.cs @@ -16,6 +16,8 @@ */ using Contralto.IO; +using PcapDotNet.Core; +using PcapDotNet.Core.Extensions; using System; using System.Collections.Generic; using System.Net.NetworkInformation; @@ -131,12 +133,10 @@ namespace Contralto.UI // Add all interfaces that PCAP knows about. case PacketInterfaceType.EthernetEncapsulation: { - List ifaces = EthernetInterface.EnumerateDevices(); - - foreach (EthernetInterface iface in ifaces) - { - EthernetInterfaceListBox.Items.Add(iface); - } + foreach (LivePacketDevice device in LivePacketDevice.AllLocalMachine) + { + EthernetInterfaceListBox.Items.Add(new EthernetInterface(device.GetNetworkInterface().Name, device.GetNetworkInterface().Description)); + } } break; @@ -157,7 +157,7 @@ namespace Contralto.UI { EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.Items[i]; - if (iface.Description == Configuration.HostPacketInterfaceName) + if (iface.Name == Configuration.HostPacketInterfaceName) { EthernetInterfaceListBox.SelectedIndex = i; break; @@ -231,7 +231,7 @@ namespace Contralto.UI // First warn the user of changes that require a restart. // if ((!(String.IsNullOrEmpty(Configuration.HostPacketInterfaceName) && EthernetInterfaceListBox.SelectedIndex == 0) && - (Configuration.HostPacketInterfaceName != iface.Description || + (Configuration.HostPacketInterfaceName != iface.Name || Configuration.HostPacketInterfaceType != _selectedInterfaceType)) || Configuration.SystemType != _selectedSystemType) { @@ -243,7 +243,7 @@ namespace Contralto.UI // Ethernet Configuration.HostAddress = Convert.ToByte(AltoEthernetAddressTextBox.Text, 8); - Configuration.HostPacketInterfaceName = iface.Description; + Configuration.HostPacketInterfaceName = iface.Name; Configuration.HostPacketInterfaceType = _selectedInterfaceType; // Display diff --git a/Contralto/app.manifest b/Contralto/app.manifest index ef8ac3a..f7417b8 100644 --- a/Contralto/app.manifest +++ b/Contralto/app.manifest @@ -1,4 +1,20 @@  + diff --git a/Contralto/readme.txt b/Contralto/readme.txt index ed1870e..029a5c0 100644 --- a/Contralto/readme.txt +++ b/Contralto/readme.txt @@ -245,8 +245,13 @@ encapsulation. ContrAlto can encapsulate the Alto's 3mbit ("experimental") Ethernet packets in either UDP datagrams or raw Ethernet packets on a network interface on the "host" computer (the computer running ContrAlto). -Raw packet encapsulation requires WinPCAP to be installed; this can be acquired -from http://www.winpcap.org/. +Raw packet encapsulation requires WinPCAP and the Microsoft Visual C++ 2010 +redistributable to be installed; these can be acquired from: + +http://www.winpcap.org/ +and +http://www.microsoft.com/en-us/download/details.aspx?id=5555 + 4.2.1 Host Address ------------------