1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Detect Wifi adapters on OSX. Fixes #549.

This commit is contained in:
grossmj 2016-06-10 12:36:41 -06:00
parent 182a979e71
commit c3c5eb533f
2 changed files with 26 additions and 3 deletions

View File

@ -17,12 +17,14 @@
import sys
import asyncio
import subprocess
from ...error import NodeError
from ...base_node import BaseNode
from ...nios.nio_udp import NIOUDP
from gns3server.utils.interfaces import interfaces
import gns3server.utils.asyncio
import logging
log = logging.getLogger(__name__)
@ -111,6 +113,26 @@ class Cloud(BaseNode):
yield from self._stop_ubridge()
log.info('Cloud "{name}" [{id}] has been closed'.format(name=self._name, id=self._id))
@asyncio.coroutine
def _is_wifi_adapter_osx(self, adapter_name):
try:
output = yield from gns3server.utils.asyncio.subprocess_check_output("networksetup", "-listallhardwareports")
except (FileNotFoundError, subprocess.SubprocessError) as e:
log.warn("Could not execute networksetup: {}".format(e))
return False
is_wifi = False
for line in output.splitlines():
if is_wifi:
if adapter_name == line.replace("Device: ", ""):
return True
is_wifi = False
else:
if 'Wi-Fi' in line:
is_wifi = True
return False
@asyncio.coroutine
def _add_ubridge_connection(self, nio, port_number):
"""
@ -164,9 +186,10 @@ class Cloud(BaseNode):
yield from self._ubridge_send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=bridge_name,
interface=port_info["interface"]))
else:
if sys.platform.startswith("darwin") and port_info["interface"].startswith("en"):
if sys.platform.startswith("darwin"):
# Wireless adapters are not well supported by the libpcap on OSX
raise NodeError("Connecting to a Wireless adapter is not supported.")
if (yield from self._is_wifi_adapter_osx(port_info["interface"])):
raise NodeError("Connecting to a Wireless adapter is not supported on Mac OS")
if sys.platform.startswith("darwin") and port_info["interface"].startswith("vmnet"):
# Use a special NIO to connect to VMware vmnet interfaces on OSX (libpcap doesn't support them)
yield from self._ubridge_send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=bridge_name,

View File

@ -56,7 +56,7 @@ def subprocess_check_output(*args, cwd=None, env=None):
if output is None:
return ""
# If we received garbage we ignore invalid characters
# it should happend only when user try to use another binary
# it should happens only when user try to use another binary
# and the code of VPCS, dynamips... Will detect it's not the correct binary
return output.decode("utf-8", errors="ignore")