From bf0ed595c7471517cc5604e4e0dbe3eb9bc20d2c Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Tue, 2 Sep 2014 14:36:51 +0300 Subject: [PATCH] Don't use IPv4 addresses when the user has enabled IPv6 address in the settings. --- src/qtlibtorrent/qbtsession.cpp | 8 +++++--- src/smtp.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 86d74e1f6..1620f5352 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1925,16 +1925,18 @@ void QBtSession::setListeningPort(int port) { QString ip; qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size()); foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries()) { - if (!listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol)) + if ((!listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol)) + || (listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv4Protocol))) continue; qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name)); s->listen_on(ports, ec, entry.ip().toString().toLatin1().constData(), session::listen_no_system_port); if (!ec) { ip = entry.ip().toString(); addConsoleMessage(tr("qBittorrent is trying to listen on interface %1 port: %2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ip).arg(QString::number(port)), "blue"); - break; + return; } - } + } + addConsoleMessage(tr("qBittorrent didn't find an %1 local address to listen on", "qBittorrent didn't find an IPv4 local address to listen on").arg(listen_ipv6 ? "IPv6" : "IPv4"), "red"); } // Set download rate limit diff --git a/src/smtp.cpp b/src/smtp.cpp index b51a91d19..ba41ac0c2 100644 --- a/src/smtp.cpp +++ b/src/smtp.cpp @@ -81,13 +81,14 @@ QByteArray determineLocalAddress() { const Preferences* const pref = Preferences::instance(); const QString iface_name = pref->getNetworkInterface(); - const bool listen_ipv6 = pref->getListenIPv6(); + const bool use_ipv6 = pref->getListenIPv6(); QByteArray address = "127.0.0.1"; if (iface_name.isEmpty()) { foreach (const QHostAddress& addr, QNetworkInterface::allAddresses()) { if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6 - || (!listen_ipv6 && (addr.protocol() == QAbstractSocket::IPv6Protocol))) + || (!use_ipv6 && (addr.protocol() == QAbstractSocket::IPv6Protocol)) + || (use_ipv6 && (addr.protocol() == QAbstractSocket::IPv4Protocol))) continue; address = addr.toString().toLatin1(); break; @@ -100,7 +101,8 @@ QByteArray determineLocalAddress() foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries()) { if (entry.ip() == QHostAddress::LocalHost || entry.ip() == QHostAddress::LocalHostIPv6 - || (!listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol))) + || (!use_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol)) + || (use_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv4Protocol))) continue; address = entry.ip().toString().toLatin1();