I have received a task in recent days and want to build a GPRS traffic statistics software under wince 6.0. Because I have never touched this aspect before, it is a headache and I have no idea at all, however, after several days of searching online, I found two solutions.
The first is to use the Windows IP helper related functions, which are in the iphlpapi. dll. If you are more accustomed to static calls, you can find the iphlpapi. h and iphlpapi. Lib in your SDK. It can be used in your project.
The second is to use raw socket. Calculate the data packet size one by one.
First, let's look at the first one. If you use dynamic calling, you need to define two structures. For detailed descriptions of these two structures, we can find them on msdn.
Http://msdn.microsoft.com/en-us/library/aa366836 (V = vs.85). aspx
Typedef struct _ mib_ifrow
{
Wchar wszname [max_interface_name_len];
DWORD dwindex;
DWORD dwtype;
DWORD dwmtu;
DWORD dwspeed;
DWORD dwphysaddrlen;
Byte bphysaddr [maxlen_physaddr];
DWORD dwadminstatus;
DWORD dwoperstatus;
DWORD dwlastchange;
DWORD dwinoctets;
DWORD dwinucastpkts;
DWORD dwinnucastpkts;
DWORD dwindiscards;
DWORD dwinerrors;
DWORD dwinunknownprotos;
DWORD dwoutoctets;
DWORD dwoutucastpkts;
DWORD dwoutnucastpkts;
DWORD dwoutdiscards;
DWORD dwouterrors;
DWORD dwoutqlen;
DWORD dwdescrlen;
Byte bdescr [maxlen_ifdescr];
} Mib_ifrow, * pmib_ifrow;
Typedef struct _ mib_iftable
{
DWORD dwnumentries; // connection format
Mib_ifrow table [any_size]; // connection information
} Mib_iftable, * pmib_iftable;
Then define the variable
Mib_ifrow * pifrow;
# Define max_interface_name_len 256
# Define maxlen_physaddr 8
# Define maxlen_ifdescr 256
# Define any_size 1
Then, call the getiftable function of the lplpapi to fill up the data structure. Note that getiftable must be called twice. The size must be determined for the first time before the second operation can be correctly filled.
If (lpgtiftable (pmit, & dwsize, 0) = error_insufficient_buffer)
{
Delete [] pmit;
Pmit = new mib_iftable [dwsize];
}
// Dwnumentries alwayse> = 1, and the last entry is loopback interface.
If (lpgtiftable (pmit, & dwsize, 0) = no_error)
{
For (INT I = 0; I <(INT) pmit-> dwnumentries; I ++)
{
Pifrow = (mib_ifrow *) & pmit-> table [I];
}
}
Next, you can determine which connection information is needed based on the content in the pifrow and process the information.