From a2ebbaa322f4be4fdf068fb471ac0cc867adf6e9 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 21 May 2016 14:43:10 -0600 Subject: [PATCH] Force Npcap DLL to be used first for Dynamips and uBridge (instead of the one from Winpcap if installed). --- gns3server/modules/dynamips/hypervisor.py | 10 +++++++++- gns3server/ubridge/hypervisor.py | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index 18c35352..a94e32df 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -19,6 +19,7 @@ Represents a Dynamips hypervisor and starts/stops the associated Dynamips process. """ +import sys import os import subprocess import asyncio @@ -117,6 +118,12 @@ class Hypervisor(DynamipsHypervisor): """ self._command = self._build_command() + env = os.environ.copy() + if sys.platform.startswith("win"): + # add the Npcap directory to $PATH to force Dynamips to use npcap DLL instead of Winpcap (if installed) + system_root = os.path.join(os.path.expandvars("%SystemRoot%"), "System32", "Npcap") + if os.path.isdir(system_root): + env["PATH"] = system_root + ';' + env["PATH"] try: log.info("Starting Dynamips: {}".format(self._command)) self._stdout_file = os.path.join(self.working_dir, "dynamips_i{}_stdout.txt".format(self._id)) @@ -125,7 +132,8 @@ class Hypervisor(DynamipsHypervisor): self._process = yield from asyncio.create_subprocess_exec(*self._command, stdout=fd, stderr=subprocess.STDOUT, - cwd=self._working_dir) + cwd=self._working_dir, + env=env) log.info("Dynamips process started PID={}".format(self._process.pid)) self._started = True except (OSError, subprocess.SubprocessError) as e: diff --git a/gns3server/ubridge/hypervisor.py b/gns3server/ubridge/hypervisor.py index 929d06f6..7c43e838 100644 --- a/gns3server/ubridge/hypervisor.py +++ b/gns3server/ubridge/hypervisor.py @@ -19,6 +19,7 @@ Represents a uBridge hypervisor and starts/stops the associated uBridge process. """ +import sys import os import subprocess import asyncio @@ -140,6 +141,12 @@ class Hypervisor(UBridgeHypervisor): """ yield from self._check_ubridge_version() + env = os.environ.copy() + if sys.platform.startswith("win"): + # add the Npcap directory to $PATH to force Dynamips to use npcap DLL instead of Winpcap (if installed) + system_root = os.path.join(os.path.expandvars("%SystemRoot%"), "System32", "Npcap") + if os.path.isdir(system_root): + env["PATH"] = system_root + ';' + env["PATH"] try: command = self._build_command() log.info("starting ubridge: {}".format(command)) @@ -149,7 +156,8 @@ class Hypervisor(UBridgeHypervisor): self._process = yield from asyncio.create_subprocess_exec(*command, stdout=fd, stderr=subprocess.STDOUT, - cwd=self._working_dir) + cwd=self._working_dir, + env=env) log.info("ubridge started PID={}".format(self._process.pid)) except (OSError, subprocess.SubprocessError) as e: