00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #define WIN32_LEAN_AND_MEAN
00014
00015 #ifndef _WIN32_WINNT
00016 #define _WIN32_WINNT 0x0400
00017 #endif
00018
00019 #include <atlbase.h>
00020 #include <stdio.h>
00021 #include <time.h>
00022
00023 #import "PacketX.dll" no_namespace, named_guids
00024
00025 static HRESULT __Stats_Handler__(IPktXStatistics* pStats,DWORD dwParam);
00026
00027 int main(int argc, char* argv[])
00028 {
00029
00030 #define MT_APARTMENT
00031 #ifdef MT_APARTMENT
00032 _S(CoInitializeEx(NULL,COINIT_MULTITHREADED));
00033 #else
00034 _S(CoInitialize(NULL));
00035 #endif
00036
00037
00038 IPktXPacketXPtr pPktX(__uuidof(PacketX));
00039
00040
00041 LONG lCount= IPktXAdapterCollectionPtr(pPktX->GetAdapters())->GetCount();
00042 for (int i=0; i < lCount; i++)
00043 {
00044
00045 IPktXAdapterPtr pAdapter = IPktXAdapterCollectionPtr(pPktX->GetAdapters())->GetItem(i+1);
00046 if (pAdapter->GetIsGood())
00047 {
00048 _bstr_t bstrtDesciption = pAdapter->GetDescription();
00049 printf("(%d) %s\n",i+1,(char*)bstrtDesciption);
00050 }
00051 }
00052
00053 pPktX->PutAdapter(NULL);
00054 while (pPktX->GetAdapter() == NULL)
00055 {
00056 char buffer[256];
00057 printf("Choose adapter#");
00058 try { pPktX->PutAdapter(IPktXAdapterCollectionPtr(
00059 pPktX->GetAdapters())->GetItem(atoi(gets(buffer)))); }
00060 catch ( _com_error& ) {}
00061 }
00062
00063 IPktXAdapterPtr(pPktX->GetAdapter())->PutMode(PktXModeStatistics);
00064 IPktXAdapterPtr(pPktX->GetAdapter())->PutReadTimeout(2000);
00065
00066
00067 IPktXPacketSinkPtr pSink(__uuidof(PacketSink));
00068 pSink.CreateInstance(__uuidof(PacketSink));
00069 pSink->CallBackOnStatistics((DWORD)__Stats_Handler__,(DWORD)0);
00070
00071
00072 pSink->Advise(pPktX);
00073
00074
00075 pPktX->Start();
00076
00077 #ifdef MT_APARTMENT
00078 Sleep(60000);
00079 #else
00080
00081 MSG msg;
00082 while (GetMessage(&msg, 0, 0, 0) && lEventCounter <= lNumOfEvents)
00083 DispatchMessage(&msg);
00084 #endif
00085
00086
00087 pPktX->Stop();
00088
00089
00090 pSink->Unadvise(pPktX);
00091
00092
00093 pSink = NULL;
00094 pPktX = NULL;
00095
00096
00097 CoUninitialize();
00098 return 0;
00099 }
00100
00101
00102 static HRESULT __Stats_Handler__(IPktXStatistics* pStats,DWORD dwParam)
00103 {
00104
00105 time_t ltime = IPktXStatisticsPtr(pStats)->GetTimeSec();
00106
00107
00108 printf("Pkts %d Bytes %d %s",
00109 IPktXStatisticsPtr(pStats)->GetPackets(),
00110 IPktXStatisticsPtr(pStats)->GetBytes(), ctime(<ime));
00111 return 0;
00112 }