Debugger/DebugServer.py

branch
5_1_x
changeset 1181
31d20dc43805
parent 1110
9de6692fadbd
child 1187
0a1dc25d1881
--- a/Debugger/DebugServer.py	Sun Jul 17 11:22:05 2011 +0200
+++ b/Debugger/DebugServer.py	Sun Jul 17 18:10:54 2011 +0200
@@ -10,7 +10,7 @@
 import os
 
 from PyQt4.QtCore import *
-from PyQt4.QtNetwork import QTcpServer, QHostAddress, QHostInfo
+from PyQt4.QtNetwork import QTcpServer, QHostAddress, QHostInfo, QNetworkInterface
 
 from E5Gui.E5Application import e5App
 from E5Gui import E5MessageBox
@@ -136,17 +136,22 @@
         
         self.networkInterface = Preferences.getDebugger("NetworkInterface")
         if self.networkInterface == "all":
-            hostAddress = QHostAddress("0.0.0.0")#QHostAddress.Any)
+            hostAddress = QHostAddress("0.0.0.0")   # QHostAddress.Any)
         elif self.networkInterface == "allv6":
-            hostAddress = QHostAddress("::")#QHostAddress.AnyIPv6)
+            hostAddress = QHostAddress("::")        # QHostAddress.AnyIPv6)
         else:
-            hostAddress = QHostAddress(Preferences.getDebugger("NetworkInterface"))
+            hostAddress = QHostAddress(self.networkInterface)
+        self.networkInterfaceName, self.networkInterfaceIndex = \
+            self.__getNetworkInterfaceAndIndex(self.networkInterface)
+        
         if Preferences.getDebugger("PassiveDbgEnabled"):
-            socket = Preferences.getDebugger("PassiveDbgPort") # default: 42424
-            self.listen(hostAddress, socket)
+            sock = Preferences.getDebugger("PassiveDbgPort") # default: 42424
+            self.listen(hostAddress, sock)
             self.passive = True
             self.passiveClientExited = False
         else:
+            if hostAddress.toString().lower().startswith("fe80"):
+                hostAddress.setScopeId(self.networkInterfaceName)
             self.listen(hostAddress)
             self.passive = False
         
@@ -195,7 +200,25 @@
             else:
                 return "{0}@@v6".format(QHostInfo.localHostName())
         else:
-            return self.networkInterface
+            return "{0}@@i{1}".format(self.networkInterface,
+                                      self.networkInterfaceIndex)
+        
+    def __getNetworkInterfaceAndIndex(self, address):
+        """
+        Private method to determine the network interface and the interface index.
+        
+        @param address address to determine the info for (string)
+        @return tuple of network interface name (string) and index (integer)
+        """
+        if address not in ["all", "allv6"]:
+            for networkInterface in QNetworkInterface.allInterfaces():
+                addressEntries = networkInterface.addressEntries()
+                if len(addressEntries) > 0:
+                    for addressEntry in addressEntries:
+                        if addressEntry.ip().toString().lower() == address.lower():
+                            return networkInterface.name(), networkInterface.index()
+        
+        return "", 0
         
     def preferencesChanged(self):
         """

eric ide

mercurial