summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-04 11:17:47 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-08-04 11:17:47 (GMT)
commitbe212bf108e71ba3b5b75802b1f4de6613ba315c (patch)
treec541ad12e8698f04e8fe386c2e1b94e8baca6c1b /src/network/kernel
parent67ae1b0dac175f48875507f3187ed49276a29ddf (diff)
parente6bb00250b321b149dd80259dc4f479088d5949b (diff)
downloadQt-be212bf108e71ba3b5b75802b1f4de6613ba315c.zip
Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.gz
Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.bz2
Merge commit 'origin/master'
Conflicts: src/corelib/global/qglobal.h src/corelib/kernel/qmetatype.cpp src/corelib/kernel/qobject.cpp src/corelib/thread/qthread_unix.cpp src/gui/graphicsview/qgraphicssceneevent.h src/gui/itemviews/qheaderview.h src/gui/kernel/qapplication_qws.cpp src/gui/kernel/qgesture.h src/gui/kernel/qgesturerecognizer.h src/gui/painting/qpaintengine_raster.cpp src/network/access/qhttpnetworkreply.cpp src/network/access/qnetworkcookie.h src/network/socket/qnativesocketengine_unix.cpp
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qnetworkinterface.cpp6
-rw-r--r--src/network/kernel/qnetworkinterface_symbian.cpp203
2 files changed, 124 insertions, 85 deletions
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index 953722c..e588c18 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -128,7 +128,7 @@ QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)
for (int i = 0; i < len; ++i) {
if (i)
result += QLatin1Char(':');
-
+
char buf[3];
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
sprintf_s(buf, 3, "%02hX", ushort(data[i]));
@@ -603,13 +603,13 @@ QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface)
<< ", hardware address = " << networkInterface.hardwareAddress()
<< ", flags = ";
flagsDebug(debug, networkInterface.flags());
-#if defined(Q_CC_RVCT)
+#if defined(Q_CC_RVCT)
// RVCT gets confused with << networkInterface.addressEntries(), reason unknown.
debug.nospace() << ")\n";
#else
debug.nospace() << ", entries = " << networkInterface.addressEntries()
<< ")\n";
-#endif
+#endif
return debug.space();
}
#endif
diff --git a/src/network/kernel/qnetworkinterface_symbian.cpp b/src/network/kernel/qnetworkinterface_symbian.cpp
index 59f1c02..f2ded36 100644
--- a/src/network/kernel/qnetworkinterface_symbian.cpp
+++ b/src/network/kernel/qnetworkinterface_symbian.cpp
@@ -41,12 +41,8 @@
//#define QNETWORKINTERFACE_DEBUG
-//#include "qset.h"
#include "qnetworkinterface.h"
#include "qnetworkinterface_p.h"
-//#include <private/qnativesocketengine_p.h>
-//#include "qalgorithms.h"
-
#ifndef QT_NO_NETWORKINTERFACE
@@ -54,142 +50,185 @@
#include <in_iface.h>
#include <es_sock.h>
-//#include <sys/types.h>
-//#include <sys/socket.h>
-//#include <errno.h>
-//#include <net/if.h>
-//#include <qplatformdefs.h>
-
QT_BEGIN_NAMESPACE
-static QNetworkInterface::InterfaceFlags convertFlags( const TSoInetInterfaceInfo& aInfo )
+static QNetworkInterface::InterfaceFlags convertFlags(const TSoInetInterfaceInfo& aInfo)
{
QNetworkInterface::InterfaceFlags flags = 0;
flags |= (aInfo.iState == EIfUp) ? QNetworkInterface::IsUp : QNetworkInterface::InterfaceFlag(0);
// We do not have separate flag for running in Symbian OS
flags |= (aInfo.iState == EIfUp) ? QNetworkInterface::IsRunning : QNetworkInterface::InterfaceFlag(0);
- flags |= (aInfo.iFeatures&KIfCanBroadcast) ? QNetworkInterface::CanBroadcast : QNetworkInterface::InterfaceFlag(0);
- flags |= (aInfo.iFeatures&KIfIsLoopback) ? QNetworkInterface::IsLoopBack : QNetworkInterface::InterfaceFlag(0);
- flags |= (aInfo.iFeatures&KIfIsPointToPoint) ? QNetworkInterface::IsPointToPoint : QNetworkInterface::InterfaceFlag(0);
- flags |= (aInfo.iFeatures&KIfCanMulticast) ? QNetworkInterface::CanMulticast : QNetworkInterface::InterfaceFlag(0);
+ flags |= (aInfo.iFeatures & KIfCanBroadcast) ? QNetworkInterface::CanBroadcast : QNetworkInterface::InterfaceFlag(0);
+ flags |= (aInfo.iFeatures & KIfIsLoopback) ? QNetworkInterface::IsLoopBack : QNetworkInterface::InterfaceFlag(0);
+ flags |= (aInfo.iFeatures & KIfIsPointToPoint) ? QNetworkInterface::IsPointToPoint : QNetworkInterface::InterfaceFlag(0);
+ flags |= (aInfo.iFeatures & KIfCanMulticast) ? QNetworkInterface::CanMulticast : QNetworkInterface::InterfaceFlag(0);
return flags;
}
-QString qstringFromDesc( const TDesC& aData )
+QString qstringFromDesc(const TDesC& aData)
{
return QString::fromUtf16(aData.Ptr(), aData.Length());
}
static QList<QNetworkInterfacePrivate *> interfaceListing()
{
- TInt err( KErrNone );
+ TInt err(KErrNone);
QList<QNetworkInterfacePrivate *> interfaces;
-
+
// Connect to Native socket server
RSocketServ socketServ;
err = socketServ.Connect();
- if( err )
+ if (err)
return interfaces;
-
+
// Open dummy socket for interface queries
RSocket socket;
- err = socket.Open( socketServ, _L("udp"));
- if( err )
- {
+ err = socket.Open(socketServ, _L("udp"));
+ if (err) {
socketServ.Close();
- return interfaces;
+ return interfaces;
}
// Ask socket to start enumerating interfaces
- err = socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl );
- if( err )
- {
+ err = socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
+ if (err) {
socket.Close();
socketServ.Close();
- return interfaces;
- }
+ return interfaces;
+ }
int ifindex = 0;
TPckgBuf<TSoInetInterfaceInfo> infoPckg;
TSoInetInterfaceInfo &info = infoPckg();
- while( socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, infoPckg) == KErrNone )
- {
+ while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, infoPckg) == KErrNone) {
// Do not include IPv6 addresses because netmask and broadcast address cannot be determined correctly
- if( info.iName != KNullDesC && info.iAddress.IsV4Mapped() )
- {
- TName address;
- QNetworkAddressEntry entry;
- QNetworkInterfacePrivate *iface = 0;
-
- iface = new QNetworkInterfacePrivate;
+ if (info.iName != KNullDesC && info.iAddress.IsV4Mapped()) {
+ TName address;
+ QNetworkAddressEntry entry;
+ QNetworkInterfacePrivate *iface = 0;
+
+ iface = new QNetworkInterfacePrivate;
iface->index = ifindex++;
interfaces << iface;
- iface->name = qstringFromDesc( info.iName );
- iface->flags = convertFlags( info );
-
- if( /*info.iFeatures&KIfHasHardwareAddr &&*/ info.iHwAddr.Family() != KAFUnspec )
- {
- for ( TInt i = sizeof(SSockAddr); i < sizeof(SSockAddr) + info.iHwAddr.GetUserLen(); i++ )
- {
+ iface->name = qstringFromDesc(info.iName);
+ iface->flags = convertFlags(info);
+
+ if (/*info.iFeatures&KIfHasHardwareAddr &&*/ info.iHwAddr.Family() != KAFUnspec) {
+ for (TInt i = sizeof(SSockAddr); i < sizeof(SSockAddr) + info.iHwAddr.GetUserLen(); i++) {
address.AppendNumFixedWidth(info.iHwAddr[i], EHex, 2);
- if( ( i + 1) < sizeof(SSockAddr) + info.iHwAddr.GetUserLen() )
- address.Append( _L(":") );
- }
- address.UpperCase();
- iface->hardwareAddress = qstringFromDesc( address );
+ if ((i + 1) < sizeof(SSockAddr) + info.iHwAddr.GetUserLen())
+ address.Append(_L(":"));
+ }
+ address.UpperCase();
+ iface->hardwareAddress = qstringFromDesc(address);
}
-
+
// Get the address of the interface
info.iAddress.Output(address);
- entry.setIp( QHostAddress( qstringFromDesc( address ) ) );
+ entry.setIp(QHostAddress(qstringFromDesc(address)));
+
+ // Get the interface netmask
+ // For some reason netmask is always 0.0.0.0
+ // info.iNetMask.Output(address);
+ // entry.setNetmask( QHostAddress( qstringFromDesc( address ) ) );
- // Get the interface netmask
- // TODO: For some reason netmask is always 0.0.0.0
- //info.iNetMask.Output(address);
- //entry.setNetmask( QHostAddress( qstringFromDesc( address ) ) );
-
// Workaround: Let Symbian determine netmask based on IP address class
- // TODO: works only for IPv4
+ // TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
TInetAddr netmask;
- netmask.NetMask( info.iAddress );
+ netmask.NetMask(info.iAddress);
netmask.Output(address);
- entry.setNetmask( QHostAddress( qstringFromDesc( address ) ) );
-
+ entry.setNetmask(QHostAddress(qstringFromDesc(address)));
+
// Get the interface broadcast address
- if (iface->flags & QNetworkInterface::CanBroadcast)
- {
+ if (iface->flags & QNetworkInterface::CanBroadcast) {
// For some reason broadcast address is always 0.0.0.0
// info.iBrdAddr.Output(address);
- // entry.setBroadcast( QHostAddress( qstringFromDesc( address ) ) );
-
+ // entry.setBroadcast( QHostAddress( qstringFromDesc( address ) ) );
+
// Workaround: Let Symbian determine broadcast address based on IP address
- // TODO: works only for IPv4
+ // TODO: Works only for IPv4 - Task: 259128 Implement IPv6 support
TInetAddr broadcast;
- broadcast.NetBroadcast( info.iAddress );
+ broadcast.NetBroadcast(info.iAddress);
broadcast.Output(address);
- entry.setBroadcast( QHostAddress( qstringFromDesc( address ) ) );
- }
-
+ entry.setBroadcast(QHostAddress(qstringFromDesc(address)));
+ }
+
// Add new entry to interface address entries
- iface->addressEntries << entry;
-
-#if defined(QNETWORKINTERFACE_DEBUG)
- qDebug("\n Found network interface %s, interface flags:\n\
+ iface->addressEntries << entry;
+
+#if defined(QNETWORKINTERFACE_DEBUG)
+ 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\
- hwaddress = %s",
- iface->name.toLatin1().constData(),
- iface->flags & QNetworkInterface::IsUp, iface->flags & QNetworkInterface::IsRunning, iface->flags & QNetworkInterface::CanBroadcast,
- iface->flags & QNetworkInterface::IsLoopBack, iface->flags & QNetworkInterface::IsPointToPoint, iface->flags & QNetworkInterface::CanMulticast,
- entry.ip().toString().toLatin1().constData(), entry.netmask().toString().toLatin1().constData(), entry.broadcast().toString().toLatin1().constData(),
- iface->hardwareAddress.toLatin1().constData());
-#endif
+ hwaddress = %s",
+ iface->name.toLatin1().constData(),
+ iface->flags & QNetworkInterface::IsUp, iface->flags & QNetworkInterface::IsRunning, iface->flags & QNetworkInterface::CanBroadcast,
+ iface->flags & QNetworkInterface::IsLoopBack, iface->flags & QNetworkInterface::IsPointToPoint, iface->flags & QNetworkInterface::CanMulticast,
+ entry.ip().toString().toLatin1().constData(), entry.netmask().toString().toLatin1().constData(), entry.broadcast().toString().toLatin1().constData(),
+ iface->hardwareAddress.toLatin1().constData());
+#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<TSoInetRouteInfo> 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 if (entry.ip().protocol() != QAbstractSocket::IPv4Protocol) {
+ // skip if not IPv4 address (e.g. IPv6)
+ // as results not reliable on Symbian
+ 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);
+ }
+ }
+ }
+ }
+
socket.Close();
- socketServ.Close();
+ socketServ.Close();
+
return interfaces;
}