QNetworkInterface: make the name lookup search numbers in string forms

That's how QHostAddress::scopeId() stores them, so we ought to look them
up the same way.

Change-Id: I7de033f80b0e4431b7f1ffff13f98cf87d45ebc6
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Thiago Macieira 2015-08-11 16:42:34 -07:00
parent 8fa44b382f
commit c72311440b
2 changed files with 21 additions and 5 deletions

View File

@ -785,7 +785,7 @@ QString QHostAddress::toString() const
usually the same as the interface name (e.g., "eth0", "en1") or number usually the same as the interface name (e.g., "eth0", "en1") or number
(e.g., "1", "2"). (e.g., "1", "2").
\sa setScopeId() \sa setScopeId(), QNetworkInterface, QNetworkInterface::interfaceFromName
*/ */
QString QHostAddress::scopeId() const QString QHostAddress::scopeId() const
{ {
@ -796,8 +796,14 @@ QString QHostAddress::scopeId() const
/*! /*!
\since 4.1 \since 4.1
Sets the IPv6 scope ID of the address to \a id. If the address Sets the IPv6 scope ID of the address to \a id. If the address protocol is
protocol is not IPv6, this function does nothing. not IPv6, this function does nothing. The scope ID may be set as an
interface name (such as "eth0" or "en1") or as an integer representing the
interface index. If \a id is an interface name, QtNetwork will convert to
an interface index using QNetworkInterface::interfaceIndexFromName() before
calling the operating system networking functions.
\sa scopeId(), QNetworkInterface, QNetworkInterface::interfaceFromName
*/ */
void QHostAddress::setScopeId(const QString &id) void QHostAddress::setScopeId(const QString &id)
{ {

View File

@ -86,9 +86,16 @@ QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interface
{ {
QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces(); QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin(); QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
for ( ; it != interfaceList.constEnd(); ++it)
if ((*it)->name == name) bool ok;
uint index = name.toUInt(&ok);
for ( ; it != interfaceList.constEnd(); ++it) {
if (ok && (*it)->index == int(index))
return *it; return *it;
else if ((*it)->name == name)
return *it;
}
return empty; return empty;
} }
@ -516,6 +523,9 @@ QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const
name. If no such interface exists, this function returns an name. If no such interface exists, this function returns an
invalid QNetworkInterface object. invalid QNetworkInterface object.
The string \a name may be either an actual interface name (such as "eth0"
or "en1") or an interface index in string form ("1", "2", etc.).
\sa name(), isValid() \sa name(), isValid()
*/ */
QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name) QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name)