From b221cb4f47f0576aaa2072f2c0fc9a554f1d9ae0 Mon Sep 17 00:00:00 2001 From: haskal Date: Sat, 1 Jul 2023 04:37:57 -0400 Subject: [PATCH] fix bug in pcap --- python/pcap/memecap.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python/pcap/memecap.py b/python/pcap/memecap.py index 2475512..41e8b3e 100644 --- a/python/pcap/memecap.py +++ b/python/pcap/memecap.py @@ -32,9 +32,6 @@ PCAP_SNAPLEN = 2048 LINKTYPE_ETHERNET = 1 async def do_pcap(devname="wlp2s0", pcapname="capture.pcap"): - if isinstance(devname, str): - devname = devname.encode() - loop = asyncio.get_event_loop() if not isinstance(loop, asyncio.selector_events.BaseSelectorEventLoop): raise Exception("you gotta run it on linux") @@ -44,11 +41,13 @@ async def do_pcap(devname="wlp2s0", pcapname="capture.pcap"): sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_IP)) sock.setblocking(False) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, devname) + # sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, devname) + # NO htons on this call + sock.bind((devname, ETH_P_IP)) logger.info("setting promisc mode") ifr = ifreq() - ifr.ifr_ifrn = devname + ifr.ifr_ifrn = devname.encode() fcntl.ioctl(sock.fileno(), SIOCGIFFLAGS, ifr) ifr.ifr_flags |= IFF_PROMISC fcntl.ioctl(sock.fileno(), SIOCSIFFLAGS, ifr)