2 ms·
I'm the author of hexcap(http://www.hexcap.org http://www.hexcap.org), an ncurses libpcap file editor and packet generator. I've also written many Scapy applica
by smutticus 12y ago
I'm the author of hexcap(http://www.hexcap.org http://www.hexcap.org), an ncurses libpcap file editor and packet generator. I've also written many Scapy applications like this one(https://github.com/smutt/mcastClients https://github.com/smutt/mcastClients). I rewrote the DHCPv4 client in Scapy since the stock one is broken. Also as part of hexcap have made numerous fixes to dpkt. Needless to say, I've done a lot with Python and packets.
If you're interested in writing a TCP/IP stack in Python I would recommend you use Python raw sockets, or possibly dnet[1] or pcapy[2]. The Scapy level of abstraction is too high for your needs.
I agree with other posters who mention buffering in libpcap. Read the man page for pcap_dispatch to get a better idea of how buffering works in libpcap. Also try capturing packets with tcpdump with and without the '-l' switch. You'll see a big difference if your pkts/sec is low.
Don't do arp spoofing. If you're writing a TCP/IP stack then you need to also code up iparp. If you don't want to do that, then use raw sockets and query the kernel's arp cache.
On second thought you really need to use raw sockets if you want this to work. Using anything pcap based will still leave the kernel's TCP/IP stack involved, which is not what you want.
[1] http://libdnet.sourceforge.net/pydoc/private/dnet-module.html http://libdnet.sourceforge.net/pydoc/private/dnet-module.htm...
[2] http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=tool&name=Pcapy http://corelabs.coresecurity.com/index.php?module=Wiki&actio...