From 1401d0a8b232278f5f07c9c34ed537885e7f17e2 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Wed, 8 Jul 2009 17:20:00 +0200 Subject: For some reason interface info on Symbian will not give neither correct netmask nor broadcast address. But, experiments show that route info can be used to obtain netmask. Then is easy to calculate broadcast address. Idea is to match interface and destination address from routeinfo entry, and then to use given netmask. "Machines take me by surprise with great frequency." Alan Turing(1912 - 1954) --- src/network/kernel/qnetworkinterface_symbian.cpp | 61 +++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/src/network/kernel/qnetworkinterface_symbian.cpp b/src/network/kernel/qnetworkinterface_symbian.cpp index 59f1c02..e3a282f 100644 --- a/src/network/kernel/qnetworkinterface_symbian.cpp +++ b/src/network/kernel/qnetworkinterface_symbian.cpp @@ -175,7 +175,7 @@ static QList interfaceListing() iface->addressEntries << entry; #if defined(QNETWORKINTERFACE_DEBUG) - qDebug("\n Found network interface %s, interface flags:\n\ + printf("\n Found network interface %s, interface flags:\n\ IsUp = %d, IsRunning = %d, CanBroadcast = %d,\n\ IsLoopBack = %d, IsPointToPoint = %d, CanMulticast = %d, \n\ ip = %s, netmask = %s, broadcast = %s,\n\ @@ -188,8 +188,65 @@ static QList interfaceListing() #endif } } + + // we will try to use routing info to detect more precisely + // netmask and then ::postProcess() should calculate + // broadcast addresses + + // use dummy socket to start enumerating routes + err = socket.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl); + if( err ) + { + socket.Close(); + socketServ.Close(); + // return what we have + // up to this moment + return interfaces; + } + + TSoInetRouteInfo routeInfo; + TPckg routeInfoPkg(routeInfo); + while(socket.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, routeInfoPkg) == KErrNone) + { + TName address; + + // get interface address + routeInfo.iIfAddr.Output(address); + QHostAddress ifAddr(qstringFromDesc(address)); + if(ifAddr.isNull()) + continue; + + routeInfo.iDstAddr.Output(address); + QHostAddress destination(qstringFromDesc(address)); + if(destination.isNull() || destination != ifAddr) + continue; + + // search interfaces + for(int ifindex = 0; ifindex < interfaces.size(); ++ifindex) { + QNetworkInterfacePrivate *iface = interfaces.at(ifindex); + for(int eindex = 0; eindex < iface->addressEntries.size(); ++eindex) { + QNetworkAddressEntry entry = iface->addressEntries.at(eindex); + if(entry.ip() != ifAddr) { + continue; + } else { + routeInfo.iNetMask.Output(address); + QHostAddress netmask(qstringFromDesc(address)); + entry.setNetmask(netmask); + // NULL boradcast address for + // ::postProcess to have effect + entry.setBroadcast(QHostAddress()); + iface->addressEntries.replace(eindex, entry); +// printf("for %s netmask = %s and destination = %s ; type = %d; state = %d; metric = %d \n", +// ifAddr.toString().toLatin1().constData(), netmask.toString().toLatin1().constData(), destination.toString().toLatin1().constData(), +// routeInfo.iType, routeInfo.iState, routeInfo.iMetric); + } + } + } + } + socket.Close(); - socketServ.Close(); + socketServ.Close(); + return interfaces; } -- cgit v0.12