wpcCapture.cpp
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <wpcobj.h>
#ifdef WIN32
#include <ipHlpApi.h>
#endif //WIN32
int main(int argc, char* argv[])
{
string filter = "host ";
string dump;
int count;
int maxCount = 10;
WpcPacket pkt;
try {
if (argc < 2) {
printf("Usage: %s <target> [<num of packets>]\n\n", argv[0]);
return -1;
}
WpcAdapter adapt = WpcGetBestAdapter(argv[1]);
printf("Found suitable adapter: %s\n", adapt.GetIfaceDesc().c_str());
filter += argv[1];
adapt.StartCapture(filter);
if (argc > 2) {
maxCount = atoi(argv[2]);
}
for (count = 0; count < maxCount;) {
if (adapt.ReadPacket(pkt)) {
dump = pkt.Dump();
printf("Packet #%d\n%s\n", count++, dump.c_str());
}
}
adapt.StopCapture();
}
catch (...) {
printf("Something strange happens! Exiting...\n");
}
return 0;
}