[Winpcap-users] Access violation when using pcap_findalldevs_ex
Виталик Rasta
johanga at sibmail.com
Fri Aug 15 04:01:36 GMT 2008
Hello, everyone!
I have an access violation error when using pcap_findalldevs_ex. I use
Microsoft
Visual studio 2005 and winpcap 4.0.2 on WinXP Professional SP2.
There are no errors when I use pcap_finalldevs_ex in other functions.
Error occurs just in send_packet function.
I don't understand where is the mistake. Please, help me!
I know exactly that error is when pcap_findalldevs_ex runs (I used
F10, F11)
here is the code:
bool send_packet(u_char *data, int size)
{
pcap_if_t *alldev=NULL;
pcap_if_t *dev;
pcap_t *handle;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldev, errbuf)
== -1) {
std::cout << "Cannot get interface list : " << errbuf <<
"\n";
return false;
}
dev = alldev->next;
if (dev == NULL) {
std::cout << "Cannot find an interface \n";
pcap_freealldevs(alldev);
return false;
}
handle = pcap_open(dev->name, PCAP_PACKET_PORTION,
PCAP_OPENFLAG_PROMISCUOUS, PCAP_READ_TIMEOUT, NULL, errbuf);
if (handle == NULL) {
std::cout << "Cannot open an interface : " << errbuf << "\n";
pcap_freealldevs(alldev);
return false;
}
if (pcap_datalink(handle) != DLT_EN10MB) {
std::cout << "This program works only on Ethernet
networks\n";
pcap_freealldevs(alldev);
return false;
}
if (pcap_sendpacket(handle, data, size) != 0) {
std::cout << "Error sending packet : " <<
pcap_geterr(handle) << "\n";
pcap_freealldevs(alldev);
return false;
}
pcap_freealldevs(alldev);
return true;
}
--
Best wishes!
Vitaly mailto:johanga at sibmail.com
More information about the Winpcap-users
mailing list