QNetworkInterface: don't add a QNetworkAddressEntry if no IP is known
If SIOCGIFADDR fails, then don't bother trying to get the broadcast address or netmask, and especially don't add the empty QNetworkAddressEntry to the interface. This can happen on interfaces that have no IP address assigned (for example, inactive interfaces). Change-Id: I8de47ed6c7be4847b99bffff141c326d94ecca78 Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
043f5d3eb5
commit
8cd67bbfac
@ -268,8 +268,13 @@ static QList<QNetworkInterfacePrivate *> interfaceListing()
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get the interface broadcast address
|
||||
// Get the address of the interface
|
||||
QNetworkAddressEntry entry;
|
||||
if (qt_safe_ioctl(socket, SIOCGIFADDR, &req) >= 0) {
|
||||
sockaddr *sa = &req.ifr_addr;
|
||||
entry.setIp(addressFromSockaddr(sa));
|
||||
|
||||
// Get the interface broadcast address
|
||||
if (iface->flags & QNetworkInterface::CanBroadcast) {
|
||||
if (qt_safe_ioctl(socket, SIOCGIFBRDADDR, &req) >= 0) {
|
||||
sockaddr *sa = &req.ifr_addr;
|
||||
@ -278,12 +283,6 @@ static QList<QNetworkInterfacePrivate *> interfaceListing()
|
||||
}
|
||||
}
|
||||
|
||||
// Get the address of the interface
|
||||
if (qt_safe_ioctl(socket, SIOCGIFADDR, &req) >= 0) {
|
||||
sockaddr *sa = &req.ifr_addr;
|
||||
entry.setIp(addressFromSockaddr(sa));
|
||||
}
|
||||
|
||||
// Get the interface netmask
|
||||
if (qt_safe_ioctl(socket, SIOCGIFNETMASK, &req) >= 0) {
|
||||
sockaddr *sa = &req.ifr_addr;
|
||||
@ -292,6 +291,7 @@ static QList<QNetworkInterfacePrivate *> interfaceListing()
|
||||
|
||||
iface->addressEntries << entry;
|
||||
}
|
||||
}
|
||||
|
||||
::close(socket);
|
||||
return interfaces;
|
||||
|
Loading…
x
Reference in New Issue
Block a user