The problem is that the Netmask of the network interface is not reported by QNetworkAddressEntry::netmask() when using Android. Also QNetworkAddressEntry::prefixLength() gives a value of -1, indicating error.
The same test program (NetInterfView) works perfect in Linux desktop for booth Qt4.8 and Qt5.1.1.
In Android it fails for Qt5.1.1 both in the emulator and when using a real Nexus7 with Android 4.3.
The test program has been attached, and the main part of it is:
void MainWindow::on_interfButton_clicked()
{
QString text;
QList<QNetworkInterface> intfList = QNetworkInterface::allInterfaces();
int intfListLen = intfList.size();
for (int i = 0; i < intfListLen; ++i) {
QNetworkInterface interface = intfList.at(i);
QNetworkInterface::InterfaceFlags flags = interface.flags();
if (!flags.testFlag( QNetworkInterface::IsUp)
|| flags.testFlag( QNetworkInterface::IsPointToPoint))
continue;
QList<QNetworkAddressEntry> entries = interface.addressEntries();
int entriesLen = entries.size();
for (int j = 0; j < entriesLen; ++j) {
QNetworkAddressEntry entry = entries.at(j);
QAbstractSocket::NetworkLayerProtocol prot = entry.ip().protocol();
if ((prot != QAbstractSocket::IPv4Protocol) && (prot != QAbstractSocket::IPv6Protocol))
continue;
text += interface.name() + " ip=" + entry.ip().toString()
+ " mask=" + entry.netmask().toString();
if (entry.prefixLength() < 0) {
// TODO MW: This seemes like a bug in android/qt, any workaround?
text += " Bad netmask";
}
text += "\n\n";
}
}
ui->textEdit->setPlainText(text);
}