diff --git a/Changelog b/Changelog index f42b0521a..357bd0168 100644 --- a/Changelog +++ b/Changelog @@ -6,6 +6,7 @@ - BUGFIX: Correctly display the hash of torrents with no metadata - BUGFIX: Elide status bar text if it is too wide - BUGFIX: Make sure the splash screen is displayed for 3 seconds + - BUGFIX: Make listening on a particular interface more reliable * Sun Oct 24 2010 - Christophe Dumez - v2.4.8 - BUGFIX: Fix possible crash on manual peer ban diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index e852c251a..5a80b584a 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1824,15 +1824,27 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); if(!network_iface.isValid()) { + qDebug("Invalid network interface: %s", qPrintable(iface_name)); + addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red"); + addConsoleMessage(tr("Trying any other network interface available instead.")); s->listen_on(ports); return; } - QString ip = "127.0.0.1"; - if(!network_iface.addressEntries().isEmpty()) { - ip = network_iface.addressEntries().first().ip().toString(); + QString ip; + qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size()); + foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) { + qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name)); + if(s->listen_on(ports, qPrintable(entry.ip().toString()))) { + ip = entry.ip().toString(); + break; + } + } + if(s->is_listening()) { + addConsoleMessage(tr("Listening on IP address %1 on network interface %2...").arg(ip).arg(iface_name)); + } else { + qDebug("Failed to listen on any of the IP addresses"); + addConsoleMessage(tr("Failed to listen on network interface %1").arg(iface_name), "red"); } - qDebug("Listening on interface %s with ip %s", qPrintable(iface_name), qPrintable(ip)); - s->listen_on(ports, ip.toLocal8Bit().constData()); } // Set download rate limit