public static TapDevice GetTapDevice(string device_name) { TapDevice tap = null; if (OSDependent.OSVersion == OSDependent.OS.Linux) { tap = new LinuxTap(device_name); } else if (OSDependent.OSVersion == OSDependent.OS.Windows) { tap = new WindowsTap(device_name); } else { tap = new cTap(device_name); } return(tap); }
/// <summary>Initializes the Ethernet device by opening the TAP device and /// starting the ISource thread.</summary> /// <param name="tap">The name of the TAP device on the host.</param> public Ethernet(string device_name) { for(int i = 0; i < 15; i++) { try { _tap = Ipop.Tap.TapDevice.GetTapDevice(device_name); break; } catch {} Thread.Sleep(2); ProtocolLog.WriteIf(ProtocolLog.Exceptions, "Unable to set up the tap, trying again..."); } if(_tap == null) { ProtocolLog.WriteIf(ProtocolLog.Exceptions, "Unable to set up the tap."); Environment.Exit(1); } Address = _tap.Address; _running = true; _read_thread = new Thread(ReadLoop); _read_thread.IsBackground = true; _read_thread.Start(); }