RunWinPcapService() public static method

Makes sure that the "NetGroup Packet Filter" service status is "Running" and that all specified interfaces are captured.
public static RunWinPcapService ( IEnumerable requiredNics = null, bool verbose = false ) : bool
requiredNics IEnumerable If this is null it only alerts the user about any non-captured interfaces and returns true
verbose bool
return bool
Beispiel #1
0
        public static bool Start()
        {
            Global.WriteLog("Byte Counter is starting.", true);
            if (!Dependencies.RunWinPcapService(null, true))
            {
                Global.WriteLog("Byte Counter failed to start.", true);
                Global.ShowTrayTip("Byte Counter", "Failed to start", System.Windows.Forms.ToolTipIcon.Error);
                return(false);
            }
            LoadingForm splash = LoadingForm.Create("Initializing ...");

            interfaceWorkers.Clear();
            foreach (string guid in Dependencies.WinPcapDevices)
            {
                interfaceWorkers.Add(new InterfaceWorker(guid));
                splash.UpdateStatus("Initializing " + interfaceWorkers.Last().Name + " ...");
                new Thread(new ThreadStart(interfaceWorkers.Last().ReceivePackets)).Start();
                interfaceWorkers.Last().Initialized.Wait(10000);
            }
            splash.Stop();
            Dependencies.WinPcapInUse.Reset(Dependencies.WinPcapInUse.CurrentCount + 1);
            Global.WriteLog("Byte Counter: started");
            Global.ShowTrayTip("Byte Counter", "Started", System.Windows.Forms.ToolTipIcon.Info);
            return(true);
        }
Beispiel #2
0
        public static bool Start(IEnumerable <NetworkInterface> requiredNics)
        {
            Global.WriteLog("Load Balancer is starting.", true);
            Status.Update(State.Starting);
            if (requiredNics.Count() == 0)
            {
                Global.WriteLog("Load Balancer can't start without any physical interface.", true);
                Global.ShowTrayTip("Load Balancer", "Can't start whitout any physical interface", System.Windows.Forms.ToolTipIcon.Error);
                Status.Update(State.Failed);
                return(false);
            }
            if (!Jobs.Extensions.Dependencies.Check())
            {
                Status.Update(State.Failed);
                return(false);
            }
            if (!TapInterface.PutUp())
            {
                Global.WriteLog("Load Balancer failed to connect to " + TapInterface.FriendlyName, true);
                Global.ShowTrayTip("Load Balancer", "Failed to connect to " + TapInterface.FriendlyName, System.Windows.Forms.ToolTipIcon.Error);
                Status.Update(State.Failed);
                return(false);
            }
            NetworkInterface tapInterface = new NetworkInterface();

            tapInterface.Guid = TapInterface.Guid;
            tapInterface.Name = TapInterface.FriendlyName;
            if (!Dependencies.RunWinPcapService(requiredNics.Concat(new NetworkInterface[] { tapInterface }), true))
            {
                Global.WriteLog("Load Balancer failed to start because some interfaces were not captured by WinPcap.", true);
                Global.ShowTrayTip("Load Balancer", "Failed to start", System.Windows.Forms.ToolTipIcon.Error);
                TapInterface.PutDown();
                Status.Update(State.Failed);
                return(false);
            }
            Interfaces = requiredNics;
            // start LB threads
            LoadingForm splash = LoadingForm.Create("Initializing ...");

            foreach (NetworkInterface nic in Global.NetworkInterfaces.Values)
            {
                if (nic.Guid != TapInterface.Guid &&
                    (nic.IPv4Gateway.Count > 0 || nic.IPv6Gateway.Count > 0))
                {
                    splash.UpdateStatus("Configuring " + nic.Name + " ...");
                    nic.SetInterfaceMetric("4000");
                    foreach (NetworkInterface.IPGatewayAddress ip in nic.IPv4Gateway)
                    {
                        nic.EditIPv4Gateway(ip.Address, "4000");
                    }
                    foreach (NetworkInterface.IPGatewayAddress ip in nic.IPv6Gateway)
                    {
                        nic.EditIPv6Gateway(ip.Address, "4000");
                    }
                }
            }
            splash.UpdateStatus("Initializing " + TapInterface.FriendlyName + " ...");
            physicalWorkers.Clear();
            tapWorker = new TapWorker(TapInterface.Guid, TapInterface.FriendlyName, TapInterface.Mac,
                                      Global.Config.LoadBalancer.IPv4LocalAddresses.First().Address, Global.Config.LoadBalancer.IPv4GatewayAddresses.First().Address);
            new Thread(new ThreadStart(tapWorker.ReceivePackets)).Start();
            tapWorker.Initialized.Wait(1000);
            foreach (NetworkInterface nic in requiredNics)
            {
                splash.UpdateStatus("Initializing " + nic.Name + " ...");
                physicalWorkers.Add(new PhysicalWorker(nic.Guid, nic.Name, nic.Mac, nic.IPv4Address.First().Address,
                                                       nic.IPv4Address.First().Subnet, nic.DefaultIPv4GatewayMac, nic.DefaultIPv4Gateway));
                new Thread(new ThreadStart(physicalWorkers.Last().ReceivePackets)).Start();
                physicalWorkers.Last().Initialized.Wait(10000);
            }
            MTU = (int)requiredNics.Min((i) => i.IPv4Mtu > 0 ? i.IPv4Mtu : 1500);
            Global.WriteLog("Load Balancer: Negociated MTU = " + MTU);
            MSS = (ushort)(MTU - 40);
            splash.Stop();
            Dependencies.WinPcapInUse.Reset(Dependencies.WinPcapInUse.CurrentCount + 1);
            Global.WriteLog("Load Balancer: started");
            Global.ShowTrayTip("Load Balancer", "Started", System.Windows.Forms.ToolTipIcon.Info);
            Status.Update(State.Running);
            new Thread(new ThreadStart(CheckUp)).Start();
            return(true);
        }