I've written a custom wireless system/driver which works on top of a wifi card with packet injection and is in monitor mode. My program is based upon libpcap and uses pcap_inject
to send packets over the wireless device.
It works just fine with any amounts of incoming traffic and with 1-2 packets per second outgoing (ICMP ping). The issue, however, is that when I start trying to transmit much faster (TCP, more useful protocols at 25+ packets per second) I quickly seem to run out of buffer and my program errors out with Failed to inject packet: send: Resource temporarily unavailable
.
This doesn't make any sense to me. I know for a fact that my wireless card can transmit fast enough to handle TCP at rates of over 500Mb/s (so it's not saturating the TX ring buffer of the device) so I assume the issue lies somewhere else. Is packet injection somehow less optimized in drivers/firmware? Is libpcap just sidestepping some sort of important buffer and trying to transmit exclusively itself?
pcap
is definitely less optimized than the kernel network stack. I don't know details, but my first guess would be thatpcap
needs system calls for every single packet, and the userspace/kernelspace switch necessary for that won't allow "real use" throughput rates - after all, it's for hacking etc. At what protocol level do you need to inject packets? Can't you use the existing kernel infrastructure, and/or write a kernel module?