擅长:python、mysql、java
<p>数据类型很重要。在</p>
<p>您需要告诉ctypes,<code>pcap_create()</code>的返回值是一个指针,并且您需要告诉它<code>pcap_can_set_rfmon()</code>的参数是一个指针。在</p>
<p>你这样做</p>
<pre><code># create handler
pcap_create = _pcap.pcap_create
pcap_create.restype = ctypes.c_void_p
handle = pcap_create(dev, errbuf)
print handle
if not handle:
print "failed creating handler:",errbuf
exit()
# monitor mode
pcap_can_set_rfmon = _pcap.pcap_can_set_rfmon
pcap_can_set_rfmon.argtypes = [ctypes.c_void_p]
print "can rfmon:",pcap_can_set_rfmon(handle)
</code></pre>
<p>在</p>
^{pr2}$
<p>以及</p>
<pre><code>pcap_can_set_rfmon.argtypes = [ctypes.c_void_p]
</code></pre>
<p>这里需要行。此代码将同时使用32位和64位指针,因此您可以在32位和64位Linux、32位和64位OS X(以及32位和64位Solaris、32位和64位FreeBSD和…)上使用它,只要对代码进行任何更改就可以加载库-在大多数Un*xes上,共享库的名称都以“.so”结尾,因此,如果您不想在其他Un*xes上使用<code>find_library</code>,那么Linux代码就足够了)。在</p>