public WinPcapAdapter(DEV9_State parDev9, string parDevice, bool isSwitch) : base(parDev9) { switched = isSwitch; NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } hostMAC = hostAdapter.GetPhysicalAddress().GetAddressBytes(); //PcapInitIO needs correct MAC SetMAC(null); byte[] wMAC = (byte[])ps2MAC.Clone(); //wMAC[3] = hostMAC[3]; wMAC[5] = hostMAC[4]; wMAC[4] = hostMAC[5]; SetMAC(wMAC); //If parDevice starts with "{", assume device is given by GUID (as it would be under windows) //else, use the string as is (wine, linux) if (!PcapInitIO(parDevice.StartsWith("{") ? @"\Device\NPF_" + parDevice : parDevice)) { Log_Error("Can't Open Device " + parDevice); #if NETCOREAPP #else System.Windows.Forms.MessageBox.Show("Can't Open Device " + parDevice); #endif return; } if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { InitDHCP(hostAdapter); } }
public TAPAdapter(DEV9_State parDev9, string parDevice) : base(parDev9) { htap = TAPOpen(parDevice); htapstream = new FileStream(htap, FileAccess.ReadWrite, 16 * 1024, true); if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } InitDHCP(hostAdapter); } SetMAC(null); byte[] hostMAC = TAPGetMac(htap); if (hostMAC == null) { Log_Error("Unable to get host MAC address, using default MAC"); return; } byte[] wMAC = (byte[])ps2MAC.Clone(); //wMAC[3] = hostMAC[3]; wMAC[5] = hostMAC[4]; wMAC[4] = hostMAC[5]; SetMAC(wMAC); }