1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-11 03:55:56 +01:00

Reliably detect the wireless interface. Thank to Markus Fuchs for investigations and patch. (LP: #415719)

This commit is contained in:
David Paleino
2012-11-15 09:48:54 +01:00
parent b9513bcbe8
commit 6a3f90853f

View File

@@ -37,6 +37,7 @@ import random
import time import time
from string import maketrans, translate from string import maketrans, translate
import dbus import dbus
import socket, fcntl
import wpath import wpath
import misc import misc
@@ -132,6 +133,27 @@ def GetDefaultGateway():
print 'couldn\'t retrieve default gateway from route -n' print 'couldn\'t retrieve default gateway from route -n'
return gateway return gateway
def isWireless(devname):
"""
Classic-style wifi device classification using linux/wireless.h
This should be extended or replaced by nl80211.h style classification
in the future, if wireless.h is fully replaced.
"""
we = None
for t in [socket.AF_INET, socket.AF_INET6, socket.AF_IPX, socket.AF_AX25, socket.AF_APPLETALK]:
sk = socket.socket(t, socket.SOCK_DGRAM)
if sk is None:
continue
skfd = sk.fileno()
try:
#define SIOCGIWNAME 0x8b01 in linux/wireless.h
# "used to verify the presence of wireless extensions"
we = fcntl.ioctl(skfd, 0x8b01, devname)
except:
pass
sk.close()
return we is not None
def GetWirelessInterfaces(): def GetWirelessInterfaces():
""" Get available wireless interfaces. """ Get available wireless interfaces.
@@ -142,10 +164,7 @@ def GetWirelessInterfaces():
""" """
dev_dir = '/sys/class/net/' dev_dir = '/sys/class/net/'
ifnames = [iface for iface in os.listdir(dev_dir) ifnames = [iface for iface in os.listdir(dev_dir) and isWireless(str(iface))]
if os.path.isdir(dev_dir + iface) and
'wireless' in os.listdir(dev_dir + iface)]
return ifnames return ifnames
def GetWiredInterfaces(): def GetWiredInterfaces():