简体   繁体   English

Pcap open_live 问题

[英]Pcap open_live issue

I'm trying to debug someone else's code.我正在尝试调试其他人的代码。 I also am not a python programmer so be gentle.我也不是 python 程序员,所以要温柔。

I'm having trouble getting to call open_live in the pcap module.我无法在 pcap 模块中调用 open_live。 The traceback follows at the end.回溯在最后。 The issue is the open_live has arg list (char*, int, int, int) but in /usr/lib/python2.7/dist-packages/pcap.py the arg list is (self, *args).问题是 open_live 有 arg 列表 (char*, int, int, int) 但在 /usr/lib/python2.7/dist-packages/pcap.py 中,arg 列表是 (self, *args)。 So the arg list of what's called doesn't match what's available.因此,调用的 arg 列表与可用内容不匹配。 Not sure if this is a mismatch in versions or what.不确定这是版本不匹配还是什么。 What's going on here?这里发生了什么? Thanks,谢谢,

Sep 14 22:03:46 raspberrypi weewx[11938] ERROR weewx.engine: Import of driver failed: in method 'pcapObject_open_live', argument 2 of type 'char *' (<type 'exceptions.TypeError'>)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** Traceback (most recent call last):
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/weewx/engine.py", line 103, in setupStation
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** self.console = loader_function(config_dict, self)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/user/interceptor.py", line 225, in loader
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** return InterceptorDriver(**config_dict[DRIVER_NAME])
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/user/interceptor.py", line 2208, in init
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** self._device = self.DEVICE_TYPES.get(self._device_type)(**stn_dict)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/user/interceptor.py", line 584, in init
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** WUClient.Parser(), handler=WUClient.Handler, **stn_dict)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/user/interceptor.py", line 283, in init
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** iface, pcap_filter, promiscuous)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/share/weewx/user/interceptor.py", line 325, in init
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** self.sniffer.open_live(iface, snaplen, pval, timeout_ms)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** File "/usr/lib/python2.7/dist-packages/pcap.py", line 108, in open_live
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** def open_live(self, *args): return _pcap.pcapObject_open_live(self, *args)
Sep 14 22:03:46 raspberrypi weewx[11938] CRITICAL weewx.engine: **** TypeError: in method 'pcapObject_open_live', argument 2 of type 'char *'

The function for this follows.其功能如下。 The entire code is nearly 2700 lines.整个代码将近2700行。

        def __init__(self, iface, pcap_filter, promiscuous):
            self.running = False
            self.data_buffer = ''
            self.sniffer_type = None
            self.sniffer_version = 'unknown'
            self.sniffer = None
            snaplen = 1600
            timeout_ms = 100
            pval = 1 if weeutil.weeutil.to_bool(promiscuous) else 0
            loginf("sniff iface=%s promiscuous=%s" % (iface, pval))
            loginf("sniff filter '%s'" % pcap_filter)
            import pcap
            try:
                # try pylibpcap
                self.sniffer = pcap.pcapObject()
                self.sniffer.open_live(iface, snaplen, pval, timeout_ms)
                self.sniffer.setfilter(pcap_filter, 0, 0)
                self.sniffer_type = 'pylibpcap'
            except AttributeError:
                # try pypcap
                self.sniffer = pcap.pcap(iface, snaplen, pval)
                self.sniffer.setfilter(pcap_filter)
                self.sniffer_type = 'pypcap'
                self.sniffer_version = pcap.__version__.lower()
            loginf("%s (%s)" % (self.sniffer_type, self.sniffer_version))

What did work for me was using pypcap instead of libpcap.对我有用的是使用 pypcap 而不是 libpcap。 So uninstall the recommended "python-libpcap" and install "python-pypcap" instead.所以卸载推荐的“python-libpcap”并安装“python-pypcap”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM