Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch not working #63

Open
havihu opened this issue Sep 8, 2019 · 1 comment
Open

dispatch not working #63

havihu opened this issue Sep 8, 2019 · 1 comment

Comments

@havihu
Copy link

havihu commented Sep 8, 2019

Hi,
im trying to capture packets and im using open_live(timeout 0) with dispatch instead of next, and I dont know why but its sniffing only a few packets and then close pip.
my code:

import pcapy
import threading
import time
from pcapy import open_live, PcapError

def parse_eth_packet_hndlr(header, packet):
print('header len:%s\n'%header.getlen())

def start():
try:
packets_reader = open_live('eth2', 200, 0, 0)
except PcapError as e:
if 'That device is not up' in str(e):
logging.debug(e)
return None
try:
print('Try to start capturing packets')
packets_reader.dispatch(-1, parse_eth_packet_hndlr)
except PcapError as e:
return

if name == 'main':
start()

pcapy version:pcapy-0.11.5.dev0
python version: 2.7
please advice

@N7-Revenant
Copy link

N7-Revenant commented Oct 3, 2019

Hi,
as far as I know, this is expected behaviour: while next process single packet, dispatch allows you to run a callback for all currently available packets, and then it returns. So you need to add a cycle around dispatch call, a while loop for example:

while condition:
    packets_reader.dispatch(-1, parse_eth_packet_hndlr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants