Monitoring the Internet connection using Symbian C++
Article Metadata
Contents |
Use case
If an application is trying to connect to the Internet, it needs to be monitored, that is, which process is trying to connect and the related information.
Headers
CommDbConnPref.h
es_enum.h
es_sock.h
rconnmon.h
Libraries
commdb.lib
esock.lib
Capability
NetworkControl
Code snippet
The following code can be used to monitor on Internet connection and display the process UID and name which is trying to connect:
RSocketServ socketServ;
RConnection connection;
TConnectionInfoBuf connInfo;
TUint count;
TConnEnumArgBuf enumArgBuf;
TConnMonClientEnum aClientEnum;
TInt err;
TConnGetClientInfoArgBuf clientInfoBuf;
socketServ.Connect();
connection.Open( socketServ );
// Enumerates currently active interfaces
if( connection.EnumerateConnections(count) == KErrNone )
{
for ( TUint j=1; j<=count; j++ )
{
enumArgBuf().iIndex = j;
if(connection.Control( KCOLConnection,
KCoEnumerateConnectionClients,
enumArgBuf ) == KErrNone )
{
for ( TUint i=1; i <= enumArgBuf().iCount; i++ )
{
clientInfoBuf().iIndex = i;
err = connection.Control( KCOLConnection,
KCoGetConnectionClientInfo,
clientInfoBuf );
if ( err != KErrNone )
{
continue;
}
TInt uid = clientInfoBuf().iClientInfo.iUid.iUid;
RProcess process;
process.Open(clientInfoBuf().iClientInfo.iProcessId );
process.Name();
TBuf<16> buf;
buf.AppendNum( uid, EHex );
CEikonEnv::InfoWinL( buf, process.Name() );
process.Close();
}
}
}
}
connection.Close();
socketServ.Close();


(no comments yet)