c# - SharpPcap Exception during Capture -
i've been trying build packet sniffer using sharppcap , packetdotnet. code far:
public static void sniffconnection() { var packets = new list<rawcapture>(); var devices = capturedevicelist.instance; pcapdevice device = null; foreach (var dev in devices) { if (((libpcaplivedevice)dev).interface.friendlyname.equals("wi-fi 3")) { device = (libpcaplivedevice)dev; break; } } try { //open device capturing device.open(devicemode.promiscuous); } catch (exception e) { console.writeline(e.message); return; } //register our handler function 'packet arrival' event device.onpacketarrival += (sender, packets_storage) => packetarrivalhandler(sender, ref packets); console.writeline("sniffing..."); try { device.capture(); } catch (system.accessviolationexception e) { console.writeline(e); } catch (exception e) { console.writeline(e); } device.close(); console.readline(); } public static void packetarrivalhandler(object sender, ref list<rawcapture> packets) { var dev = (winpcapdevice)sender; rawcapture p = dev.getnextpacket(); if (p != null) { var raw_packet = packet.parsepacket(p.linklayertype, p.data); // split packet layers check data in layers valid var tcppacket = (tcppacket)raw_packet.extract(typeof(tcppacket)); var ippacket = (ippacket)raw_packet.extract(typeof(ippacket)); packets.add(p); } }
after few packets captured, capture function throws exception, memory. (access violation, out of memory, overflow) idea what's causing , how solve this? (when out of memory or overflow exceptions thrown, says it's in sharppcap.libpcap.pcapdevice.marshalrawpacket function, when access violation thrown, says it's happenning in dll thats not related code directly)
Comments
Post a Comment