Don't use IPv4 addresses when the user has enabled IPv6 address in the settings.

This commit is contained in:
sledgehammer999 2014-09-02 14:36:51 +03:00
parent a708c642ef
commit bf0ed595c7
2 changed files with 10 additions and 6 deletions

View file

@ -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

View file

@ -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();