fix bug in pcap

This commit is contained in:
xenia 2023-07-01 04:37:57 -04:00
parent 97f3441e58
commit b221cb4f47
1 changed files with 4 additions and 5 deletions

View File

@ -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)