I'm able to do most everything in the PCap library successfully, except install this callback function. The line I bolded in the code below is where my program just freezes at. However, I tried using this same code in a console application, and it worked just fine. What's the deal?
Stack trace:Code:void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{
return;
}
void RawPacket::SetupFilter(pcap_if_t* Device)
{
char Error[256];
struct bpf_program fp;
char filter_exp[] = "src net 128.0.27.111";
bpf_u_int32 mask;
bpf_u_int32 net;
if (pcap_lookupnet(Device->name, &net, &mask, Error) == -1) {
fprintf(stderr, "Can't get netmask for device %s\n", Device->name);
net = 0;
mask = 0;
}
handle = pcap_open_live(Device->name, BUFSIZ, FALSE, 1000, Error);
if(!handle) {
fprintf(stderr, "Couldn't open device %s: %s\n", Device->name, Error);
return;
}
if (pcap_datalink(handle) != DLT_EN10MB) {
fprintf(stderr, "%s is not an Ethernet\n", Device->name);
return;
}
if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
return;
}
if (pcap_setfilter(handle, &fp) == -1) {
fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
return;
}
if (pcap_loop(handle, 10, got_packet, NULL) == -1) {
fprintf(stderr, "Couldn't install callback: %s\n", pcap_geterr(handle));
return;
}
pcap_freecode(&fp);
pcap_close(handle);
filterSetup = true;
}
ntdll.dll!7d61c846()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
kernel32.dll!7d4d8c9e()
kernel32.dll!7d4d8c0d()
Packet.dll!00d23c3a()
wpcap.dll!10016810()
> UDP Packet Test.exe!RawPacket::SetupFilter(pcap_if * Device) Line 359 + 0x14 bytes C++

