PPC下如何获取GPRS的网络流量
2010-08-22 12:43:00 来源:WEB开发网PDA/PPC设备上,GPRS上网的途径有两种:通过Modem拨号和通过WI-FI无线上网,前者一般用在PDA/PPC和电脑间的,使用数据线、红外线、蓝牙等连接途径与电脑相连,拨号上网;
通过WI-FI无线上网则是手机直接上网。在PDA/PPC下,网络流量的统计和其他WINDOWS平台并没有太大区别,最简单的方法就是通过微软的IPHELPER API,其他的方法有通过NDISUIO
用CreateFile打开"UIO0:",,DeviceIoControl实现对网卡的枚举,绑定等工作或是用SPI等应用层(使用SPI在Windows CE/Mobile上实现网络防火墙的例子代码)。
int GetTraffic(void)
{
DWORD dwSize = 0;
DWORD dwRetVal = 0;
int i = 0;
int j = 0;
MIB_IFTABLE *pIfTable;
MIB_IFROW *pIfRow;
// Allocate memory for our pointers.
pIfTable = (MIB_IFTABLE *) MALLOC(sizeof (MIB_IFTABLE));
if (pIfTable == NULL)
{
return 0;
}
// Make an initial call to GetIfTable to get the
// necessary size into dwSize
dwSize = sizeof (MIB_IFTABLE);
if (GetIfTable(pIfTable, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
{
FREE(pIfTable);
pIfTable = (MIB_IFTABLE *) MALLOC(dwSize);
if (pIfTable == NULL)
{
return 0;
}
}
// Make a second call to GetIfTable to get the actual
// data we want.
if ((dwRetVal = GetIfTable(pIfTable, &dwSize, FALSE)) == NO_ERROR)
{
for (i = 0; i < (int) pIfTable->dwNumEntries; i++)
{
pIfRow = (MIB_IFROW *) & pIfTable->table[i];
if ((pIfRow->dwType == IF_TYPE_ETHERNET_CSMACD) || (pIfRow->dwType == IF_TYPE_PPP))//以太网
{
m_lConnection = TRUE;
if (strstr(Descr,"cmwap") || strstr(Descr,"cmnet"))//接入点是cmwap
{
{
sprintf(m_sNowTraffic,"%1.2f",pIfRow->dwInOctets / 1024.0);//现在的流量
更多精彩
赞助商链接