--- a/src/eric7/Debugger/DebugServer.py Tue Nov 22 16:33:30 2022 +0100 +++ b/src/eric7/Debugger/DebugServer.py Wed Nov 23 10:48:46 2022 +0100 @@ -28,6 +28,14 @@ "None": "DebuggerInterfaceNone", } +NetworkInterfaceMapping = { + "all": QHostAddress.SpecialAddress.Any, + "allv4": QHostAddress.SpecialAddress.AnyIPv4, + "allv6": QHostAddress.SpecialAddress.AnyIPv6, + "localv4": QHostAddress.SpecialAddress.LocalHost, + "localv6": QHostAddress.SpecialAddress.LocalHostIPv6, +} + class DebugServer(QTcpServer): """ @@ -190,28 +198,34 @@ self.__reportedWatchpointIssues = [] self.networkInterface = Preferences.getDebugger("NetworkInterface") - if self.networkInterface == "all": - hostAddress = QHostAddress("0.0.0.0") - # QHostAddress.SpecialAddress.AnyIPv4) # secok - elif self.networkInterface == "allv6": - hostAddress = QHostAddress("::") - # QHostAddress.SpecialAddress.AnyIPv6) - else: - hostAddress = QHostAddress(self.networkInterface) + hostAddress = ( + QHostAddress(NetworkInterfaceMapping[self.networkInterface]) + if self.networkInterface in NetworkInterfaceMapping + else QHostAddress(self.networkInterface) + ) ( self.networkInterfaceName, self.networkInterfaceIndex, ) = self.__getNetworkInterfaceAndIndex(self.networkInterface) if not preventPassiveDebugging and Preferences.getDebugger("PassiveDbgEnabled"): - sock = Preferences.getDebugger("PassiveDbgPort") # default: 42424 - self.listen(hostAddress, sock) + port = Preferences.getDebugger("PassiveDbgPort") # default: 42424 + self.listen(hostAddress, port) self.passive = True self.passiveClientExited = False else: if hostAddress.toString().lower().startswith("fe80"): hostAddress.setScopeId(self.networkInterfaceName) - self.listen(hostAddress) + if Preferences.getDebugger("NetworkPortFixed"): + port = Preferences.getDebugger("NetworkPort") + res = self.listen(hostAddress, port) + if not res and Preferences.getDebugger("NetworkPortIncrement"): + maxPort = port + 100 # try a maximum of 100 ports + while not res and port < maxPort: + port += 1 + res = self.listen(hostAddress, port) + else: + self.listen(hostAddress) self.passive = False self.debuggerInterface = None @@ -261,13 +275,13 @@ @return IP address or hostname @rtype str """ - if self.networkInterface == "all": - if localhost: + if self.networkInterface in ("allv4", "localv4"): + if localhost or self.networkInterface == "localv4": return "127.0.0.1" else: return "{0}@@v4".format(QHostInfo.localHostName()) - elif self.networkInterface == "allv6": - if localhost: + elif self.networkInterface in ("all", "allv6", "localv6"): + if localhost or self.networkInterface == "localv6": return "::1" else: return "{0}@@v6".format(QHostInfo.localHostName())