×
Namespaces

Variants
Actions

监控互联网连接

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
hoolee
最后由 hamishwillee 在 06 Aug 2012 编辑

TSS001000


  • 开发伙伴平台:


  • 详细描述

如果一个程序试图来连接互联网,它需要被监控起来,即哪个进程正在试图连接,以及获得相关信息。


Contents

头文件

CommDbConnPref.h
es_enum.h
es_sock.h
rconnmon.h


链接库

commdb.lib
esock.lib


能力

NetworkControl


代码片段

下列代码用来监控互联网连接,并在试图连接时显示进程ID和名称:

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();
This page was last modified on 6 August 2012, at 09:20.
38 page views in the last 30 days.