pax_global_header00006660000000000000000000000064127063662660014530gustar00rootroot0000000000000052 comment=e69c7cbb944efbb733b2c5fd48bba6af90ae6d46 pypcap-1.1.5/000077500000000000000000000000001270636626600130305ustar00rootroot00000000000000pypcap-1.1.5/AUTHORS000066400000000000000000000001041270636626600140730ustar00rootroot00000000000000 Dug Song Bartosz Skowron pypcap-1.1.5/CHANGES000066400000000000000000000020311270636626600140170ustar00rootroot00000000000000pypcap-1.1.5: - fix for immediate mode on linux (#12) pypcap-1.1.4: - fix for immediate mode on Mac OS X 10.10 pypcap-1.1.3: - minor bugfixing pypcap-1.1.2: - setdirection() support - from Eddi Linder - make it possible to install without pyrex pypcap-1.1.1: - honor 'immediate' flag to disable buffering under Windows - by Kosma Moczek - sendpacket() support - by Kosma Moczek - API CHANGE: require 'cnt' as first parameter to pcap.loop() - by Bartosz Skowron - lookupnet() support - from Joao Medeiros - findalldevs() support - by Bartosz Skowron - better support for installing on Fedora, Ubuntu and Mac OS X pypcap-1.1: - better lookupdev() on win32, as requested by Zack Payton - add Linux SLL datalink type - better threading support from A. Nonymous pypcap-1.0: - API CHANGE: require 'cnt' as first parameter to pcap.dispatch(), shadowing libpcap pcap_dispatch(). - add pcap.{get,set}nonblock(), to work around broken BPF select() on certain platforms (MacOS X, older FreeBSD, etc.). # $Id$ pypcap-1.1.5/LICENSE000066400000000000000000000026271270636626600140440ustar00rootroot00000000000000 Copyright (c) 2004 Dug Song All rights reserved, all wrongs reversed. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors and copyright holders may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pypcap-1.1.5/MANIFEST.in000066400000000000000000000000221270636626600145600ustar00rootroot00000000000000include pcap_ex.h pypcap-1.1.5/README000066400000000000000000000006771270636626600137220ustar00rootroot00000000000000Python pcap module ------------------ This is a simplified object-oriented Python wrapper for libpcap - the current tcpdump.org version, and the WinPcap port for Windows. example use: >>> import pcap >>> for ts, pkt in pcap.pcap(): ... print ts, `pkt` ... Install -------- This package requires: * libpcap-dev * python-dev To install run:: pip install pypcap Support ------- Visit https://github.com/pynetwork/pypcap for help! pypcap-1.1.5/pcap.c000066400000000000000000010521751270636626600141320ustar00rootroot00000000000000/* Generated by Cython 0.21.2 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS #ifdef PYLONG_BITS_IN_DIGIT #define CYTHON_USE_PYLONG_INTERNALS 0 #else #include "pyconfig.h" #ifdef PYLONG_BITS_IN_DIGIT #define CYTHON_USE_PYLONG_INTERNALS 1 #else #define CYTHON_USE_PYLONG_INTERNALS 0 #endif #endif #endif #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) #error Cython requires Python 2.6+ or Python 3.2+. #else #define CYTHON_ABI "0_21_2" #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyType_Type #endif #if PY_MAJOR_VERSION >= 3 #define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_HAVE_INDEX 0 #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE) #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #define __Pyx_PyFrozenSet_Size(s) PyObject_Size(s) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #define __Pyx_PyFrozenSet_Size(s) PySet_Size(s) #endif #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #ifndef CYTHON_INLINE #if defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is a quiet NaN. */ float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #ifdef __cplusplus template void __Pyx_call_destructor(T* x) { x->~T(); } #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #define __PYX_HAVE__pcap #define __PYX_HAVE_API__pcap #include "pcap.h" #include "pcap_ex.h" #ifdef _OPENMP #include #endif /* _OPENMP */ #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_fits_Py_ssize_t(v, type, is_signed) ( \ (sizeof(type) < sizeof(Py_ssize_t)) || \ (sizeof(type) > sizeof(Py_ssize_t) && \ likely(v < (type)PY_SSIZE_T_MAX || \ v == (type)PY_SSIZE_T_MAX) && \ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN || \ v == (type)PY_SSIZE_T_MIN))) || \ (sizeof(type) == sizeof(Py_ssize_t) && \ (is_signed || likely(v < (type)PY_SSIZE_T_MAX || \ v == (type)PY_SSIZE_T_MAX))) ) static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromUString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromUString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromUString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((const char*)s) #if PY_MAJOR_VERSION < 3 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #else #define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen #endif #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_COMPILING_IN_CPYTHON #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "pcap.pyx", }; /*--- Type declarations ---*/ struct __pyx_obj_4pcap_bpf; struct __pyx_obj_4pcap_pcap; struct __pyx_t_4pcap_pcap_handler_ctx; /* "pcap.pyx":52 * char *name * * ctypedef void (*pcap_handler)(void *arg, pcap_pkthdr *hdr, char *pkt) # <<<<<<<<<<<<<< * * cdef extern from "pcap.h": */ typedef void (*__pyx_t_4pcap_pcap_handler)(void *, struct pcap_pkthdr *, char *); /* "pcap.pyx":98 * void free(void *ptr) * * cdef struct pcap_handler_ctx: # <<<<<<<<<<<<<< * void *callback * void *args */ struct __pyx_t_4pcap_pcap_handler_ctx { void *callback; void *args; int got_exc; }; /* "pcap.pyx":147 * DLT_LOOP:4, DLT_RAW:0, DLT_LINUX_SLL:16 } * * cdef class bpf: # <<<<<<<<<<<<<< * """bpf(filter, dlt=DLT_RAW) -> BPF filter object""" * cdef bpf_program fcode */ struct __pyx_obj_4pcap_bpf { PyObject_HEAD struct bpf_program fcode; }; /* "pcap.pyx":165 * pcap_freecode(&self.fcode) * * cdef class pcap: # <<<<<<<<<<<<<< * """pcap(name=None, snaplen=65535, promisc=True, timeout_ms=None, immediate=False) -> packet capture object * */ struct __pyx_obj_4pcap_pcap { PyObject_HEAD pcap_t *__pyx___pcap; char *__pyx___name; char *__pyx___filter; char __pyx___ebuf[256]; int __pyx___dloff; }; #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil) \ if (acquire_gil) { \ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ PyGILState_Release(__pyx_gilstate_save); \ } else { \ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil) \ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext() \ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do { \ PyObject *tmp = (PyObject *) r; \ r = v; __Pyx_XDECREF(tmp); \ } while (0) #define __Pyx_DECREF_SET(r, v) do { \ PyObject *tmp = (PyObject *) r; \ r = v; __Pyx_DECREF(tmp); \ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif static PyObject *__Pyx_GetBuiltinName(PyObject *name); #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename, int full_traceback); static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i)))) #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \ __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \ (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { PyListObject* L = (PyListObject*) list; Py_ssize_t len = Py_SIZE(list); if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { Py_INCREF(x); PyList_SET_ITEM(list, len, x); Py_SIZE(list) = len+1; return 0; } return PyList_Append(list, x); } #else #define __Pyx_PyList_Append(L,x) PyList_Append(L,x) #endif #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); #endif static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #else #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif typedef struct { int code_line; PyCodeObject* code_object; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value); static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); static int __Pyx_check_binary_version(void); static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /* Module declarations from 'pcap' */ static PyTypeObject *__pyx_ptype_4pcap_bpf = 0; static PyTypeObject *__pyx_ptype_4pcap_pcap = 0; static void __pyx_f_4pcap___pcap_handler(void *, struct pcap_pkthdr *, char *); /*proto*/ #define __Pyx_MODULE_NAME "pcap" int __pyx_module_is_main_pcap = 0; /* Implementation of 'pcap' */ static PyObject *__pyx_builtin_IOError; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_KeyboardInterrupt; static PyObject *__pyx_builtin_StopIteration; static int __pyx_pf_4pcap_3bpf___init__(struct __pyx_obj_4pcap_bpf *__pyx_v_self, char *__pyx_v_filter, PyObject *__pyx_v_dlt); /* proto */ static PyObject *__pyx_pf_4pcap_3bpf_2filter(struct __pyx_obj_4pcap_bpf *__pyx_v_self, PyObject *__pyx_v_buf); /* proto */ static void __pyx_pf_4pcap_3bpf_4__dealloc__(struct __pyx_obj_4pcap_bpf *__pyx_v_self); /* proto */ static int __pyx_pf_4pcap_4pcap___init__(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_snaplen, PyObject *__pyx_v_promisc, PyObject *__pyx_v_timeout_ms, PyObject *__pyx_v_immediate); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_4name___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_7snaplen___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_5dloff___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_6filter___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_2fd___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_2fileno(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_4setfilter(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_value, PyObject *__pyx_v_optimize); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_6setdirection(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_direction); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_8setnonblock(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_nonblock); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_10getnonblock(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_12datalink(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_14__add_pkts(CYTHON_UNUSED struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_ts, PyObject *__pyx_v_pkt, PyObject *__pyx_v_pkts); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_16readpkts(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_18dispatch(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_cnt, PyObject *__pyx_v_callback, PyObject *__pyx_v_args); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_20loop(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_cnt, PyObject *__pyx_v_callback, PyObject *__pyx_v_args); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_22sendpacket(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_buf); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_24geterr(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_26stats(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_28__iter__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_4pcap_30__next__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static void __pyx_pf_4pcap_4pcap_32__dealloc__(struct __pyx_obj_4pcap_pcap *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4pcap_ex_name(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_foo); /* proto */ static PyObject *__pyx_pf_4pcap_2lookupdev(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_4pcap_4findalldevs(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_4pcap_6lookupnet(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_dev); /* proto */ static PyObject *__pyx_tp_new_4pcap_bpf(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_4pcap_pcap(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static char __pyx_k_I[] = "I"; static char __pyx_k_p[] = "p"; static char __pyx_k__2[] = ""; static char __pyx_k_ts[] = "ts"; static char __pyx_k_1_1[] = "1.1"; static char __pyx_k_cnt[] = "cnt"; static char __pyx_k_dev[] = "dev"; static char __pyx_k_dlt[] = "dlt"; static char __pyx_k_foo[] = "foo"; static char __pyx_k_pkt[] = "pkt"; static char __pyx_k_sys[] = "sys"; static char __pyx_k_url[] = "__url__"; static char __pyx_k_curr[] = "curr"; static char __pyx_k_devs[] = "devs"; static char __pyx_k_ebuf[] = "ebuf"; static char __pyx_k_find[] = "find"; static char __pyx_k_main[] = "__main__"; static char __pyx_k_name[] = "name"; static char __pyx_k_netp[] = "netp"; static char __pyx_k_pack[] = "pack"; static char __pyx_k_pcap[] = "pcap"; static char __pyx_k_pkts[] = "pkts"; static char __pyx_k_test[] = "__test__"; static char __pyx_k_maskp[] = "maskp"; static char __pyx_k_value[] = "value"; static char __pyx_k_append[] = "append"; static char __pyx_k_author[] = "__author__"; static char __pyx_k_dltoff[] = "dltoff"; static char __pyx_k_filter[] = "filter"; static char __pyx_k_import[] = "__import__"; static char __pyx_k_retval[] = "retval"; static char __pyx_k_status[] = "status"; static char __pyx_k_struct[] = "struct"; static char __pyx_k_DLT_PPP[] = "DLT_PPP"; static char __pyx_k_DLT_RAW[] = "DLT_RAW"; static char __pyx_k_IOError[] = "IOError"; static char __pyx_k_OSError[] = "OSError"; static char __pyx_k_ex_name[] = "ex_name"; static char __pyx_k_license[] = "__license__"; static char __pyx_k_openbsd[] = "openbsd"; static char __pyx_k_promisc[] = "promisc"; static char __pyx_k_snaplen[] = "snaplen"; static char __pyx_k_version[] = "__version__"; static char __pyx_k_DLT_AX25[] = "DLT_AX25"; static char __pyx_k_DLT_FDDI[] = "DLT_FDDI"; static char __pyx_k_DLT_LOOP[] = "DLT_LOOP"; static char __pyx_k_DLT_NULL[] = "DLT_NULL"; static char __pyx_k_DLT_SLIP[] = "DLT_SLIP"; static char __pyx_k_KeyError[] = "KeyError"; static char __pyx_k_add_pkts[] = "__add_pkts"; static char __pyx_k_callback[] = "callback"; static char __pyx_k_dispatch[] = "dispatch"; static char __pyx_k_exc_info[] = "exc_info"; static char __pyx_k_nonblock[] = "nonblock"; static char __pyx_k_optimize[] = "optimize"; static char __pyx_k_platform[] = "platform"; static char __pyx_k_DLT_CHAOS[] = "DLT_CHAOS"; static char __pyx_k_DLT_EN3MB[] = "DLT_EN3MB"; static char __pyx_k_DLT_PFLOG[] = "DLT_PFLOG"; static char __pyx_k_PCAP_D_IN[] = "PCAP_D_IN"; static char __pyx_k_TypeError[] = "TypeError"; static char __pyx_k_copyright[] = "__copyright__"; static char __pyx_k_immediate[] = "immediate"; static char __pyx_k_lookupdev[] = "lookupdev"; static char __pyx_k_lookupnet[] = "lookupnet"; static char __pyx_k_DLT_ARCNET[] = "DLT_ARCNET"; static char __pyx_k_DLT_EN10MB[] = "DLT_EN10MB"; static char __pyx_k_DLT_PFSYNC[] = "DLT_PFSYNC"; static char __pyx_k_DLT_PRONET[] = "DLT_PRONET"; static char __pyx_k_PCAP_D_OUT[] = "PCAP_D_OUT"; static char __pyx_k_bad_filter[] = "bad filter"; static char __pyx_k_timeout_ms[] = "timeout_ms"; static char __pyx_k_BSD_license[] = "BSD license"; static char __pyx_k_DLT_IEEE802[] = "DLT_IEEE802"; static char __pyx_k_findalldevs[] = "findalldevs"; static char __pyx_k_PCAP_D_INOUT[] = "PCAP_D_INOUT"; static char __pyx_k_DLT_LINUX_SLL[] = "DLT_LINUX_SLL"; static char __pyx_k_StopIteration[] = "StopIteration"; static char __pyx_k_KeyboardInterrupt[] = "KeyboardInterrupt"; static char __pyx_k_root_pypcap_pcap_pyx[] = "/root/pypcap/pcap.pyx"; static char __pyx_k_Copyright_c_2004_Dug_Song[] = "Copyright (c) 2004 Dug Song"; static char __pyx_k_Dug_Song_dugsong_monkey_org[] = "Dug Song "; static char __pyx_k_Current_packet_capture_filter[] = "Current packet capture filter."; static char __pyx_k_couldn_t_enable_immediate_mode[] = "couldn't enable immediate mode"; static char __pyx_k_http_monkey_org_dugsong_pypcap[] = "http://monkey.org/~dugsong/pypcap/"; static char __pyx_k_Datalink_offset_length_of_layer[] = "Datalink offset (length of layer-2 frame header)."; static char __pyx_k_File_descriptor_or_Win32_HANDLE[] = "File descriptor (or Win32 HANDLE) for capture handle."; static char __pyx_k_Maximum_number_of_bytes_to_captu[] = "Maximum number of bytes to capture for each packet."; static char __pyx_k_Network_interface_or_dumpfile_na[] = "Network interface or dumpfile name."; static char __pyx_k_packet_capture_library_This_modu[] = "packet capture library\n\nThis module provides a high level interface to packet capture systems.\nAll packets on the network, even those destined for other hosts, are\naccessible through this mechanism.\n"; static PyObject *__pyx_kp_s_1_1; static PyObject *__pyx_kp_s_BSD_license; static PyObject *__pyx_kp_s_Copyright_c_2004_Dug_Song; static PyObject *__pyx_n_s_DLT_ARCNET; static PyObject *__pyx_n_s_DLT_AX25; static PyObject *__pyx_n_s_DLT_CHAOS; static PyObject *__pyx_n_s_DLT_EN10MB; static PyObject *__pyx_n_s_DLT_EN3MB; static PyObject *__pyx_n_s_DLT_FDDI; static PyObject *__pyx_n_s_DLT_IEEE802; static PyObject *__pyx_n_s_DLT_LINUX_SLL; static PyObject *__pyx_n_s_DLT_LOOP; static PyObject *__pyx_n_s_DLT_NULL; static PyObject *__pyx_n_s_DLT_PFLOG; static PyObject *__pyx_n_s_DLT_PFSYNC; static PyObject *__pyx_n_s_DLT_PPP; static PyObject *__pyx_n_s_DLT_PRONET; static PyObject *__pyx_n_s_DLT_RAW; static PyObject *__pyx_n_s_DLT_SLIP; static PyObject *__pyx_kp_s_Dug_Song_dugsong_monkey_org; static PyObject *__pyx_n_s_I; static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_n_s_KeyboardInterrupt; static PyObject *__pyx_n_s_OSError; static PyObject *__pyx_n_s_PCAP_D_IN; static PyObject *__pyx_n_s_PCAP_D_INOUT; static PyObject *__pyx_n_s_PCAP_D_OUT; static PyObject *__pyx_n_s_StopIteration; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_add_pkts; static PyObject *__pyx_n_s_append; static PyObject *__pyx_n_s_author; static PyObject *__pyx_kp_s_bad_filter; static PyObject *__pyx_n_s_callback; static PyObject *__pyx_n_s_cnt; static PyObject *__pyx_n_s_copyright; static PyObject *__pyx_kp_s_couldn_t_enable_immediate_mode; static PyObject *__pyx_n_s_curr; static PyObject *__pyx_n_s_dev; static PyObject *__pyx_n_s_devs; static PyObject *__pyx_n_s_dispatch; static PyObject *__pyx_n_s_dlt; static PyObject *__pyx_n_s_dltoff; static PyObject *__pyx_n_s_ebuf; static PyObject *__pyx_n_s_ex_name; static PyObject *__pyx_n_s_exc_info; static PyObject *__pyx_n_s_filter; static PyObject *__pyx_n_s_find; static PyObject *__pyx_n_s_findalldevs; static PyObject *__pyx_n_s_foo; static PyObject *__pyx_kp_s_http_monkey_org_dugsong_pypcap; static PyObject *__pyx_n_s_immediate; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_license; static PyObject *__pyx_n_s_lookupdev; static PyObject *__pyx_n_s_lookupnet; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_maskp; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_netp; static PyObject *__pyx_n_s_nonblock; static PyObject *__pyx_n_s_openbsd; static PyObject *__pyx_n_s_optimize; static PyObject *__pyx_n_s_p; static PyObject *__pyx_n_s_pack; static PyObject *__pyx_n_s_pcap; static PyObject *__pyx_n_s_pkt; static PyObject *__pyx_n_s_pkts; static PyObject *__pyx_n_s_platform; static PyObject *__pyx_n_s_promisc; static PyObject *__pyx_n_s_retval; static PyObject *__pyx_kp_s_root_pypcap_pcap_pyx; static PyObject *__pyx_n_s_snaplen; static PyObject *__pyx_n_s_status; static PyObject *__pyx_n_s_struct; static PyObject *__pyx_n_s_sys; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_timeout_ms; static PyObject *__pyx_n_s_ts; static PyObject *__pyx_n_s_url; static PyObject *__pyx_n_s_value; static PyObject *__pyx_n_s_version; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; static PyObject *__pyx_int_3; static PyObject *__pyx_int_4; static PyObject *__pyx_int_5; static PyObject *__pyx_int_6; static PyObject *__pyx_int_7; static PyObject *__pyx_int_8; static PyObject *__pyx_int_9; static PyObject *__pyx_int_10; static PyObject *__pyx_int_12; static PyObject *__pyx_int_14; static PyObject *__pyx_int_16; static PyObject *__pyx_int_18; static PyObject *__pyx_int_21; static PyObject *__pyx_int_22; static PyObject *__pyx_int_48; static PyObject *__pyx_int_108; static PyObject *__pyx_int_113; static PyObject *__pyx_int_117; static PyObject *__pyx_int_65535; static PyObject *__pyx_int_neg_1; static PyObject *__pyx_k_; static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__10; static PyObject *__pyx_codeobj__5; static PyObject *__pyx_codeobj__7; static PyObject *__pyx_codeobj__9; static PyObject *__pyx_codeobj__11; /* "pcap.pyx":103 * int got_exc * * cdef void __pcap_handler(void *arg, pcap_pkthdr *hdr, char *pkt): # <<<<<<<<<<<<<< * cdef pcap_handler_ctx *ctx * cdef int gil */ static void __pyx_f_4pcap___pcap_handler(void *__pyx_v_arg, struct pcap_pkthdr *__pyx_v_hdr, char *__pyx_v_pkt) { struct __pyx_t_4pcap_pcap_handler_ctx *__pyx_v_ctx; int __pyx_v_gil; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pcap_handler", 0); /* "pcap.pyx":106 * cdef pcap_handler_ctx *ctx * cdef int gil * ctx = arg # <<<<<<<<<<<<<< * gil = PyGILState_Ensure() * try: */ __pyx_v_ctx = ((struct __pyx_t_4pcap_pcap_handler_ctx *)__pyx_v_arg); /* "pcap.pyx":107 * cdef int gil * ctx = arg * gil = PyGILState_Ensure() # <<<<<<<<<<<<<< * try: * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), */ __pyx_v_gil = PyGILState_Ensure(); /* "pcap.pyx":108 * ctx = arg * gil = PyGILState_Ensure() * try: # <<<<<<<<<<<<<< * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), */ { __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { /* "pcap.pyx":109 * gil = PyGILState_Ensure() * try: * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), * *(ctx.args)) */ __pyx_t_4 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); /* "pcap.pyx":110 * try: * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), # <<<<<<<<<<<<<< * *(ctx.args)) * except: */ __pyx_t_5 = PyBuffer_FromMemory(__pyx_v_pkt, __pyx_v_hdr->caplen); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_5); /* "pcap.pyx":109 * gil = PyGILState_Ensure() * try: * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), * *(ctx.args)) */ __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_4 = 0; __pyx_t_5 = 0; /* "pcap.pyx":111 * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), * *(ctx.args)) # <<<<<<<<<<<<<< * except: * ctx.got_exc = 1 */ __pyx_t_5 = PySequence_Tuple(((PyObject *)__pyx_v_ctx->args)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_5); /* "pcap.pyx":109 * gil = PyGILState_Ensure() * try: * (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), * *(ctx.args)) */ __pyx_t_4 = PyNumber_Add(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_v_ctx->callback), __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L10_try_end; __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; /* "pcap.pyx":112 * PyBuffer_FromMemory(pkt, hdr.caplen), * *(ctx.args)) * except: # <<<<<<<<<<<<<< * ctx.got_exc = 1 * PyGILState_Release(gil) */ /*except:*/ { __Pyx_AddTraceback("pcap.__pcap_handler", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L5_except_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); /* "pcap.pyx":113 * *(ctx.args)) * except: * ctx.got_exc = 1 # <<<<<<<<<<<<<< * PyGILState_Release(gil) * */ __pyx_v_ctx->got_exc = 1; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L4_exception_handled; } __pyx_L5_except_error:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L1_error; __pyx_L4_exception_handled:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); __pyx_L10_try_end:; } /* "pcap.pyx":114 * except: * ctx.got_exc = 1 * PyGILState_Release(gil) # <<<<<<<<<<<<<< * * DLT_NULL = 0 */ PyGILState_Release(__pyx_v_gil); /* "pcap.pyx":103 * int got_exc * * cdef void __pcap_handler(void *arg, pcap_pkthdr *hdr, char *pkt): # <<<<<<<<<<<<<< * cdef pcap_handler_ctx *ctx * cdef int gil */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_WriteUnraisable("pcap.__pcap_handler", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); __pyx_L0:; __Pyx_RefNannyFinishContext(); } /* "pcap.pyx":150 * """bpf(filter, dlt=DLT_RAW) -> BPF filter object""" * cdef bpf_program fcode * def __init__(self, char *filter, dlt=DLT_RAW): # <<<<<<<<<<<<<< * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' */ /* Python wrapper */ static int __pyx_pw_4pcap_3bpf_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_4pcap_3bpf_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { char *__pyx_v_filter; PyObject *__pyx_v_dlt = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filter,&__pyx_n_s_dlt,0}; PyObject* values[2] = {0,0}; values[1] = __pyx_k_; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_filter)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_dlt); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_filter = __Pyx_PyObject_AsString(values[0]); if (unlikely((!__pyx_v_filter) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_dlt = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pcap.bpf.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_3bpf___init__(((struct __pyx_obj_4pcap_bpf *)__pyx_v_self), __pyx_v_filter, __pyx_v_dlt); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_4pcap_3bpf___init__(struct __pyx_obj_4pcap_bpf *__pyx_v_self, char *__pyx_v_filter, PyObject *__pyx_v_dlt) { int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "pcap.pyx":151 * cdef bpf_program fcode * def __init__(self, char *filter, dlt=DLT_RAW): * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: # <<<<<<<<<<<<<< * raise IOError, 'bad filter' * def filter(self, buf): */ __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_dlt); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = ((pcap_ex_compile_nopcap(65535, __pyx_t_1, (&__pyx_v_self->fcode), __pyx_v_filter, 1, 0) < 0) != 0); if (__pyx_t_2) { /* "pcap.pyx":152 * def __init__(self, char *filter, dlt=DLT_RAW): * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' # <<<<<<<<<<<<<< * def filter(self, buf): * """Return boolean match for buf against our filter.""" */ __Pyx_Raise(__pyx_builtin_IOError, __pyx_kp_s_bad_filter, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":150 * """bpf(filter, dlt=DLT_RAW) -> BPF filter object""" * cdef bpf_program fcode * def __init__(self, char *filter, dlt=DLT_RAW): # <<<<<<<<<<<<<< * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("pcap.bpf.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":153 * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' * def filter(self, buf): # <<<<<<<<<<<<<< * """Return boolean match for buf against our filter.""" * cdef char *p */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_3bpf_3filter(PyObject *__pyx_v_self, PyObject *__pyx_v_buf); /*proto*/ static char __pyx_doc_4pcap_3bpf_2filter[] = "Return boolean match for buf against our filter."; static PyObject *__pyx_pw_4pcap_3bpf_3filter(PyObject *__pyx_v_self, PyObject *__pyx_v_buf) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("filter (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_3bpf_2filter(((struct __pyx_obj_4pcap_bpf *)__pyx_v_self), ((PyObject *)__pyx_v_buf)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_3bpf_2filter(struct __pyx_obj_4pcap_bpf *__pyx_v_self, PyObject *__pyx_v_buf) { char *__pyx_v_p; int __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("filter", 0); /* "pcap.pyx":157 * cdef char *p * cdef int n * if PyObject_AsCharBuffer(buf, &p, &n) < 0: # <<<<<<<<<<<<<< * raise TypeError * if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: */ __pyx_t_1 = ((PyObject_AsCharBuffer(__pyx_v_buf, (&__pyx_v_p), (&__pyx_v_n)) < 0) != 0); if (__pyx_t_1) { /* "pcap.pyx":158 * cdef int n * if PyObject_AsCharBuffer(buf, &p, &n) < 0: * raise TypeError # <<<<<<<<<<<<<< * if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: * return False */ __Pyx_Raise(__pyx_builtin_TypeError, 0, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":159 * if PyObject_AsCharBuffer(buf, &p, &n) < 0: * raise TypeError * if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: # <<<<<<<<<<<<<< * return False * return True */ __pyx_t_1 = ((bpf_filter(__pyx_v_self->fcode.bf_insns, __pyx_v_p, __pyx_v_n, __pyx_v_n) == 0) != 0); if (__pyx_t_1) { /* "pcap.pyx":160 * raise TypeError * if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: * return False # <<<<<<<<<<<<<< * return True * def __dealloc__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_False); __pyx_r = Py_False; goto __pyx_L0; } /* "pcap.pyx":161 * if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: * return False * return True # <<<<<<<<<<<<<< * def __dealloc__(self): * pcap_freecode(&self.fcode) */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_True); __pyx_r = Py_True; goto __pyx_L0; /* "pcap.pyx":153 * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' * def filter(self, buf): # <<<<<<<<<<<<<< * """Return boolean match for buf against our filter.""" * cdef char *p */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("pcap.bpf.filter", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":162 * return False * return True * def __dealloc__(self): # <<<<<<<<<<<<<< * pcap_freecode(&self.fcode) * */ /* Python wrapper */ static void __pyx_pw_4pcap_3bpf_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_pw_4pcap_3bpf_5__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); __pyx_pf_4pcap_3bpf_4__dealloc__(((struct __pyx_obj_4pcap_bpf *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); } static void __pyx_pf_4pcap_3bpf_4__dealloc__(struct __pyx_obj_4pcap_bpf *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); /* "pcap.pyx":163 * return True * def __dealloc__(self): * pcap_freecode(&self.fcode) # <<<<<<<<<<<<<< * * cdef class pcap: */ pcap_freecode((&__pyx_v_self->fcode)); /* "pcap.pyx":162 * return False * return True * def __dealloc__(self): # <<<<<<<<<<<<<< * pcap_freecode(&self.fcode) * */ /* function exit code */ __Pyx_RefNannyFinishContext(); } /* "pcap.pyx":186 * cdef int __dloff * * def __init__(self, name=None, snaplen=65535, promisc=True, # <<<<<<<<<<<<<< * timeout_ms=0, immediate=False): * global dltoff */ /* Python wrapper */ static int __pyx_pw_4pcap_4pcap_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_4pcap_4pcap_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_name = 0; PyObject *__pyx_v_snaplen = 0; PyObject *__pyx_v_promisc = 0; PyObject *__pyx_v_timeout_ms = 0; PyObject *__pyx_v_immediate = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_snaplen,&__pyx_n_s_promisc,&__pyx_n_s_timeout_ms,&__pyx_n_s_immediate,0}; PyObject* values[5] = {0,0,0,0,0}; values[0] = ((PyObject *)Py_None); values[1] = ((PyObject *)__pyx_int_65535); values[2] = ((PyObject *)Py_True); values[3] = ((PyObject *)__pyx_int_0); /* "pcap.pyx":187 * * def __init__(self, name=None, snaplen=65535, promisc=True, * timeout_ms=0, immediate=False): # <<<<<<<<<<<<<< * global dltoff * cdef char *p */ values[4] = ((PyObject *)Py_False); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_name); if (value) { values[0] = value; kw_args--; } } case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_snaplen); if (value) { values[1] = value; kw_args--; } } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_promisc); if (value) { values[2] = value; kw_args--; } } case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_timeout_ms); if (value) { values[3] = value; kw_args--; } } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_immediate); if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_name = values[0]; __pyx_v_snaplen = values[1]; __pyx_v_promisc = values[2]; __pyx_v_timeout_ms = values[3]; __pyx_v_immediate = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pcap.pcap.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap___init__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_name, __pyx_v_snaplen, __pyx_v_promisc, __pyx_v_timeout_ms, __pyx_v_immediate); /* "pcap.pyx":186 * cdef int __dloff * * def __init__(self, name=None, snaplen=65535, promisc=True, # <<<<<<<<<<<<<< * timeout_ms=0, immediate=False): * global dltoff */ /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_4pcap_4pcap___init__(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_snaplen, PyObject *__pyx_v_promisc, PyObject *__pyx_v_timeout_ms, PyObject *__pyx_v_immediate) { char *__pyx_v_p; int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; char *__pyx_t_4; int __pyx_t_5; int __pyx_t_6; int __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; PyObject *__pyx_t_11 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "pcap.pyx":191 * cdef char *p * * if not name: # <<<<<<<<<<<<<< * p = pcap_ex_lookupdev(self.__ebuf) * if p == NULL: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_name); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = ((!__pyx_t_1) != 0); if (__pyx_t_2) { /* "pcap.pyx":192 * * if not name: * p = pcap_ex_lookupdev(self.__ebuf) # <<<<<<<<<<<<<< * if p == NULL: * raise OSError, self.__ebuf */ __pyx_v_p = pcap_ex_lookupdev(__pyx_v_self->__pyx___ebuf); /* "pcap.pyx":193 * if not name: * p = pcap_ex_lookupdev(self.__ebuf) * if p == NULL: # <<<<<<<<<<<<<< * raise OSError, self.__ebuf * else: */ __pyx_t_2 = ((__pyx_v_p == NULL) != 0); if (__pyx_t_2) { /* "pcap.pyx":194 * p = pcap_ex_lookupdev(self.__ebuf) * if p == NULL: * raise OSError, self.__ebuf # <<<<<<<<<<<<<< * else: * p = name */ __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx___ebuf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } goto __pyx_L3; } /*else*/ { /* "pcap.pyx":196 * raise OSError, self.__ebuf * else: * p = name # <<<<<<<<<<<<<< * * self.__pcap = pcap_open_offline(p, self.__ebuf) */ __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_p = __pyx_t_4; } __pyx_L3:; /* "pcap.pyx":198 * p = name * * self.__pcap = pcap_open_offline(p, self.__ebuf) # <<<<<<<<<<<<<< * if not self.__pcap: * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, */ __pyx_v_self->__pyx___pcap = pcap_open_offline(__pyx_v_p, __pyx_v_self->__pyx___ebuf); /* "pcap.pyx":199 * * self.__pcap = pcap_open_offline(p, self.__ebuf) * if not self.__pcap: # <<<<<<<<<<<<<< * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, * timeout_ms, self.__ebuf) */ __pyx_t_2 = ((!(__pyx_v_self->__pyx___pcap != 0)) != 0); if (__pyx_t_2) { /* "pcap.pyx":200 * self.__pcap = pcap_open_offline(p, self.__ebuf) * if not self.__pcap: * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, # <<<<<<<<<<<<<< * timeout_ms, self.__ebuf) * if not self.__pcap: */ __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_snaplen); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_promisc); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":201 * if not self.__pcap: * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, * timeout_ms, self.__ebuf) # <<<<<<<<<<<<<< * if not self.__pcap: * raise OSError, self.__ebuf */ __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_timeout_ms); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":200 * self.__pcap = pcap_open_offline(p, self.__ebuf) * if not self.__pcap: * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, # <<<<<<<<<<<<<< * timeout_ms, self.__ebuf) * if not self.__pcap: */ __pyx_v_self->__pyx___pcap = pcap_open_live(pcap_ex_name(__pyx_v_p), __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_v_self->__pyx___ebuf); goto __pyx_L5; } __pyx_L5:; /* "pcap.pyx":202 * self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, * timeout_ms, self.__ebuf) * if not self.__pcap: # <<<<<<<<<<<<<< * raise OSError, self.__ebuf * */ __pyx_t_2 = ((!(__pyx_v_self->__pyx___pcap != 0)) != 0); if (__pyx_t_2) { /* "pcap.pyx":203 * timeout_ms, self.__ebuf) * if not self.__pcap: * raise OSError, self.__ebuf # <<<<<<<<<<<<<< * * self.__name = strdup(p) */ __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx___ebuf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":205 * raise OSError, self.__ebuf * * self.__name = strdup(p) # <<<<<<<<<<<<<< * self.__filter = strdup("") * try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] */ __pyx_v_self->__pyx___name = strdup(__pyx_v_p); /* "pcap.pyx":206 * * self.__name = strdup(p) * self.__filter = strdup("") # <<<<<<<<<<<<<< * try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] * except KeyError: pass */ __pyx_v_self->__pyx___filter = strdup(__pyx_k__2); /* "pcap.pyx":207 * self.__name = strdup(p) * self.__filter = strdup("") * try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] # <<<<<<<<<<<<<< * except KeyError: pass * if immediate and pcap_ex_immediate(self.__pcap) < 0: */ { __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); __Pyx_XGOTREF(__pyx_t_8); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_10); /*try:*/ { __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_dltoff); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = pcap_datalink(__pyx_v_self->__pyx___pcap); __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_3, __pyx_t_7, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_v_self->__pyx___dloff = __pyx_t_7; } __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L14_try_end; __pyx_L7_error:; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; /* "pcap.pyx":208 * self.__filter = strdup("") * try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] * except KeyError: pass # <<<<<<<<<<<<<< * if immediate and pcap_ex_immediate(self.__pcap) < 0: * raise OSError, "couldn't enable immediate mode" */ __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_7) { PyErr_Restore(0,0,0); goto __pyx_L8_exception_handled; } goto __pyx_L9_except_error; __pyx_L9_except_error:; __Pyx_XGIVEREF(__pyx_t_8); __Pyx_XGIVEREF(__pyx_t_9); __Pyx_XGIVEREF(__pyx_t_10); __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); goto __pyx_L1_error; __pyx_L8_exception_handled:; __Pyx_XGIVEREF(__pyx_t_8); __Pyx_XGIVEREF(__pyx_t_9); __Pyx_XGIVEREF(__pyx_t_10); __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); __pyx_L14_try_end:; } /* "pcap.pyx":209 * try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] * except KeyError: pass * if immediate and pcap_ex_immediate(self.__pcap) < 0: # <<<<<<<<<<<<<< * raise OSError, "couldn't enable immediate mode" * */ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_immediate); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; goto __pyx_L16_bool_binop_done; } __pyx_t_1 = ((pcap_ex_immediate(__pyx_v_self->__pyx___pcap) < 0) != 0); __pyx_t_2 = __pyx_t_1; __pyx_L16_bool_binop_done:; if (__pyx_t_2) { /* "pcap.pyx":210 * except KeyError: pass * if immediate and pcap_ex_immediate(self.__pcap) < 0: * raise OSError, "couldn't enable immediate mode" # <<<<<<<<<<<<<< * * property name: */ __Pyx_Raise(__pyx_builtin_OSError, __pyx_kp_s_couldn_t_enable_immediate_mode, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":186 * cdef int __dloff * * def __init__(self, name=None, snaplen=65535, promisc=True, # <<<<<<<<<<<<<< * timeout_ms=0, immediate=False): * global dltoff */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pcap.pcap.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":214 * property name: * """Network interface or dumpfile name.""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__name * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_4name_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_4name___get__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_4name___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "pcap.pyx":215 * """Network interface or dumpfile name.""" * def __get__(self): * return self.__name # <<<<<<<<<<<<<< * * property snaplen: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx___name); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":214 * property name: * """Network interface or dumpfile name.""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__name * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":219 * property snaplen: * """Maximum number of bytes to capture for each packet.""" * def __get__(self): # <<<<<<<<<<<<<< * return pcap_snapshot(self.__pcap) * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_7snaplen_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_7snaplen_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_7snaplen___get__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_7snaplen___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "pcap.pyx":220 * """Maximum number of bytes to capture for each packet.""" * def __get__(self): * return pcap_snapshot(self.__pcap) # <<<<<<<<<<<<<< * * property dloff: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(pcap_snapshot(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":219 * property snaplen: * """Maximum number of bytes to capture for each packet.""" * def __get__(self): # <<<<<<<<<<<<<< * return pcap_snapshot(self.__pcap) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.snaplen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":224 * property dloff: * """Datalink offset (length of layer-2 frame header).""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__dloff * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_5dloff_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_5dloff_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_5dloff___get__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_5dloff___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "pcap.pyx":225 * """Datalink offset (length of layer-2 frame header).""" * def __get__(self): * return self.__dloff # <<<<<<<<<<<<<< * * property filter: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx___dloff); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":224 * property dloff: * """Datalink offset (length of layer-2 frame header).""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__dloff * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.dloff.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":229 * property filter: * """Current packet capture filter.""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__filter * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_6filter_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_6filter_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_6filter___get__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_6filter___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "pcap.pyx":230 * """Current packet capture filter.""" * def __get__(self): * return self.__filter # <<<<<<<<<<<<<< * * property fd: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx___filter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":229 * property filter: * """Current packet capture filter.""" * def __get__(self): # <<<<<<<<<<<<<< * return self.__filter * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.filter.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":234 * property fd: * """File descriptor (or Win32 HANDLE) for capture handle.""" * def __get__(self): # <<<<<<<<<<<<<< * return pcap_ex_fileno(self.__pcap) * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_2fd_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_2fd_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_2fd___get__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_2fd___get__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); /* "pcap.pyx":235 * """File descriptor (or Win32 HANDLE) for capture handle.""" * def __get__(self): * return pcap_ex_fileno(self.__pcap) # <<<<<<<<<<<<<< * * def fileno(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(pcap_ex_fileno(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":234 * property fd: * """File descriptor (or Win32 HANDLE) for capture handle.""" * def __get__(self): # <<<<<<<<<<<<<< * return pcap_ex_fileno(self.__pcap) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.fd.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":237 * return pcap_ex_fileno(self.__pcap) * * def fileno(self): # <<<<<<<<<<<<<< * """Return file descriptor (or Win32 HANDLE) for capture handle.""" * return pcap_ex_fileno(self.__pcap) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_3fileno(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_2fileno[] = "Return file descriptor (or Win32 HANDLE) for capture handle."; static PyObject *__pyx_pw_4pcap_4pcap_3fileno(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fileno (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_2fileno(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_2fileno(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("fileno", 0); /* "pcap.pyx":239 * def fileno(self): * """Return file descriptor (or Win32 HANDLE) for capture handle.""" * return pcap_ex_fileno(self.__pcap) # <<<<<<<<<<<<<< * * def setfilter(self, value, optimize=1): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(pcap_ex_fileno(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":237 * return pcap_ex_fileno(self.__pcap) * * def fileno(self): # <<<<<<<<<<<<<< * """Return file descriptor (or Win32 HANDLE) for capture handle.""" * return pcap_ex_fileno(self.__pcap) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.fileno", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":241 * return pcap_ex_fileno(self.__pcap) * * def setfilter(self, value, optimize=1): # <<<<<<<<<<<<<< * """Set BPF-format packet capture filter.""" * cdef bpf_program fcode */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_5setfilter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_4pcap_4pcap_4setfilter[] = "Set BPF-format packet capture filter."; static PyObject *__pyx_pw_4pcap_4pcap_5setfilter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_value = 0; PyObject *__pyx_v_optimize = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("setfilter (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_optimize,0}; PyObject* values[2] = {0,0}; values[1] = ((PyObject *)__pyx_int_1); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_optimize); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfilter") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_value = values[0]; __pyx_v_optimize = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("setfilter", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pcap.pcap.setfilter", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap_4setfilter(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_value, __pyx_v_optimize); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_4setfilter(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_value, PyObject *__pyx_v_optimize) { struct bpf_program __pyx_v_fcode; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations char *__pyx_t_1; int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setfilter", 0); /* "pcap.pyx":244 * """Set BPF-format packet capture filter.""" * cdef bpf_program fcode * free(self.__filter) # <<<<<<<<<<<<<< * self.__filter = strdup(value) * if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: */ free(__pyx_v_self->__pyx___filter); /* "pcap.pyx":245 * cdef bpf_program fcode * free(self.__filter) * self.__filter = strdup(value) # <<<<<<<<<<<<<< * if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: * raise OSError, pcap_geterr(self.__pcap) */ __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->__pyx___filter = strdup(__pyx_t_1); /* "pcap.pyx":246 * free(self.__filter) * self.__filter = strdup(value) * if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: # <<<<<<<<<<<<<< * raise OSError, pcap_geterr(self.__pcap) * if pcap_setfilter(self.__pcap, &fcode) < 0: */ __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_v_optimize); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = ((pcap_compile(__pyx_v_self->__pyx___pcap, (&__pyx_v_fcode), __pyx_v_self->__pyx___filter, __pyx_t_2, 0) < 0) != 0); if (__pyx_t_3) { /* "pcap.pyx":247 * self.__filter = strdup(value) * if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: * raise OSError, pcap_geterr(self.__pcap) # <<<<<<<<<<<<<< * if pcap_setfilter(self.__pcap, &fcode) < 0: * raise OSError, pcap_geterr(self.__pcap) */ __pyx_t_4 = __Pyx_PyBytes_FromString(pcap_geterr(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_4, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":248 * if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: * raise OSError, pcap_geterr(self.__pcap) * if pcap_setfilter(self.__pcap, &fcode) < 0: # <<<<<<<<<<<<<< * raise OSError, pcap_geterr(self.__pcap) * pcap_freecode(&fcode) */ __pyx_t_3 = ((pcap_setfilter(__pyx_v_self->__pyx___pcap, (&__pyx_v_fcode)) < 0) != 0); if (__pyx_t_3) { /* "pcap.pyx":249 * raise OSError, pcap_geterr(self.__pcap) * if pcap_setfilter(self.__pcap, &fcode) < 0: * raise OSError, pcap_geterr(self.__pcap) # <<<<<<<<<<<<<< * pcap_freecode(&fcode) * */ __pyx_t_4 = __Pyx_PyBytes_FromString(pcap_geterr(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_4, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":250 * if pcap_setfilter(self.__pcap, &fcode) < 0: * raise OSError, pcap_geterr(self.__pcap) * pcap_freecode(&fcode) # <<<<<<<<<<<<<< * * def setdirection(self, direction): */ pcap_freecode((&__pyx_v_fcode)); /* "pcap.pyx":241 * return pcap_ex_fileno(self.__pcap) * * def setfilter(self, value, optimize=1): # <<<<<<<<<<<<<< * """Set BPF-format packet capture filter.""" * cdef bpf_program fcode */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pcap.pcap.setfilter", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":252 * pcap_freecode(&fcode) * * def setdirection(self, direction): # <<<<<<<<<<<<<< * """Set capture direction.""" * ret = pcap_ex_setdirection(self.__pcap, direction) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_7setdirection(PyObject *__pyx_v_self, PyObject *__pyx_v_direction); /*proto*/ static char __pyx_doc_4pcap_4pcap_6setdirection[] = "Set capture direction."; static PyObject *__pyx_pw_4pcap_4pcap_7setdirection(PyObject *__pyx_v_self, PyObject *__pyx_v_direction) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("setdirection (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_6setdirection(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), ((PyObject *)__pyx_v_direction)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_6setdirection(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_direction) { int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setdirection", 0); /* "pcap.pyx":254 * def setdirection(self, direction): * """Set capture direction.""" * ret = pcap_ex_setdirection(self.__pcap, direction) # <<<<<<<<<<<<<< * if ret == 0: * return True */ __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_direction); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_ret = pcap_ex_setdirection(__pyx_v_self->__pyx___pcap, __pyx_t_1); /* "pcap.pyx":255 * """Set capture direction.""" * ret = pcap_ex_setdirection(self.__pcap, direction) * if ret == 0: # <<<<<<<<<<<<<< * return True * return False */ __pyx_t_2 = ((__pyx_v_ret == 0) != 0); if (__pyx_t_2) { /* "pcap.pyx":256 * ret = pcap_ex_setdirection(self.__pcap, direction) * if ret == 0: * return True # <<<<<<<<<<<<<< * return False * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_True); __pyx_r = Py_True; goto __pyx_L0; } /* "pcap.pyx":257 * if ret == 0: * return True * return False # <<<<<<<<<<<<<< * * def setnonblock(self, nonblock=True): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_False); __pyx_r = Py_False; goto __pyx_L0; /* "pcap.pyx":252 * pcap_freecode(&fcode) * * def setdirection(self, direction): # <<<<<<<<<<<<<< * """Set capture direction.""" * ret = pcap_ex_setdirection(self.__pcap, direction) */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("pcap.pcap.setdirection", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":259 * return False * * def setnonblock(self, nonblock=True): # <<<<<<<<<<<<<< * """Set non-blocking capture mode.""" * pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_9setnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_4pcap_4pcap_8setnonblock[] = "Set non-blocking capture mode."; static PyObject *__pyx_pw_4pcap_4pcap_9setnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_nonblock = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("setnonblock (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_nonblock,0}; PyObject* values[1] = {0}; values[0] = ((PyObject *)Py_True); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nonblock); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setnonblock") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_nonblock = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("setnonblock", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pcap.pcap.setnonblock", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap_8setnonblock(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_nonblock); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_8setnonblock(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_nonblock) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("setnonblock", 0); /* "pcap.pyx":261 * def setnonblock(self, nonblock=True): * """Set non-blocking capture mode.""" * pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) # <<<<<<<<<<<<<< * * def getnonblock(self): */ __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_nonblock); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;} pcap_ex_setnonblock(__pyx_v_self->__pyx___pcap, __pyx_t_1, __pyx_v_self->__pyx___ebuf); /* "pcap.pyx":259 * return False * * def setnonblock(self, nonblock=True): # <<<<<<<<<<<<<< * """Set non-blocking capture mode.""" * pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("pcap.pcap.setnonblock", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":263 * pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) * * def getnonblock(self): # <<<<<<<<<<<<<< * """Return non-blocking capture mode as boolean.""" * ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_11getnonblock(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_10getnonblock[] = "Return non-blocking capture mode as boolean."; static PyObject *__pyx_pw_4pcap_4pcap_11getnonblock(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getnonblock (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_10getnonblock(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_10getnonblock(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getnonblock", 0); /* "pcap.pyx":265 * def getnonblock(self): * """Return non-blocking capture mode as boolean.""" * ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) # <<<<<<<<<<<<<< * if ret < 0: * raise OSError, self.__ebuf */ __pyx_v_ret = pcap_ex_getnonblock(__pyx_v_self->__pyx___pcap, __pyx_v_self->__pyx___ebuf); /* "pcap.pyx":266 * """Return non-blocking capture mode as boolean.""" * ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) * if ret < 0: # <<<<<<<<<<<<<< * raise OSError, self.__ebuf * elif ret: */ __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { /* "pcap.pyx":267 * ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) * if ret < 0: * raise OSError, self.__ebuf # <<<<<<<<<<<<<< * elif ret: * return True */ __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx___ebuf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":268 * if ret < 0: * raise OSError, self.__ebuf * elif ret: # <<<<<<<<<<<<<< * return True * return False */ __pyx_t_1 = (__pyx_v_ret != 0); if (__pyx_t_1) { /* "pcap.pyx":269 * raise OSError, self.__ebuf * elif ret: * return True # <<<<<<<<<<<<<< * return False * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_True); __pyx_r = Py_True; goto __pyx_L0; } /* "pcap.pyx":270 * elif ret: * return True * return False # <<<<<<<<<<<<<< * * def datalink(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_False); __pyx_r = Py_False; goto __pyx_L0; /* "pcap.pyx":263 * pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) * * def getnonblock(self): # <<<<<<<<<<<<<< * """Return non-blocking capture mode as boolean.""" * ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("pcap.pcap.getnonblock", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":272 * return False * * def datalink(self): # <<<<<<<<<<<<<< * """Return datalink type (DLT_* values).""" * return pcap_datalink(self.__pcap) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_13datalink(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_12datalink[] = "Return datalink type (DLT_* values)."; static PyObject *__pyx_pw_4pcap_4pcap_13datalink(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("datalink (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_12datalink(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_12datalink(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("datalink", 0); /* "pcap.pyx":274 * def datalink(self): * """Return datalink type (DLT_* values).""" * return pcap_datalink(self.__pcap) # <<<<<<<<<<<<<< * * def __add_pkts(self, ts, pkt, pkts): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(pcap_datalink(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":272 * return False * * def datalink(self): # <<<<<<<<<<<<<< * """Return datalink type (DLT_* values).""" * return pcap_datalink(self.__pcap) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.datalink", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":276 * return pcap_datalink(self.__pcap) * * def __add_pkts(self, ts, pkt, pkts): # <<<<<<<<<<<<<< * pkts.append((ts, pkt)) * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_15__add_pkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_15__add_pkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_ts = 0; PyObject *__pyx_v_pkt = 0; PyObject *__pyx_v_pkts = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add_pkts (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ts,&__pyx_n_s_pkt,&__pyx_n_s_pkts,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ts)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pkt)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__add_pkts", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pkts)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__add_pkts", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__add_pkts") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_ts = values[0]; __pyx_v_pkt = values[1]; __pyx_v_pkts = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__add_pkts", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pcap.pcap.__add_pkts", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap_14__add_pkts(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_ts, __pyx_v_pkt, __pyx_v_pkts); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_14__add_pkts(CYTHON_UNUSED struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_ts, PyObject *__pyx_v_pkt, PyObject *__pyx_v_pkts) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add_pkts", 0); /* "pcap.pyx":277 * * def __add_pkts(self, ts, pkt, pkts): * pkts.append((ts, pkt)) # <<<<<<<<<<<<<< * * def readpkts(self): */ __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_ts); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_ts); __Pyx_GIVEREF(__pyx_v_ts); __Pyx_INCREF(__pyx_v_pkt); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_pkt); __Pyx_GIVEREF(__pyx_v_pkt); __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_pkts, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":276 * return pcap_datalink(self.__pcap) * * def __add_pkts(self, ts, pkt, pkts): # <<<<<<<<<<<<<< * pkts.append((ts, pkt)) * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.__add_pkts", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":279 * pkts.append((ts, pkt)) * * def readpkts(self): # <<<<<<<<<<<<<< * """Return a list of (timestamp, packet) tuples received in one buffer.""" * pkts = [] */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_17readpkts(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_16readpkts[] = "Return a list of (timestamp, packet) tuples received in one buffer."; static PyObject *__pyx_pw_4pcap_4pcap_17readpkts(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("readpkts (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_16readpkts(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_16readpkts(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_v_pkts = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; Py_ssize_t __pyx_t_5; PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("readpkts", 0); /* "pcap.pyx":281 * def readpkts(self): * """Return a list of (timestamp, packet) tuples received in one buffer.""" * pkts = [] # <<<<<<<<<<<<<< * self.dispatch(-1, self.__add_pkts, pkts) * return pkts */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_pkts = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":282 * """Return a list of (timestamp, packet) tuples received in one buffer.""" * pkts = [] * self.dispatch(-1, self.__add_pkts, pkts) # <<<<<<<<<<<<<< * return pkts * */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dispatch); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_pkts); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; __pyx_t_5 = 0; if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_5 = 1; } } __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); if (__pyx_t_4) { PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL; } __Pyx_INCREF(__pyx_int_neg_1); PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_pkts); PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_pkts); __Pyx_GIVEREF(__pyx_v_pkts); __pyx_t_3 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":283 * pkts = [] * self.dispatch(-1, self.__add_pkts, pkts) * return pkts # <<<<<<<<<<<<<< * * def dispatch(self, cnt, callback, *args): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_pkts); __pyx_r = __pyx_v_pkts; goto __pyx_L0; /* "pcap.pyx":279 * pkts.append((ts, pkt)) * * def readpkts(self): # <<<<<<<<<<<<<< * """Return a list of (timestamp, packet) tuples received in one buffer.""" * pkts = [] */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pcap.pcap.readpkts", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_pkts); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":285 * return pkts * * def dispatch(self, cnt, callback, *args): # <<<<<<<<<<<<<< * """Collect and process packets with a user callback, * return the number of packets processed, or 0 for a savefile. */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_19dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_4pcap_4pcap_18dispatch[] = "Collect and process packets with a user callback,\n return the number of packets processed, or 0 for a savefile.\n \n Arguments:\n \n cnt -- number of packets to process;\n or 0 to process all packets until an error occurs,\n EOF is reached, or the read times out;\n or -1 to process all packets received in one buffer\n callback -- function with (timestamp, pkt, *args) prototype\n *args -- optional arguments passed to callback on execution\n "; static PyObject *__pyx_pw_4pcap_4pcap_19dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_cnt = 0; PyObject *__pyx_v_callback = 0; PyObject *__pyx_v_args = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dispatch (wrapper)", 0); if (PyTuple_GET_SIZE(__pyx_args) > 2) { __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); if (unlikely(!__pyx_v_args)) { __Pyx_RefNannyFinishContext(); return NULL; } __Pyx_GOTREF(__pyx_v_args); } else { __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple); } { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_cnt,&__pyx_n_s_callback,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { default: case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_cnt)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_callback)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("dispatch", 0, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { const Py_ssize_t used_pos_args = (pos_args < 2) ? pos_args : 2; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) < 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_cnt = values[0]; __pyx_v_callback = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("dispatch", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0; __Pyx_AddTraceback("pcap.pcap.dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap_18dispatch(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_cnt, __pyx_v_callback, __pyx_v_args); /* function exit code */ __Pyx_XDECREF(__pyx_v_args); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_18dispatch(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_cnt, PyObject *__pyx_v_callback, PyObject *__pyx_v_args) { struct __pyx_t_4pcap_pcap_handler_ctx __pyx_v_ctx; int __pyx_v_n; PyObject *__pyx_v_exc = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dispatch", 0); /* "pcap.pyx":301 * cdef int n * * ctx.callback = callback # <<<<<<<<<<<<<< * ctx.args = args * ctx.got_exc = 0 */ __pyx_v_ctx.callback = ((void *)__pyx_v_callback); /* "pcap.pyx":302 * * ctx.callback = callback * ctx.args = args # <<<<<<<<<<<<<< * ctx.got_exc = 0 * n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, */ __pyx_v_ctx.args = ((void *)__pyx_v_args); /* "pcap.pyx":303 * ctx.callback = callback * ctx.args = args * ctx.got_exc = 0 # <<<<<<<<<<<<<< * n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, * &ctx) */ __pyx_v_ctx.got_exc = 0; /* "pcap.pyx":304 * ctx.args = args * ctx.got_exc = 0 * n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, # <<<<<<<<<<<<<< * &ctx) * if ctx.got_exc: */ __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_cnt); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":305 * ctx.got_exc = 0 * n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, * &ctx) # <<<<<<<<<<<<<< * if ctx.got_exc: * exc = sys.exc_info() */ __pyx_v_n = pcap_dispatch(__pyx_v_self->__pyx___pcap, __pyx_t_1, __pyx_f_4pcap___pcap_handler, ((unsigned char *)(&__pyx_v_ctx))); /* "pcap.pyx":306 * n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, * &ctx) * if ctx.got_exc: # <<<<<<<<<<<<<< * exc = sys.exc_info() * raise exc[0], exc[1], exc[2] */ __pyx_t_2 = (__pyx_v_ctx.got_exc != 0); if (__pyx_t_2) { /* "pcap.pyx":307 * &ctx) * if ctx.got_exc: * exc = sys.exc_info() # <<<<<<<<<<<<<< * raise exc[0], exc[1], exc[2] * return n */ __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exc_info); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); } } if (__pyx_t_4) { __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_exc = __pyx_t_3; __pyx_t_3 = 0; /* "pcap.pyx":308 * if ctx.got_exc: * exc = sys.exc_info() * raise exc[0], exc[1], exc[2] # <<<<<<<<<<<<<< * return n * */ __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_exc, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_exc, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_exc, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_3, __pyx_t_5, __pyx_t_4, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":309 * exc = sys.exc_info() * raise exc[0], exc[1], exc[2] * return n # <<<<<<<<<<<<<< * * def loop(self, cnt, callback, *args): */ __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; /* "pcap.pyx":285 * return pkts * * def dispatch(self, cnt, callback, *args): # <<<<<<<<<<<<<< * """Collect and process packets with a user callback, * return the number of packets processed, or 0 for a savefile. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pcap.pcap.dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_exc); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":311 * return n * * def loop(self, cnt, callback, *args): # <<<<<<<<<<<<<< * """Processing packets with a user callback during a loop. * The loop can be exited when cnt value is reached */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_21loop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_4pcap_4pcap_20loop[] = "Processing packets with a user callback during a loop.\n The loop can be exited when cnt value is reached\n or with an exception, including KeyboardInterrupt.\n \n Arguments:\n\n cnt -- number of packets to process;\n 0 or -1 to process all packets until an error occurs,\n EOF is reached;\n callback -- function with (timestamp, pkt, *args) prototype\n *args -- optional arguments passed to callback on execution\n "; static PyObject *__pyx_pw_4pcap_4pcap_21loop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_cnt = 0; PyObject *__pyx_v_callback = 0; PyObject *__pyx_v_args = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("loop (wrapper)", 0); if (PyTuple_GET_SIZE(__pyx_args) > 2) { __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); if (unlikely(!__pyx_v_args)) { __Pyx_RefNannyFinishContext(); return NULL; } __Pyx_GOTREF(__pyx_v_args); } else { __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple); } { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_cnt,&__pyx_n_s_callback,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { default: case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_cnt)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_callback)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("loop", 0, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { const Py_ssize_t used_pos_args = (pos_args < 2) ? pos_args : 2; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "loop") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) < 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_cnt = values[0]; __pyx_v_callback = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("loop", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0; __Pyx_AddTraceback("pcap.pcap.loop", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_4pcap_20loop(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), __pyx_v_cnt, __pyx_v_callback, __pyx_v_args); /* function exit code */ __Pyx_XDECREF(__pyx_v_args); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_20loop(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_cnt, PyObject *__pyx_v_callback, PyObject *__pyx_v_args) { struct pcap_pkthdr *__pyx_v_hdr; char *__pyx_v_pkt; int __pyx_v_n; int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("loop", 0); /* "pcap.pyx":328 * cdef int n * cdef int i * i = 1 # <<<<<<<<<<<<<< * pcap_ex_setup(self.__pcap) * while 1: */ __pyx_v_i = 1; /* "pcap.pyx":329 * cdef int i * i = 1 * pcap_ex_setup(self.__pcap) # <<<<<<<<<<<<<< * while 1: * Py_BEGIN_ALLOW_THREADS */ pcap_ex_setup(__pyx_v_self->__pyx___pcap); /* "pcap.pyx":330 * i = 1 * pcap_ex_setup(self.__pcap) * while 1: # <<<<<<<<<<<<<< * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) */ while (1) { /* "pcap.pyx":331 * pcap_ex_setup(self.__pcap) * while 1: * Py_BEGIN_ALLOW_THREADS # <<<<<<<<<<<<<< * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS */ Py_BEGIN_ALLOW_THREADS; /* "pcap.pyx":332 * while 1: * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) # <<<<<<<<<<<<<< * Py_END_ALLOW_THREADS * if n == 1: */ __pyx_v_n = pcap_ex_next(__pyx_v_self->__pyx___pcap, (&__pyx_v_hdr), (&__pyx_v_pkt)); /* "pcap.pyx":333 * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS # <<<<<<<<<<<<<< * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), */ Py_END_ALLOW_THREADS; /* "pcap.pyx":341 * elif n == -1: * raise KeyboardInterrupt * elif n == -2: # <<<<<<<<<<<<<< * break * if i == cnt: */ switch (__pyx_v_n) { /* "pcap.pyx":334 * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS * if n == 1: # <<<<<<<<<<<<<< * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), *args) */ case 1: /* "pcap.pyx":335 * Py_END_ALLOW_THREADS * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), *args) * elif n == 0: */ __pyx_t_1 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); /* "pcap.pyx":336 * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), *args) # <<<<<<<<<<<<<< * elif n == 0: * break */ __pyx_t_2 = PyBuffer_FromMemory(__pyx_v_pkt, __pyx_v_hdr->caplen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); /* "pcap.pyx":335 * Py_END_ALLOW_THREADS * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), *args) * elif n == 0: */ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; /* "pcap.pyx":336 * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), *args) # <<<<<<<<<<<<<< * elif n == 0: * break */ __pyx_t_2 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); /* "pcap.pyx":335 * Py_END_ALLOW_THREADS * if n == 1: * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen), *args) * elif n == 0: */ __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_v_callback, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; break; /* "pcap.pyx":337 * callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen), *args) * elif n == 0: # <<<<<<<<<<<<<< * break * elif n == -1: */ case 0: /* "pcap.pyx":338 * PyBuffer_FromMemory(pkt, hdr.caplen), *args) * elif n == 0: * break # <<<<<<<<<<<<<< * elif n == -1: * raise KeyboardInterrupt */ goto __pyx_L4_break; break; /* "pcap.pyx":339 * elif n == 0: * break * elif n == -1: # <<<<<<<<<<<<<< * raise KeyboardInterrupt * elif n == -2: */ case -1: /* "pcap.pyx":340 * break * elif n == -1: * raise KeyboardInterrupt # <<<<<<<<<<<<<< * elif n == -2: * break */ __Pyx_Raise(__pyx_builtin_KeyboardInterrupt, 0, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; /* "pcap.pyx":341 * elif n == -1: * raise KeyboardInterrupt * elif n == -2: # <<<<<<<<<<<<<< * break * if i == cnt: */ case -2: /* "pcap.pyx":342 * raise KeyboardInterrupt * elif n == -2: * break # <<<<<<<<<<<<<< * if i == cnt: * break */ goto __pyx_L4_break; break; default: break; } /* "pcap.pyx":343 * elif n == -2: * break * if i == cnt: # <<<<<<<<<<<<<< * break * i = i + 1 */ __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_v_cnt, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) { /* "pcap.pyx":344 * break * if i == cnt: * break # <<<<<<<<<<<<<< * i = i + 1 * */ goto __pyx_L4_break; } /* "pcap.pyx":345 * if i == cnt: * break * i = i + 1 # <<<<<<<<<<<<<< * * def sendpacket(self, buf): */ __pyx_v_i = (__pyx_v_i + 1); } __pyx_L4_break:; /* "pcap.pyx":311 * return n * * def loop(self, cnt, callback, *args): # <<<<<<<<<<<<<< * """Processing packets with a user callback during a loop. * The loop can be exited when cnt value is reached */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pcap.pcap.loop", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":347 * i = i + 1 * * def sendpacket(self, buf): # <<<<<<<<<<<<<< * """Send a raw network packet on the interface.""" * ret = pcap_sendpacket(self.__pcap, buf, len(buf)) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_23sendpacket(PyObject *__pyx_v_self, PyObject *__pyx_v_buf); /*proto*/ static char __pyx_doc_4pcap_4pcap_22sendpacket[] = "Send a raw network packet on the interface."; static PyObject *__pyx_pw_4pcap_4pcap_23sendpacket(PyObject *__pyx_v_self, PyObject *__pyx_v_buf) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sendpacket (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_22sendpacket(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self), ((PyObject *)__pyx_v_buf)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_22sendpacket(struct __pyx_obj_4pcap_pcap *__pyx_v_self, PyObject *__pyx_v_buf) { int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations char *__pyx_t_1; Py_ssize_t __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("sendpacket", 0); /* "pcap.pyx":349 * def sendpacket(self, buf): * """Send a raw network packet on the interface.""" * ret = pcap_sendpacket(self.__pcap, buf, len(buf)) # <<<<<<<<<<<<<< * if ret == -1: * raise OSError, pcap_geterr(self.__pcap) */ __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_buf); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = PyObject_Length(__pyx_v_buf); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_ret = pcap_sendpacket(__pyx_v_self->__pyx___pcap, __pyx_t_1, __pyx_t_2); /* "pcap.pyx":350 * """Send a raw network packet on the interface.""" * ret = pcap_sendpacket(self.__pcap, buf, len(buf)) * if ret == -1: # <<<<<<<<<<<<<< * raise OSError, pcap_geterr(self.__pcap) * return len(buf) */ __pyx_t_3 = ((__pyx_v_ret == -1) != 0); if (__pyx_t_3) { /* "pcap.pyx":351 * ret = pcap_sendpacket(self.__pcap, buf, len(buf)) * if ret == -1: * raise OSError, pcap_geterr(self.__pcap) # <<<<<<<<<<<<<< * return len(buf) * */ __pyx_t_4 = __Pyx_PyBytes_FromString(pcap_geterr(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_4, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":352 * if ret == -1: * raise OSError, pcap_geterr(self.__pcap) * return len(buf) # <<<<<<<<<<<<<< * * def geterr(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_Length(__pyx_v_buf); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; /* "pcap.pyx":347 * i = i + 1 * * def sendpacket(self, buf): # <<<<<<<<<<<<<< * """Send a raw network packet on the interface.""" * ret = pcap_sendpacket(self.__pcap, buf, len(buf)) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pcap.pcap.sendpacket", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":354 * return len(buf) * * def geterr(self): # <<<<<<<<<<<<<< * """Return the last error message associated with this handle.""" * return pcap_geterr(self.__pcap) */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_25geterr(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_24geterr[] = "Return the last error message associated with this handle."; static PyObject *__pyx_pw_4pcap_4pcap_25geterr(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("geterr (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_24geterr(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_24geterr(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("geterr", 0); /* "pcap.pyx":356 * def geterr(self): * """Return the last error message associated with this handle.""" * return pcap_geterr(self.__pcap) # <<<<<<<<<<<<<< * * def stats(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBytes_FromString(pcap_geterr(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":354 * return len(buf) * * def geterr(self): # <<<<<<<<<<<<<< * """Return the last error message associated with this handle.""" * return pcap_geterr(self.__pcap) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.pcap.geterr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":358 * return pcap_geterr(self.__pcap) * * def stats(self): # <<<<<<<<<<<<<< * """Return a 3-tuple of the total number of packets received, * dropped, and dropped by the interface.""" */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_27stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4pcap_26stats[] = "Return a 3-tuple of the total number of packets received,\n dropped, and dropped by the interface."; static PyObject *__pyx_pw_4pcap_4pcap_27stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("stats (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_26stats(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_26stats(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { struct pcap_stat __pyx_v_pstat; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("stats", 0); /* "pcap.pyx":362 * dropped, and dropped by the interface.""" * cdef pcap_stat pstat * if pcap_stats(self.__pcap, &pstat) < 0: # <<<<<<<<<<<<<< * raise OSError, pcap_geterr(self.__pcap) * return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) */ __pyx_t_1 = ((pcap_stats(__pyx_v_self->__pyx___pcap, (&__pyx_v_pstat)) < 0) != 0); if (__pyx_t_1) { /* "pcap.pyx":363 * cdef pcap_stat pstat * if pcap_stats(self.__pcap, &pstat) < 0: * raise OSError, pcap_geterr(self.__pcap) # <<<<<<<<<<<<<< * return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) * */ __pyx_t_2 = __Pyx_PyBytes_FromString(pcap_geterr(__pyx_v_self->__pyx___pcap)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":364 * if pcap_stats(self.__pcap, &pstat) < 0: * raise OSError, pcap_geterr(self.__pcap) * return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) # <<<<<<<<<<<<<< * * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyInt_From_unsigned_int(__pyx_v_pstat.ps_recv); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_pstat.ps_drop); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_v_pstat.ps_ifdrop); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; /* "pcap.pyx":358 * return pcap_geterr(self.__pcap) * * def stats(self): # <<<<<<<<<<<<<< * """Return a 3-tuple of the total number of packets received, * dropped, and dropped by the interface.""" */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pcap.pcap.stats", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":366 * return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) * * def __iter__(self): # <<<<<<<<<<<<<< * pcap_ex_setup(self.__pcap) * return self */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_29__iter__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_29__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_28__iter__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_28__iter__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); /* "pcap.pyx":367 * * def __iter__(self): * pcap_ex_setup(self.__pcap) # <<<<<<<<<<<<<< * return self * */ pcap_ex_setup(__pyx_v_self->__pyx___pcap); /* "pcap.pyx":368 * def __iter__(self): * pcap_ex_setup(self.__pcap) * return self # <<<<<<<<<<<<<< * * def __next__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; /* "pcap.pyx":366 * return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) * * def __iter__(self): # <<<<<<<<<<<<<< * pcap_ex_setup(self.__pcap) * return self */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":370 * return self * * def __next__(self): # <<<<<<<<<<<<<< * cdef pcap_pkthdr *hdr * cdef char *pkt */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_4pcap_31__next__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_4pcap_4pcap_31__next__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4pcap_30__next__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4pcap_30__next__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { struct pcap_pkthdr *__pyx_v_hdr; char *__pyx_v_pkt; int __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__next__", 0); /* "pcap.pyx":374 * cdef char *pkt * cdef int n * while 1: # <<<<<<<<<<<<<< * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) */ while (1) { /* "pcap.pyx":375 * cdef int n * while 1: * Py_BEGIN_ALLOW_THREADS # <<<<<<<<<<<<<< * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS */ Py_BEGIN_ALLOW_THREADS; /* "pcap.pyx":376 * while 1: * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) # <<<<<<<<<<<<<< * Py_END_ALLOW_THREADS * if n == 1: */ __pyx_v_n = pcap_ex_next(__pyx_v_self->__pyx___pcap, (&__pyx_v_hdr), (&__pyx_v_pkt)); /* "pcap.pyx":377 * Py_BEGIN_ALLOW_THREADS * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS # <<<<<<<<<<<<<< * if n == 1: * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), */ Py_END_ALLOW_THREADS; /* "pcap.pyx":385 * elif n == -1: * raise KeyboardInterrupt * elif n == -2: # <<<<<<<<<<<<<< * raise StopIteration * */ switch (__pyx_v_n) { /* "pcap.pyx":378 * n = pcap_ex_next(self.__pcap, &hdr, &pkt) * Py_END_ALLOW_THREADS * if n == 1: # <<<<<<<<<<<<<< * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen)) */ case 1: /* "pcap.pyx":379 * Py_END_ALLOW_THREADS * if n == 1: * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen)) * elif n == 0: */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); /* "pcap.pyx":380 * if n == 1: * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen)) # <<<<<<<<<<<<<< * elif n == 0: * return None */ __pyx_t_2 = PyBuffer_FromMemory(__pyx_v_pkt, __pyx_v_hdr->caplen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); /* "pcap.pyx":379 * Py_END_ALLOW_THREADS * if n == 1: * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), # <<<<<<<<<<<<<< * PyBuffer_FromMemory(pkt, hdr.caplen)) * elif n == 0: */ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; break; /* "pcap.pyx":381 * return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), * PyBuffer_FromMemory(pkt, hdr.caplen)) * elif n == 0: # <<<<<<<<<<<<<< * return None * elif n == -1: */ case 0: /* "pcap.pyx":382 * PyBuffer_FromMemory(pkt, hdr.caplen)) * elif n == 0: * return None # <<<<<<<<<<<<<< * elif n == -1: * raise KeyboardInterrupt */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = Py_None; goto __pyx_L0; break; /* "pcap.pyx":383 * elif n == 0: * return None * elif n == -1: # <<<<<<<<<<<<<< * raise KeyboardInterrupt * elif n == -2: */ case -1: /* "pcap.pyx":384 * return None * elif n == -1: * raise KeyboardInterrupt # <<<<<<<<<<<<<< * elif n == -2: * raise StopIteration */ __Pyx_Raise(__pyx_builtin_KeyboardInterrupt, 0, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; /* "pcap.pyx":385 * elif n == -1: * raise KeyboardInterrupt * elif n == -2: # <<<<<<<<<<<<<< * raise StopIteration * */ case -2: /* "pcap.pyx":386 * raise KeyboardInterrupt * elif n == -2: * raise StopIteration # <<<<<<<<<<<<<< * * def __dealloc__(self): */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; default: break; } } /* "pcap.pyx":370 * return self * * def __next__(self): # <<<<<<<<<<<<<< * cdef pcap_pkthdr *hdr * cdef char *pkt */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pcap.pcap.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":388 * raise StopIteration * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.__name: * free(self.__name) */ /* Python wrapper */ static void __pyx_pw_4pcap_4pcap_33__dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_pw_4pcap_4pcap_33__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); __pyx_pf_4pcap_4pcap_32__dealloc__(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); } static void __pyx_pf_4pcap_4pcap_32__dealloc__(struct __pyx_obj_4pcap_pcap *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); /* "pcap.pyx":389 * * def __dealloc__(self): * if self.__name: # <<<<<<<<<<<<<< * free(self.__name) * if self.__filter: */ __pyx_t_1 = (__pyx_v_self->__pyx___name != 0); if (__pyx_t_1) { /* "pcap.pyx":390 * def __dealloc__(self): * if self.__name: * free(self.__name) # <<<<<<<<<<<<<< * if self.__filter: * free(self.__filter) */ free(__pyx_v_self->__pyx___name); goto __pyx_L3; } __pyx_L3:; /* "pcap.pyx":391 * if self.__name: * free(self.__name) * if self.__filter: # <<<<<<<<<<<<<< * free(self.__filter) * if self.__pcap: */ __pyx_t_1 = (__pyx_v_self->__pyx___filter != 0); if (__pyx_t_1) { /* "pcap.pyx":392 * free(self.__name) * if self.__filter: * free(self.__filter) # <<<<<<<<<<<<<< * if self.__pcap: * pcap_close(self.__pcap) */ free(__pyx_v_self->__pyx___filter); goto __pyx_L4; } __pyx_L4:; /* "pcap.pyx":393 * if self.__filter: * free(self.__filter) * if self.__pcap: # <<<<<<<<<<<<<< * pcap_close(self.__pcap) * */ __pyx_t_1 = (__pyx_v_self->__pyx___pcap != 0); if (__pyx_t_1) { /* "pcap.pyx":394 * free(self.__filter) * if self.__pcap: * pcap_close(self.__pcap) # <<<<<<<<<<<<<< * * def ex_name(char *foo): */ pcap_close(__pyx_v_self->__pyx___pcap); goto __pyx_L5; } __pyx_L5:; /* "pcap.pyx":388 * raise StopIteration * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.__name: * free(self.__name) */ /* function exit code */ __Pyx_RefNannyFinishContext(); } /* "pcap.pyx":396 * pcap_close(self.__pcap) * * def ex_name(char *foo): # <<<<<<<<<<<<<< * return pcap_ex_name(foo) * */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_1ex_name(PyObject *__pyx_self, PyObject *__pyx_arg_foo); /*proto*/ static PyMethodDef __pyx_mdef_4pcap_1ex_name = {"ex_name", (PyCFunction)__pyx_pw_4pcap_1ex_name, METH_O, 0}; static PyObject *__pyx_pw_4pcap_1ex_name(PyObject *__pyx_self, PyObject *__pyx_arg_foo) { char *__pyx_v_foo; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("ex_name (wrapper)", 0); assert(__pyx_arg_foo); { __pyx_v_foo = __Pyx_PyObject_AsString(__pyx_arg_foo); if (unlikely((!__pyx_v_foo) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("pcap.ex_name", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_ex_name(__pyx_self, ((char *)__pyx_v_foo)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_ex_name(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_foo) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("ex_name", 0); /* "pcap.pyx":397 * * def ex_name(char *foo): * return pcap_ex_name(foo) # <<<<<<<<<<<<<< * * def lookupdev(): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyBytes_FromString(pcap_ex_name(__pyx_v_foo)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "pcap.pyx":396 * pcap_close(self.__pcap) * * def ex_name(char *foo): # <<<<<<<<<<<<<< * return pcap_ex_name(foo) * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("pcap.ex_name", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":399 * return pcap_ex_name(foo) * * def lookupdev(): # <<<<<<<<<<<<<< * """Return the name of a network device suitable for sniffing.""" * cdef char *p */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_3lookupdev(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_2lookupdev[] = "Return the name of a network device suitable for sniffing."; static PyMethodDef __pyx_mdef_4pcap_3lookupdev = {"lookupdev", (PyCFunction)__pyx_pw_4pcap_3lookupdev, METH_NOARGS, __pyx_doc_4pcap_2lookupdev}; static PyObject *__pyx_pw_4pcap_3lookupdev(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("lookupdev (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_2lookupdev(__pyx_self); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_2lookupdev(CYTHON_UNUSED PyObject *__pyx_self) { char *__pyx_v_p; char __pyx_v_ebuf[256]; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lookupdev", 0); /* "pcap.pyx":403 * cdef char *p * cdef char ebuf[256] * p = pcap_ex_lookupdev(ebuf) # <<<<<<<<<<<<<< * if p == NULL: * raise OSError, ebuf */ __pyx_v_p = pcap_ex_lookupdev(__pyx_v_ebuf); /* "pcap.pyx":404 * cdef char ebuf[256] * p = pcap_ex_lookupdev(ebuf) * if p == NULL: # <<<<<<<<<<<<<< * raise OSError, ebuf * return p */ __pyx_t_1 = ((__pyx_v_p == NULL) != 0); if (__pyx_t_1) { /* "pcap.pyx":405 * p = pcap_ex_lookupdev(ebuf) * if p == NULL: * raise OSError, ebuf # <<<<<<<<<<<<<< * return p * */ __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_ebuf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_builtin_OSError, __pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":406 * if p == NULL: * raise OSError, ebuf * return p # <<<<<<<<<<<<<< * * def findalldevs(): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_p); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; /* "pcap.pyx":399 * return pcap_ex_name(foo) * * def lookupdev(): # <<<<<<<<<<<<<< * """Return the name of a network device suitable for sniffing.""" * cdef char *p */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("pcap.lookupdev", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":408 * return p * * def findalldevs(): # <<<<<<<<<<<<<< * """Return a list of capture devices.""" * cdef pcap_if_t *devs */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_5findalldevs(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_4pcap_4findalldevs[] = "Return a list of capture devices."; static PyMethodDef __pyx_mdef_4pcap_5findalldevs = {"findalldevs", (PyCFunction)__pyx_pw_4pcap_5findalldevs, METH_NOARGS, __pyx_doc_4pcap_4findalldevs}; static PyObject *__pyx_pw_4pcap_5findalldevs(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("findalldevs (wrapper)", 0); __pyx_r = __pyx_pf_4pcap_4findalldevs(__pyx_self); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_4findalldevs(CYTHON_UNUSED PyObject *__pyx_self) { pcap_if_t *__pyx_v_devs; pcap_if_t *__pyx_v_curr; char __pyx_v_ebuf[256]; int __pyx_v_status; PyObject *__pyx_v_retval = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; pcap_if_t *__pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("findalldevs", 0); /* "pcap.pyx":414 * cdef char ebuf[256] * * status = pcap_findalldevs(&devs, ebuf) # <<<<<<<<<<<<<< * if status: * raise OSError(ebuf) */ __pyx_v_status = pcap_findalldevs((&__pyx_v_devs), __pyx_v_ebuf); /* "pcap.pyx":415 * * status = pcap_findalldevs(&devs, ebuf) * if status: # <<<<<<<<<<<<<< * raise OSError(ebuf) * retval = [] */ __pyx_t_1 = (__pyx_v_status != 0); if (__pyx_t_1) { /* "pcap.pyx":416 * status = pcap_findalldevs(&devs, ebuf) * if status: * raise OSError(ebuf) # <<<<<<<<<<<<<< * retval = [] * if not devs: */ __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_ebuf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":417 * if status: * raise OSError(ebuf) * retval = [] # <<<<<<<<<<<<<< * if not devs: * return retval */ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_v_retval = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "pcap.pyx":418 * raise OSError(ebuf) * retval = [] * if not devs: # <<<<<<<<<<<<<< * return retval * curr = devs */ __pyx_t_1 = ((!(__pyx_v_devs != 0)) != 0); if (__pyx_t_1) { /* "pcap.pyx":419 * retval = [] * if not devs: * return retval # <<<<<<<<<<<<<< * curr = devs * while 1: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_retval); __pyx_r = __pyx_v_retval; goto __pyx_L0; } /* "pcap.pyx":420 * if not devs: * return retval * curr = devs # <<<<<<<<<<<<<< * while 1: * retval.append(curr.name) */ __pyx_v_curr = __pyx_v_devs; /* "pcap.pyx":421 * return retval * curr = devs * while 1: # <<<<<<<<<<<<<< * retval.append(curr.name) * if not curr.next: */ while (1) { /* "pcap.pyx":422 * curr = devs * while 1: * retval.append(curr.name) # <<<<<<<<<<<<<< * if not curr.next: * break */ __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_curr->name); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_retval, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pcap.pyx":423 * while 1: * retval.append(curr.name) * if not curr.next: # <<<<<<<<<<<<<< * break * curr = curr.next */ __pyx_t_1 = ((!(__pyx_v_curr->next != 0)) != 0); if (__pyx_t_1) { /* "pcap.pyx":424 * retval.append(curr.name) * if not curr.next: * break # <<<<<<<<<<<<<< * curr = curr.next * pcap_freealldevs(devs) */ goto __pyx_L6_break; } /* "pcap.pyx":425 * if not curr.next: * break * curr = curr.next # <<<<<<<<<<<<<< * pcap_freealldevs(devs) * return retval */ __pyx_t_5 = __pyx_v_curr->next; __pyx_v_curr = __pyx_t_5; } __pyx_L6_break:; /* "pcap.pyx":426 * break * curr = curr.next * pcap_freealldevs(devs) # <<<<<<<<<<<<<< * return retval * */ pcap_freealldevs(__pyx_v_devs); /* "pcap.pyx":427 * curr = curr.next * pcap_freealldevs(devs) * return retval # <<<<<<<<<<<<<< * * def lookupnet(char *dev): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_retval); __pyx_r = __pyx_v_retval; goto __pyx_L0; /* "pcap.pyx":408 * return p * * def findalldevs(): # <<<<<<<<<<<<<< * """Return a list of capture devices.""" * cdef pcap_if_t *devs */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("pcap.findalldevs", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_retval); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "pcap.pyx":429 * return retval * * def lookupnet(char *dev): # <<<<<<<<<<<<<< * """ * Return the address and the netmask of a given device */ /* Python wrapper */ static PyObject *__pyx_pw_4pcap_7lookupnet(PyObject *__pyx_self, PyObject *__pyx_arg_dev); /*proto*/ static char __pyx_doc_4pcap_6lookupnet[] = "\n Return the address and the netmask of a given device\n as network-byteorder integers.\n "; static PyMethodDef __pyx_mdef_4pcap_7lookupnet = {"lookupnet", (PyCFunction)__pyx_pw_4pcap_7lookupnet, METH_O, __pyx_doc_4pcap_6lookupnet}; static PyObject *__pyx_pw_4pcap_7lookupnet(PyObject *__pyx_self, PyObject *__pyx_arg_dev) { char *__pyx_v_dev; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("lookupnet (wrapper)", 0); assert(__pyx_arg_dev); { __pyx_v_dev = __Pyx_PyObject_AsString(__pyx_arg_dev); if (unlikely((!__pyx_v_dev) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("pcap.lookupnet", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4pcap_6lookupnet(__pyx_self, ((char *)__pyx_v_dev)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4pcap_6lookupnet(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_dev) { unsigned int __pyx_v_netp; unsigned int __pyx_v_maskp; char __pyx_v_ebuf[256]; int __pyx_v_status; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lookupnet", 0); /* "pcap.pyx":438 * cdef char ebuf[256] * * status = pcap_lookupnet(dev, &netp, &maskp, ebuf) # <<<<<<<<<<<<<< * if status: * raise OSError(ebuf) */ __pyx_v_status = pcap_lookupnet(__pyx_v_dev, (&__pyx_v_netp), (&__pyx_v_maskp), __pyx_v_ebuf); /* "pcap.pyx":439 * * status = pcap_lookupnet(dev, &netp, &maskp, ebuf) * if status: # <<<<<<<<<<<<<< * raise OSError(ebuf) * return struct.pack('I', netp), struct.pack('I', maskp) */ __pyx_t_1 = (__pyx_v_status != 0); if (__pyx_t_1) { /* "pcap.pyx":440 * status = pcap_lookupnet(dev, &netp, &maskp, ebuf) * if status: * raise OSError(ebuf) # <<<<<<<<<<<<<< * return struct.pack('I', netp), struct.pack('I', maskp) */ __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_ebuf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } /* "pcap.pyx":441 * if status: * raise OSError(ebuf) * return struct.pack('I', netp), struct.pack('I', maskp) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_pack); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_netp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = NULL; __pyx_t_6 = 0; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_5) { PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL; } __Pyx_INCREF(__pyx_n_s_I); PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_s_I); __Pyx_GIVEREF(__pyx_n_s_I); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_pack); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyInt_From_unsigned_int(__pyx_v_maskp); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_5 = NULL; __pyx_t_6 = 0; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } __pyx_t_8 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_5) { PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL; } __Pyx_INCREF(__pyx_n_s_I); PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_6, __pyx_n_s_I); __Pyx_GIVEREF(__pyx_n_s_I); PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_6, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; /* "pcap.pyx":429 * return retval * * def lookupnet(char *dev): # <<<<<<<<<<<<<< * """ * Return the address and the netmask of a given device */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("pcap.lookupnet", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_tp_new_4pcap_bpf(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; return o; } static void __pyx_tp_dealloc_4pcap_bpf(PyObject *o) { #if PY_VERSION_HEX >= 0x030400a1 if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_pw_4pcap_3bpf_5__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } static PyMethodDef __pyx_methods_4pcap_bpf[] = { {"filter", (PyCFunction)__pyx_pw_4pcap_3bpf_3filter, METH_O, __pyx_doc_4pcap_3bpf_2filter}, {0, 0, 0, 0} }; static PyTypeObject __pyx_type_4pcap_bpf = { PyVarObject_HEAD_INIT(0, 0) "pcap.bpf", /*tp_name*/ sizeof(struct __pyx_obj_4pcap_bpf), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_4pcap_bpf, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ "bpf(filter, dlt=DLT_RAW) -> BPF filter object", /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_4pcap_bpf, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_4pcap_3bpf_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_4pcap_bpf, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; static PyObject *__pyx_tp_new_4pcap_pcap(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; return o; } static void __pyx_tp_dealloc_4pcap_pcap(PyObject *o) { #if PY_VERSION_HEX >= 0x030400a1 if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); __pyx_pw_4pcap_4pcap_33__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } static PyObject *__pyx_getprop_4pcap_4pcap_name(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_4pcap_4pcap_4name_1__get__(o); } static PyObject *__pyx_getprop_4pcap_4pcap_snaplen(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_4pcap_4pcap_7snaplen_1__get__(o); } static PyObject *__pyx_getprop_4pcap_4pcap_dloff(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_4pcap_4pcap_5dloff_1__get__(o); } static PyObject *__pyx_getprop_4pcap_4pcap_filter(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_4pcap_4pcap_6filter_1__get__(o); } static PyObject *__pyx_getprop_4pcap_4pcap_fd(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_4pcap_4pcap_2fd_1__get__(o); } static PyMethodDef __pyx_methods_4pcap_pcap[] = { {"fileno", (PyCFunction)__pyx_pw_4pcap_4pcap_3fileno, METH_NOARGS, __pyx_doc_4pcap_4pcap_2fileno}, {"setfilter", (PyCFunction)__pyx_pw_4pcap_4pcap_5setfilter, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_4setfilter}, {"setdirection", (PyCFunction)__pyx_pw_4pcap_4pcap_7setdirection, METH_O, __pyx_doc_4pcap_4pcap_6setdirection}, {"setnonblock", (PyCFunction)__pyx_pw_4pcap_4pcap_9setnonblock, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_8setnonblock}, {"getnonblock", (PyCFunction)__pyx_pw_4pcap_4pcap_11getnonblock, METH_NOARGS, __pyx_doc_4pcap_4pcap_10getnonblock}, {"datalink", (PyCFunction)__pyx_pw_4pcap_4pcap_13datalink, METH_NOARGS, __pyx_doc_4pcap_4pcap_12datalink}, {"__add_pkts", (PyCFunction)__pyx_pw_4pcap_4pcap_15__add_pkts, METH_VARARGS|METH_KEYWORDS, 0}, {"readpkts", (PyCFunction)__pyx_pw_4pcap_4pcap_17readpkts, METH_NOARGS, __pyx_doc_4pcap_4pcap_16readpkts}, {"dispatch", (PyCFunction)__pyx_pw_4pcap_4pcap_19dispatch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_18dispatch}, {"loop", (PyCFunction)__pyx_pw_4pcap_4pcap_21loop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_20loop}, {"sendpacket", (PyCFunction)__pyx_pw_4pcap_4pcap_23sendpacket, METH_O, __pyx_doc_4pcap_4pcap_22sendpacket}, {"geterr", (PyCFunction)__pyx_pw_4pcap_4pcap_25geterr, METH_NOARGS, __pyx_doc_4pcap_4pcap_24geterr}, {"stats", (PyCFunction)__pyx_pw_4pcap_4pcap_27stats, METH_NOARGS, __pyx_doc_4pcap_4pcap_26stats}, {"__next__", (PyCFunction)__pyx_pw_4pcap_4pcap_31__next__, METH_NOARGS|METH_COEXIST, 0}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_4pcap_pcap[] = { {(char *)"name", __pyx_getprop_4pcap_4pcap_name, 0, __pyx_k_Network_interface_or_dumpfile_na, 0}, {(char *)"snaplen", __pyx_getprop_4pcap_4pcap_snaplen, 0, __pyx_k_Maximum_number_of_bytes_to_captu, 0}, {(char *)"dloff", __pyx_getprop_4pcap_4pcap_dloff, 0, __pyx_k_Datalink_offset_length_of_layer, 0}, {(char *)"filter", __pyx_getprop_4pcap_4pcap_filter, 0, __pyx_k_Current_packet_capture_filter, 0}, {(char *)"fd", __pyx_getprop_4pcap_4pcap_fd, 0, __pyx_k_File_descriptor_or_Win32_HANDLE, 0}, {0, 0, 0, 0, 0} }; static PyTypeObject __pyx_type_4pcap_pcap = { PyVarObject_HEAD_INIT(0, 0) "pcap.pcap", /*tp_name*/ sizeof(struct __pyx_obj_4pcap_pcap), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_4pcap_pcap, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ "pcap(name=None, snaplen=65535, promisc=True, timeout_ms=None, immediate=False) -> packet capture object\n \n Open a handle to a packet capture descriptor.\n \n Keyword arguments:\n name -- name of a network interface or dumpfile to open,\n or None to open the first available up interface\n snaplen -- maximum number of bytes to capture for each packet\n promisc -- boolean to specify promiscuous mode sniffing\n timeout_ms -- requests for the next packet will return None if the timeout\n (in milliseconds) is reached and no packets were received\n (Default: no timeout) \n immediate -- disable buffering, if possible\n ", /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ __pyx_pw_4pcap_4pcap_29__iter__, /*tp_iter*/ __pyx_pw_4pcap_4pcap_31__next__, /*tp_iternext*/ __pyx_methods_4pcap_pcap, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_4pcap_pcap, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_4pcap_4pcap_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_4pcap_pcap, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { #if PY_VERSION_HEX < 0x03020000 { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, #else PyModuleDef_HEAD_INIT, #endif "pcap", __pyx_k_packet_capture_library_This_modu, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_1_1, __pyx_k_1_1, sizeof(__pyx_k_1_1), 0, 0, 1, 0}, {&__pyx_kp_s_BSD_license, __pyx_k_BSD_license, sizeof(__pyx_k_BSD_license), 0, 0, 1, 0}, {&__pyx_kp_s_Copyright_c_2004_Dug_Song, __pyx_k_Copyright_c_2004_Dug_Song, sizeof(__pyx_k_Copyright_c_2004_Dug_Song), 0, 0, 1, 0}, {&__pyx_n_s_DLT_ARCNET, __pyx_k_DLT_ARCNET, sizeof(__pyx_k_DLT_ARCNET), 0, 0, 1, 1}, {&__pyx_n_s_DLT_AX25, __pyx_k_DLT_AX25, sizeof(__pyx_k_DLT_AX25), 0, 0, 1, 1}, {&__pyx_n_s_DLT_CHAOS, __pyx_k_DLT_CHAOS, sizeof(__pyx_k_DLT_CHAOS), 0, 0, 1, 1}, {&__pyx_n_s_DLT_EN10MB, __pyx_k_DLT_EN10MB, sizeof(__pyx_k_DLT_EN10MB), 0, 0, 1, 1}, {&__pyx_n_s_DLT_EN3MB, __pyx_k_DLT_EN3MB, sizeof(__pyx_k_DLT_EN3MB), 0, 0, 1, 1}, {&__pyx_n_s_DLT_FDDI, __pyx_k_DLT_FDDI, sizeof(__pyx_k_DLT_FDDI), 0, 0, 1, 1}, {&__pyx_n_s_DLT_IEEE802, __pyx_k_DLT_IEEE802, sizeof(__pyx_k_DLT_IEEE802), 0, 0, 1, 1}, {&__pyx_n_s_DLT_LINUX_SLL, __pyx_k_DLT_LINUX_SLL, sizeof(__pyx_k_DLT_LINUX_SLL), 0, 0, 1, 1}, {&__pyx_n_s_DLT_LOOP, __pyx_k_DLT_LOOP, sizeof(__pyx_k_DLT_LOOP), 0, 0, 1, 1}, {&__pyx_n_s_DLT_NULL, __pyx_k_DLT_NULL, sizeof(__pyx_k_DLT_NULL), 0, 0, 1, 1}, {&__pyx_n_s_DLT_PFLOG, __pyx_k_DLT_PFLOG, sizeof(__pyx_k_DLT_PFLOG), 0, 0, 1, 1}, {&__pyx_n_s_DLT_PFSYNC, __pyx_k_DLT_PFSYNC, sizeof(__pyx_k_DLT_PFSYNC), 0, 0, 1, 1}, {&__pyx_n_s_DLT_PPP, __pyx_k_DLT_PPP, sizeof(__pyx_k_DLT_PPP), 0, 0, 1, 1}, {&__pyx_n_s_DLT_PRONET, __pyx_k_DLT_PRONET, sizeof(__pyx_k_DLT_PRONET), 0, 0, 1, 1}, {&__pyx_n_s_DLT_RAW, __pyx_k_DLT_RAW, sizeof(__pyx_k_DLT_RAW), 0, 0, 1, 1}, {&__pyx_n_s_DLT_SLIP, __pyx_k_DLT_SLIP, sizeof(__pyx_k_DLT_SLIP), 0, 0, 1, 1}, {&__pyx_kp_s_Dug_Song_dugsong_monkey_org, __pyx_k_Dug_Song_dugsong_monkey_org, sizeof(__pyx_k_Dug_Song_dugsong_monkey_org), 0, 0, 1, 0}, {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1}, {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, {&__pyx_n_s_KeyboardInterrupt, __pyx_k_KeyboardInterrupt, sizeof(__pyx_k_KeyboardInterrupt), 0, 0, 1, 1}, {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, {&__pyx_n_s_PCAP_D_IN, __pyx_k_PCAP_D_IN, sizeof(__pyx_k_PCAP_D_IN), 0, 0, 1, 1}, {&__pyx_n_s_PCAP_D_INOUT, __pyx_k_PCAP_D_INOUT, sizeof(__pyx_k_PCAP_D_INOUT), 0, 0, 1, 1}, {&__pyx_n_s_PCAP_D_OUT, __pyx_k_PCAP_D_OUT, sizeof(__pyx_k_PCAP_D_OUT), 0, 0, 1, 1}, {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_add_pkts, __pyx_k_add_pkts, sizeof(__pyx_k_add_pkts), 0, 0, 1, 1}, {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, {&__pyx_n_s_author, __pyx_k_author, sizeof(__pyx_k_author), 0, 0, 1, 1}, {&__pyx_kp_s_bad_filter, __pyx_k_bad_filter, sizeof(__pyx_k_bad_filter), 0, 0, 1, 0}, {&__pyx_n_s_callback, __pyx_k_callback, sizeof(__pyx_k_callback), 0, 0, 1, 1}, {&__pyx_n_s_cnt, __pyx_k_cnt, sizeof(__pyx_k_cnt), 0, 0, 1, 1}, {&__pyx_n_s_copyright, __pyx_k_copyright, sizeof(__pyx_k_copyright), 0, 0, 1, 1}, {&__pyx_kp_s_couldn_t_enable_immediate_mode, __pyx_k_couldn_t_enable_immediate_mode, sizeof(__pyx_k_couldn_t_enable_immediate_mode), 0, 0, 1, 0}, {&__pyx_n_s_curr, __pyx_k_curr, sizeof(__pyx_k_curr), 0, 0, 1, 1}, {&__pyx_n_s_dev, __pyx_k_dev, sizeof(__pyx_k_dev), 0, 0, 1, 1}, {&__pyx_n_s_devs, __pyx_k_devs, sizeof(__pyx_k_devs), 0, 0, 1, 1}, {&__pyx_n_s_dispatch, __pyx_k_dispatch, sizeof(__pyx_k_dispatch), 0, 0, 1, 1}, {&__pyx_n_s_dlt, __pyx_k_dlt, sizeof(__pyx_k_dlt), 0, 0, 1, 1}, {&__pyx_n_s_dltoff, __pyx_k_dltoff, sizeof(__pyx_k_dltoff), 0, 0, 1, 1}, {&__pyx_n_s_ebuf, __pyx_k_ebuf, sizeof(__pyx_k_ebuf), 0, 0, 1, 1}, {&__pyx_n_s_ex_name, __pyx_k_ex_name, sizeof(__pyx_k_ex_name), 0, 0, 1, 1}, {&__pyx_n_s_exc_info, __pyx_k_exc_info, sizeof(__pyx_k_exc_info), 0, 0, 1, 1}, {&__pyx_n_s_filter, __pyx_k_filter, sizeof(__pyx_k_filter), 0, 0, 1, 1}, {&__pyx_n_s_find, __pyx_k_find, sizeof(__pyx_k_find), 0, 0, 1, 1}, {&__pyx_n_s_findalldevs, __pyx_k_findalldevs, sizeof(__pyx_k_findalldevs), 0, 0, 1, 1}, {&__pyx_n_s_foo, __pyx_k_foo, sizeof(__pyx_k_foo), 0, 0, 1, 1}, {&__pyx_kp_s_http_monkey_org_dugsong_pypcap, __pyx_k_http_monkey_org_dugsong_pypcap, sizeof(__pyx_k_http_monkey_org_dugsong_pypcap), 0, 0, 1, 0}, {&__pyx_n_s_immediate, __pyx_k_immediate, sizeof(__pyx_k_immediate), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_license, __pyx_k_license, sizeof(__pyx_k_license), 0, 0, 1, 1}, {&__pyx_n_s_lookupdev, __pyx_k_lookupdev, sizeof(__pyx_k_lookupdev), 0, 0, 1, 1}, {&__pyx_n_s_lookupnet, __pyx_k_lookupnet, sizeof(__pyx_k_lookupnet), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_maskp, __pyx_k_maskp, sizeof(__pyx_k_maskp), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_netp, __pyx_k_netp, sizeof(__pyx_k_netp), 0, 0, 1, 1}, {&__pyx_n_s_nonblock, __pyx_k_nonblock, sizeof(__pyx_k_nonblock), 0, 0, 1, 1}, {&__pyx_n_s_openbsd, __pyx_k_openbsd, sizeof(__pyx_k_openbsd), 0, 0, 1, 1}, {&__pyx_n_s_optimize, __pyx_k_optimize, sizeof(__pyx_k_optimize), 0, 0, 1, 1}, {&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1}, {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1}, {&__pyx_n_s_pcap, __pyx_k_pcap, sizeof(__pyx_k_pcap), 0, 0, 1, 1}, {&__pyx_n_s_pkt, __pyx_k_pkt, sizeof(__pyx_k_pkt), 0, 0, 1, 1}, {&__pyx_n_s_pkts, __pyx_k_pkts, sizeof(__pyx_k_pkts), 0, 0, 1, 1}, {&__pyx_n_s_platform, __pyx_k_platform, sizeof(__pyx_k_platform), 0, 0, 1, 1}, {&__pyx_n_s_promisc, __pyx_k_promisc, sizeof(__pyx_k_promisc), 0, 0, 1, 1}, {&__pyx_n_s_retval, __pyx_k_retval, sizeof(__pyx_k_retval), 0, 0, 1, 1}, {&__pyx_kp_s_root_pypcap_pcap_pyx, __pyx_k_root_pypcap_pcap_pyx, sizeof(__pyx_k_root_pypcap_pcap_pyx), 0, 0, 1, 0}, {&__pyx_n_s_snaplen, __pyx_k_snaplen, sizeof(__pyx_k_snaplen), 0, 0, 1, 1}, {&__pyx_n_s_status, __pyx_k_status, sizeof(__pyx_k_status), 0, 0, 1, 1}, {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_timeout_ms, __pyx_k_timeout_ms, sizeof(__pyx_k_timeout_ms), 0, 0, 1, 1}, {&__pyx_n_s_ts, __pyx_k_ts, sizeof(__pyx_k_ts), 0, 0, 1, 1}, {&__pyx_n_s_url, __pyx_k_url, sizeof(__pyx_k_url), 0, 0, 1, 1}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_KeyboardInterrupt = __Pyx_GetBuiltinName(__pyx_n_s_KeyboardInterrupt); if (!__pyx_builtin_KeyboardInterrupt) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "pcap.pyx":132 * DLT_PFLOG = 117 * DLT_PFSYNC = 18 * if sys.platform.find('openbsd') != -1: # <<<<<<<<<<<<<< * DLT_LOOP = 12 * DLT_RAW = 14 */ __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_openbsd); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); /* "pcap.pyx":396 * pcap_close(self.__pcap) * * def ex_name(char *foo): # <<<<<<<<<<<<<< * return pcap_ex_name(foo) * */ __pyx_tuple__4 = PyTuple_Pack(2, __pyx_n_s_foo, __pyx_n_s_foo); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_root_pypcap_pcap_pyx, __pyx_n_s_ex_name, 396, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":399 * return pcap_ex_name(foo) * * def lookupdev(): # <<<<<<<<<<<<<< * """Return the name of a network device suitable for sniffing.""" * cdef char *p */ __pyx_tuple__6 = PyTuple_Pack(2, __pyx_n_s_p, __pyx_n_s_ebuf); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_root_pypcap_pcap_pyx, __pyx_n_s_lookupdev, 399, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":408 * return p * * def findalldevs(): # <<<<<<<<<<<<<< * """Return a list of capture devices.""" * cdef pcap_if_t *devs */ __pyx_tuple__8 = PyTuple_Pack(5, __pyx_n_s_devs, __pyx_n_s_curr, __pyx_n_s_ebuf, __pyx_n_s_status, __pyx_n_s_retval); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_root_pypcap_pcap_pyx, __pyx_n_s_findalldevs, 408, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":429 * return retval * * def lookupnet(char *dev): # <<<<<<<<<<<<<< * """ * Return the address and the netmask of a given device */ __pyx_tuple__10 = PyTuple_Pack(6, __pyx_n_s_dev, __pyx_n_s_dev, __pyx_n_s_netp, __pyx_n_s_maskp, __pyx_n_s_ebuf, __pyx_n_s_status); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_root_pypcap_pcap_pyx, __pyx_n_s_lookupnet, 429, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_9 = PyInt_FromLong(9); if (unlikely(!__pyx_int_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_12 = PyInt_FromLong(12); if (unlikely(!__pyx_int_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_14 = PyInt_FromLong(14); if (unlikely(!__pyx_int_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_18 = PyInt_FromLong(18); if (unlikely(!__pyx_int_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_21 = PyInt_FromLong(21); if (unlikely(!__pyx_int_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_22 = PyInt_FromLong(22); if (unlikely(!__pyx_int_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_48 = PyInt_FromLong(48); if (unlikely(!__pyx_int_48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_108 = PyInt_FromLong(108); if (unlikely(!__pyx_int_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_113 = PyInt_FromLong(113); if (unlikely(!__pyx_int_113)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_117 = PyInt_FromLong(117); if (unlikely(!__pyx_int_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_65535 = PyInt_FromLong(65535L); if (unlikely(!__pyx_int_65535)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initpcap(void); /*proto*/ PyMODINIT_FUNC initpcap(void) #else PyMODINIT_FUNC PyInit_pcap(void); /*proto*/ PyMODINIT_FUNC PyInit_pcap(void) #endif { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_pcap(void)", 0); if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __Pyx_CyFunction_USED if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("pcap", __pyx_methods, __pyx_k_packet_capture_library_This_modu, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif if (__pyx_module_is_main_pcap) { if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (!PyDict_GetItemString(modules, "pcap")) { if (unlikely(PyDict_SetItemString(modules, "pcap", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } #endif /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Global init code ---*/ /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type_4pcap_bpf) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_type_4pcap_bpf.tp_print = 0; if (PyObject_SetAttrString(__pyx_m, "bpf", (PyObject *)&__pyx_type_4pcap_bpf) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_4pcap_bpf = &__pyx_type_4pcap_bpf; if (PyType_Ready(&__pyx_type_4pcap_pcap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_type_4pcap_pcap.tp_print = 0; if (PyObject_SetAttrString(__pyx_m, "pcap", (PyObject *)&__pyx_type_4pcap_pcap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_4pcap_pcap = &__pyx_type_4pcap_pcap; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "pcap.pyx":13 * """ * * __author__ = 'Dug Song ' # <<<<<<<<<<<<<< * __copyright__ = 'Copyright (c) 2004 Dug Song' * __license__ = 'BSD license' */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_author, __pyx_kp_s_Dug_Song_dugsong_monkey_org) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":14 * * __author__ = 'Dug Song ' * __copyright__ = 'Copyright (c) 2004 Dug Song' # <<<<<<<<<<<<<< * __license__ = 'BSD license' * __url__ = 'http://monkey.org/~dugsong/pypcap/' */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_copyright, __pyx_kp_s_Copyright_c_2004_Dug_Song) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":15 * __author__ = 'Dug Song ' * __copyright__ = 'Copyright (c) 2004 Dug Song' * __license__ = 'BSD license' # <<<<<<<<<<<<<< * __url__ = 'http://monkey.org/~dugsong/pypcap/' * __version__ = '1.1' */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_license, __pyx_kp_s_BSD_license) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":16 * __copyright__ = 'Copyright (c) 2004 Dug Song' * __license__ = 'BSD license' * __url__ = 'http://monkey.org/~dugsong/pypcap/' # <<<<<<<<<<<<<< * __version__ = '1.1' * */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_url, __pyx_kp_s_http_monkey_org_dugsong_pypcap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":17 * __license__ = 'BSD license' * __url__ = 'http://monkey.org/~dugsong/pypcap/' * __version__ = '1.1' # <<<<<<<<<<<<<< * * import sys */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_s_1_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":19 * __version__ = '1.1' * * import sys # <<<<<<<<<<<<<< * import struct * */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":20 * * import sys * import struct # <<<<<<<<<<<<<< * * cdef extern from "Python.h": */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":116 * PyGILState_Release(gil) * * DLT_NULL = 0 # <<<<<<<<<<<<<< * DLT_EN10MB = 1 * DLT_EN3MB = 2 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_NULL, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":117 * * DLT_NULL = 0 * DLT_EN10MB = 1 # <<<<<<<<<<<<<< * DLT_EN3MB = 2 * DLT_AX25 = 3 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_EN10MB, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":118 * DLT_NULL = 0 * DLT_EN10MB = 1 * DLT_EN3MB = 2 # <<<<<<<<<<<<<< * DLT_AX25 = 3 * DLT_PRONET = 4 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_EN3MB, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":119 * DLT_EN10MB = 1 * DLT_EN3MB = 2 * DLT_AX25 = 3 # <<<<<<<<<<<<<< * DLT_PRONET = 4 * DLT_CHAOS = 5 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_AX25, __pyx_int_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":120 * DLT_EN3MB = 2 * DLT_AX25 = 3 * DLT_PRONET = 4 # <<<<<<<<<<<<<< * DLT_CHAOS = 5 * DLT_IEEE802 = 6 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_PRONET, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":121 * DLT_AX25 = 3 * DLT_PRONET = 4 * DLT_CHAOS = 5 # <<<<<<<<<<<<<< * DLT_IEEE802 = 6 * DLT_ARCNET = 7 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_CHAOS, __pyx_int_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":122 * DLT_PRONET = 4 * DLT_CHAOS = 5 * DLT_IEEE802 = 6 # <<<<<<<<<<<<<< * DLT_ARCNET = 7 * DLT_SLIP = 8 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_IEEE802, __pyx_int_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":123 * DLT_CHAOS = 5 * DLT_IEEE802 = 6 * DLT_ARCNET = 7 # <<<<<<<<<<<<<< * DLT_SLIP = 8 * DLT_PPP = 9 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_ARCNET, __pyx_int_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":124 * DLT_IEEE802 = 6 * DLT_ARCNET = 7 * DLT_SLIP = 8 # <<<<<<<<<<<<<< * DLT_PPP = 9 * DLT_FDDI = 10 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_SLIP, __pyx_int_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":125 * DLT_ARCNET = 7 * DLT_SLIP = 8 * DLT_PPP = 9 # <<<<<<<<<<<<<< * DLT_FDDI = 10 * # XXX - Linux */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_PPP, __pyx_int_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":126 * DLT_SLIP = 8 * DLT_PPP = 9 * DLT_FDDI = 10 # <<<<<<<<<<<<<< * # XXX - Linux * DLT_LINUX_SLL = 113 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_FDDI, __pyx_int_10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":128 * DLT_FDDI = 10 * # XXX - Linux * DLT_LINUX_SLL = 113 # <<<<<<<<<<<<<< * # XXX - OpenBSD * DLT_PFLOG = 117 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_LINUX_SLL, __pyx_int_113) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":130 * DLT_LINUX_SLL = 113 * # XXX - OpenBSD * DLT_PFLOG = 117 # <<<<<<<<<<<<<< * DLT_PFSYNC = 18 * if sys.platform.find('openbsd') != -1: */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_PFLOG, __pyx_int_117) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":131 * # XXX - OpenBSD * DLT_PFLOG = 117 * DLT_PFSYNC = 18 # <<<<<<<<<<<<<< * if sys.platform.find('openbsd') != -1: * DLT_LOOP = 12 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_PFSYNC, __pyx_int_18) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":132 * DLT_PFLOG = 117 * DLT_PFSYNC = 18 * if sys.platform.find('openbsd') != -1: # <<<<<<<<<<<<<< * DLT_LOOP = 12 * DLT_RAW = 14 */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_platform); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_find); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_3) { /* "pcap.pyx":133 * DLT_PFSYNC = 18 * if sys.platform.find('openbsd') != -1: * DLT_LOOP = 12 # <<<<<<<<<<<<<< * DLT_RAW = 14 * else: */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_LOOP, __pyx_int_12) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":134 * if sys.platform.find('openbsd') != -1: * DLT_LOOP = 12 * DLT_RAW = 14 # <<<<<<<<<<<<<< * else: * DLT_LOOP = 108 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_RAW, __pyx_int_14) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L2; } /*else*/ { /* "pcap.pyx":136 * DLT_RAW = 14 * else: * DLT_LOOP = 108 # <<<<<<<<<<<<<< * DLT_RAW = 12 * */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_LOOP, __pyx_int_108) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":137 * else: * DLT_LOOP = 108 * DLT_RAW = 12 # <<<<<<<<<<<<<< * * PCAP_D_INOUT = 0 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_DLT_RAW, __pyx_int_12) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L2:; /* "pcap.pyx":139 * DLT_RAW = 12 * * PCAP_D_INOUT = 0 # <<<<<<<<<<<<<< * PCAP_D_IN = 1 * PCAP_D_OUT = 2 */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_PCAP_D_INOUT, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":140 * * PCAP_D_INOUT = 0 * PCAP_D_IN = 1 # <<<<<<<<<<<<<< * PCAP_D_OUT = 2 * */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_PCAP_D_IN, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":141 * PCAP_D_INOUT = 0 * PCAP_D_IN = 1 * PCAP_D_OUT = 2 # <<<<<<<<<<<<<< * * dltoff = { DLT_NULL:4, DLT_EN10MB:14, DLT_IEEE802:22, DLT_ARCNET:6, */ if (PyDict_SetItem(__pyx_d, __pyx_n_s_PCAP_D_OUT, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "pcap.pyx":143 * PCAP_D_OUT = 2 * * dltoff = { DLT_NULL:4, DLT_EN10MB:14, DLT_IEEE802:22, DLT_ARCNET:6, # <<<<<<<<<<<<<< * DLT_SLIP:16, DLT_PPP:4, DLT_FDDI:21, DLT_PFLOG:48, DLT_PFSYNC:4, * DLT_LOOP:4, DLT_RAW:0, DLT_LINUX_SLL:16 } */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_EN10MB); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_14) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_IEEE802); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_22) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_ARCNET); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pcap.pyx":144 * * dltoff = { DLT_NULL:4, DLT_EN10MB:14, DLT_IEEE802:22, DLT_ARCNET:6, * DLT_SLIP:16, DLT_PPP:4, DLT_FDDI:21, DLT_PFLOG:48, DLT_PFSYNC:4, # <<<<<<<<<<<<<< * DLT_LOOP:4, DLT_RAW:0, DLT_LINUX_SLL:16 } * */ __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_SLIP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_16) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_PPP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_FDDI); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_21) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_PFLOG); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_48) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_PFSYNC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pcap.pyx":145 * dltoff = { DLT_NULL:4, DLT_EN10MB:14, DLT_IEEE802:22, DLT_ARCNET:6, * DLT_SLIP:16, DLT_PPP:4, DLT_FDDI:21, DLT_PFLOG:48, DLT_PFSYNC:4, * DLT_LOOP:4, DLT_RAW:0, DLT_LINUX_SLL:16 } # <<<<<<<<<<<<<< * * cdef class bpf: */ __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_LOOP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_RAW); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_LINUX_SLL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_16) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_dltoff, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":150 * """bpf(filter, dlt=DLT_RAW) -> BPF filter object""" * cdef bpf_program fcode * def __init__(self, char *filter, dlt=DLT_RAW): # <<<<<<<<<<<<<< * if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: * raise IOError, 'bad filter' */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_DLT_RAW); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_k_ = __pyx_t_1; __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":396 * pcap_close(self.__pcap) * * def ex_name(char *foo): # <<<<<<<<<<<<<< * return pcap_ex_name(foo) * */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4pcap_1ex_name, NULL, __pyx_n_s_pcap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_ex_name, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":399 * return pcap_ex_name(foo) * * def lookupdev(): # <<<<<<<<<<<<<< * """Return the name of a network device suitable for sniffing.""" * cdef char *p */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4pcap_3lookupdev, NULL, __pyx_n_s_pcap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_lookupdev, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":408 * return p * * def findalldevs(): # <<<<<<<<<<<<<< * """Return a list of capture devices.""" * cdef pcap_if_t *devs */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4pcap_5findalldevs, NULL, __pyx_n_s_pcap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_findalldevs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":429 * return retval * * def lookupnet(char *dev): # <<<<<<<<<<<<<< * """ * Return the address and the netmask of a given device */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4pcap_7lookupnet, NULL, __pyx_n_s_pcap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_lookupnet, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pcap.pyx":1 * # # <<<<<<<<<<<<<< * # pcap.pyx * # */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init pcap", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init pcap"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* Runtime support code */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule((char *)modname); if (!m) goto end; p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { PyErr_Format(PyExc_NameError, #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; } #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; ternaryfunc call = func->ob_type->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; *value = tstate->exc_value; *tb = tstate->exc_traceback; Py_XINCREF(*type); Py_XINCREF(*value); Py_XINCREF(*tb); #else PyErr_GetExcInfo(type, value, tb); #endif } static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; tstate->exc_type = type; tstate->exc_value = value; tstate->exc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_SetExcInfo(type, value, tb); #endif } static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { PyObject *local_type, *local_value, *local_tb; #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); local_type = tstate->curexc_type; local_value = tstate->curexc_value; local_tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; #else PyErr_Fetch(&local_type, &local_value, &local_tb); #endif PyErr_NormalizeException(&local_type, &local_value, &local_tb); #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(tstate->curexc_type)) #else if (unlikely(PyErr_Occurred())) #endif goto bad; #if PY_MAJOR_VERSION >= 3 if (local_tb) { if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) goto bad; } #endif Py_XINCREF(local_tb); Py_XINCREF(local_type); Py_XINCREF(local_value); *type = local_type; *value = local_value; *tb = local_tb; #if CYTHON_COMPILING_IN_CPYTHON tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; tstate->exc_type = local_type; tstate->exc_value = local_value; tstate->exc_traceback = local_tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_SetExcInfo(local_type, local_value, local_tb); #endif return 0; bad: *type = 0; *value = 0; *tb = 0; Py_XDECREF(local_type); Py_XDECREF(local_value); Py_XDECREF(local_tb); return -1; } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else PyErr_Restore(type, value, tb); #endif } static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; #else PyErr_Fetch(type, value, tb); #endif } static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, int full_traceback) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); if (full_traceback) { Py_XINCREF(old_exc); Py_XINCREF(old_val); Py_XINCREF(old_tb); __Pyx_ErrRestore(old_exc, old_val, old_tb); PyErr_PrintEx(1); } #if PY_MAJOR_VERSION < 3 ctx = PyString_FromString(name); #else ctx = PyUnicode_FromString(name); #endif __Pyx_ErrRestore(old_exc, old_val, old_tb); if (!ctx) { PyErr_WriteUnraisable(Py_None); } else { PyErr_WriteUnraisable(ctx); Py_DECREF(ctx); } } static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { Py_XINCREF(type); if (!value || value == Py_None) value = NULL; else Py_INCREF(value); if (!tb || tb == Py_None) tb = NULL; else { Py_INCREF(tb); if (!PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } } if (PyType_Check(type)) { #if CYTHON_COMPILING_IN_PYPY if (!value) { Py_INCREF(Py_None); value = Py_None; } #endif PyErr_NormalizeException(&type, &value, &tb); } else { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } value = type; type = (PyObject*) Py_TYPE(type); Py_INCREF(type); if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto raise_error; } } __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { PyObject* owned_instance = NULL; if (tb == Py_None) { tb = 0; } else if (tb && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto bad; } if (value == Py_None) value = 0; if (PyExceptionInstance_Check(type)) { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto bad; } value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { PyObject *instance_class = NULL; if (value && PyExceptionInstance_Check(value)) { instance_class = (PyObject*) Py_TYPE(value); if (instance_class != type) { if (PyObject_IsSubclass(instance_class, type)) { type = instance_class; } else { instance_class = NULL; } } } if (!instance_class) { PyObject *args; if (!value) args = PyTuple_New(0); else if (PyTuple_Check(value)) { Py_INCREF(value); args = value; } else args = PyTuple_Pack(1, value); if (!args) goto bad; owned_instance = PyObject_Call(type, args, NULL); Py_DECREF(args); if (!owned_instance) goto bad; value = owned_instance; if (!PyExceptionInstance_Check(value)) { PyErr_Format(PyExc_TypeError, "calling %R should have returned an instance of " "BaseException, not %R", type, Py_TYPE(value)); goto bad; } } } else { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto bad; } #if PY_VERSION_HEX >= 0x03030000 if (cause) { #else if (cause && cause != Py_None) { #endif PyObject *fixed_cause; if (cause == Py_None) { fixed_cause = NULL; } else if (PyExceptionClass_Check(cause)) { fixed_cause = PyObject_CallObject(cause, NULL); if (fixed_cause == NULL) goto bad; } else if (PyExceptionInstance_Check(cause)) { fixed_cause = cause; Py_INCREF(fixed_cause); } else { PyErr_SetString(PyExc_TypeError, "exception causes must derive from " "BaseException"); goto bad; } PyException_SetCause(value, fixed_cause); } PyErr_SetObject(type, value); if (tb) { #if CYTHON_COMPILING_IN_PYPY PyObject *tmp_type, *tmp_value, *tmp_tb; PyErr_Fetch(tmp_type, tmp_value, tmp_tb); Py_INCREF(tb); PyErr_Restore(tmp_type, tmp_value, tb); Py_XDECREF(tmp_tb); #else PyThreadState *tstate = PyThreadState_GET(); PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } #endif } bad: Py_XDECREF(owned_instance); return; } #endif static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { PyObject *result; #if CYTHON_COMPILING_IN_CPYTHON result = PyDict_GetItem(__pyx_d, name); if (likely(result)) { Py_INCREF(result); } else { #else result = PyObject_GetItem(__pyx_d, name); if (!result) { PyErr_Clear(); #endif result = __Pyx_GetBuiltinName(name); } return result; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (is_list || PyList_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; } } else if (PyTuple_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (likely(l >= 0)) { i += l; } else { if (PyErr_ExceptionMatches(PyExc_OverflowError)) PyErr_Clear(); else return NULL; } } return m->sq_item(o, i); } } #else if (is_list || PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { PyObject *self, *result; PyCFunction cfunc; cfunc = PyCFunction_GET_FUNCTION(func); self = PyCFunction_GET_SELF(func); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = cfunc(self, arg); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_New(1); if (unlikely(!args)) return NULL; Py_INCREF(arg); PyTuple_SET_ITEM(args, 0, arg); result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { #else if (likely(PyCFunction_Check(func))) { #endif if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { return __Pyx_PyObject_CallMethO(func, arg); } } return __Pyx__PyObject_CallOneArg(func, arg); } #else static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject* args = PyTuple_Pack(1, arg); return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL; } #endif static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { PyObject *method, *result = NULL; method = __Pyx_PyObject_GetAttrStr(obj, method_name); if (unlikely(!method)) goto bad; #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyMethod_Check(method))) { PyObject *self = PyMethod_GET_SELF(method); if (likely(self)) { PyObject *args; PyObject *function = PyMethod_GET_FUNCTION(method); args = PyTuple_New(2); if (unlikely(!args)) goto bad; Py_INCREF(self); PyTuple_SET_ITEM(args, 0, self); Py_INCREF(arg); PyTuple_SET_ITEM(args, 1, arg); Py_INCREF(function); Py_DECREF(method); method = NULL; result = __Pyx_PyObject_Call(function, args, NULL); Py_DECREF(args); Py_DECREF(function); return result; } } #endif result = __Pyx_PyObject_CallOneArg(method, arg); bad: Py_XDECREF(method); return result; } static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { if (likely(PyList_CheckExact(L))) { if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; } else { PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x); if (unlikely(!retval)) return -1; Py_DECREF(retval); } return 0; } #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { #else if (likely(PyCFunction_Check(func))) { #endif if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } } return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); } #endif static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = (start + end) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; py_code = __pyx_find_code_object(c_line ? c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? c_line : py_line, py_code); } py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = py_line; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; #if PY_VERSION_HEX < 0x03030000 PyObject *py_import; py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if (strchr(__Pyx_MODULE_NAME, '.')) { #if PY_VERSION_HEX < 0x03030000 PyObject *py_level = PyInt_FromLong(1); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); #endif if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; } #endif if (!module) { #if PY_VERSION_HEX < 0x03030000 PyObject *py_level = PyInt_FromLong(level); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, level); #endif } } bad: #if PY_VERSION_HEX < 0x03030000 Py_XDECREF(py_import); #endif Py_XDECREF(empty_list); Py_XDECREF(empty_dict); return module; } #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value) \ { \ func_type value = func_value; \ if (sizeof(target_type) < sizeof(func_type)) { \ if (unlikely(value != (func_type) (target_type) value)) { \ func_type zero = 0; \ if (is_unsigned && unlikely(value < zero)) \ goto raise_neg_overflow; \ else \ goto raise_overflow; \ } \ } \ return (target_type) value; \ } #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #endif #endif static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS switch (Py_SIZE(x)) { case 0: return 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, ((PyLongObject*)x)->ob_digit[0]); } #endif #endif if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong(x)) } else if (sizeof(int) <= sizeof(unsigned long long)) { __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong(x)) } } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS switch (Py_SIZE(x)) { case 0: return 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, +(((PyLongObject*)x)->ob_digit[0])); case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]); } #endif #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong(x)) } else if (sizeof(int) <= sizeof(long long)) { __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong(x)) } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_Int(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(int) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); } else if (sizeof(int) <= sizeof(unsigned long long)) { return PyLong_FromUnsignedLongLong((unsigned long long) value); } } else { if (sizeof(int) <= sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(int) <= sizeof(long long)) { return PyLong_FromLongLong((long long) value); } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(int), little, !is_unsigned); } } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); } else if (sizeof(long) <= sizeof(unsigned long long)) { return PyLong_FromUnsignedLongLong((unsigned long long) value); } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(long long)) { return PyLong_FromLongLong((long long) value); } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { const unsigned int neg_one = (unsigned int) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned int) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { return PyLong_FromUnsignedLongLong((unsigned long long) value); } } else { if (sizeof(unsigned int) <= sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned int) <= sizeof(long long)) { return PyLong_FromLongLong((long long) value); } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(unsigned int), little, !is_unsigned); } } static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS switch (Py_SIZE(x)) { case 0: return 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, ((PyLongObject*)x)->ob_digit[0]); } #endif #endif if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong(x)) } else if (sizeof(long) <= sizeof(unsigned long long)) { __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong(x)) } } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS switch (Py_SIZE(x)) { case 0: return 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, +(((PyLongObject*)x)->ob_digit[0])); case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]); } #endif #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong(x)) } else if (sizeof(long) <= sizeof(long long)) { __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong(x)) } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_Int(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { char message[200]; PyOS_snprintf(message, sizeof(message), "compiletime version %s of module '%.100s' " "does not match runtime version %s", ctversion, __Pyx_MODULE_NAME, rtversion); return PyErr_WarnEx(NULL, message, 1); } return 0; } static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { #if PY_VERSION_HEX < 0x03030000 char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; #else if (__Pyx_PyUnicode_READY(o) == -1) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (PyUnicode_IS_ASCII(o)) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif #endif } else #endif #if !CYTHON_COMPILING_IN_PYPY if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_MAJOR_VERSION < 3 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) return PyInt_AS_LONG(b); #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS switch (Py_SIZE(b)) { case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0]; case 0: return 0; case 1: return ((PyLongObject*)b)->ob_digit[0]; } #endif #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ pypcap-1.1.5/pcap.pyx000066400000000000000000000336231270636626600145240ustar00rootroot00000000000000# # pcap.pyx # # $Id$ """packet capture library This module provides a high level interface to packet capture systems. All packets on the network, even those destined for other hosts, are accessible through this mechanism. """ __author__ = 'Dug Song ' __copyright__ = 'Copyright (c) 2004 Dug Song' __license__ = 'BSD license' __url__ = 'http://monkey.org/~dugsong/pypcap/' __version__ = '1.1' import sys import struct cdef extern from "Python.h": object PyBuffer_FromMemory(char *s, int len) int PyObject_AsCharBuffer(object obj, char **buffer, int *buffer_len) int PyGILState_Ensure() void PyGILState_Release(int gil) void Py_BEGIN_ALLOW_THREADS() void Py_END_ALLOW_THREADS() cdef extern from "pcap.h": struct bpf_insn: int __xxx struct bpf_program: bpf_insn *bf_insns struct bpf_timeval: unsigned int tv_sec unsigned int tv_usec struct pcap_stat: unsigned int ps_recv unsigned int ps_drop unsigned int ps_ifdrop struct pcap_pkthdr: bpf_timeval ts unsigned int caplen ctypedef struct pcap_t: int __xxx ctypedef struct pcap_if_t # hack for win32 ctypedef struct pcap_if_t: pcap_if_t *next char *name ctypedef void (*pcap_handler)(void *arg, pcap_pkthdr *hdr, char *pkt) cdef extern from "pcap.h": pcap_t *pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *errbuf) pcap_t *pcap_open_offline(char *fname, char *errbuf) int pcap_compile(pcap_t *p, bpf_program *fp, char *str, int optimize, unsigned int netmask) int pcap_setfilter(pcap_t *p, bpf_program *fp) void pcap_freecode(bpf_program *fp) int pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, unsigned char *arg) unsigned char *pcap_next(pcap_t *p, pcap_pkthdr *hdr) int pcap_datalink(pcap_t *p) int pcap_snapshot(pcap_t *p) int pcap_stats(pcap_t *p, pcap_stat *ps) char *pcap_geterr(pcap_t *p) void pcap_close(pcap_t *p) int bpf_filter(bpf_insn *insns, char *buf, int len, int caplen) int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) void pcap_freealldevs(pcap_if_t *alldevs) int pcap_lookupnet(char *device, unsigned int *netp, unsigned int *maskp, char *errbuf) int pcap_sendpacket(pcap_t *p, char *buf, int size) cdef extern from "pcap_ex.h": # XXX - hrr, sync with libdnet and libevent int pcap_ex_immediate(pcap_t *p) char *pcap_ex_name(char *name) char *pcap_ex_lookupdev(char *ebuf) int pcap_ex_fileno(pcap_t *p) void pcap_ex_setup(pcap_t *p) void pcap_ex_setnonblock(pcap_t *p, int nonblock, char *ebuf) int pcap_ex_getnonblock(pcap_t *p, char *ebuf) int pcap_ex_setdirection(pcap_t *p, int direction) int pcap_ex_next(pcap_t *p, pcap_pkthdr **hdr, char **pkt) int pcap_ex_compile_nopcap(int snaplen, int dlt, bpf_program *fp, char *str, int optimize, unsigned int netmask) cdef extern from *: char *strdup(char *src) void free(void *ptr) cdef struct pcap_handler_ctx: void *callback void *args int got_exc cdef void __pcap_handler(void *arg, pcap_pkthdr *hdr, char *pkt): cdef pcap_handler_ctx *ctx cdef int gil ctx = arg gil = PyGILState_Ensure() try: (ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0), PyBuffer_FromMemory(pkt, hdr.caplen), *(ctx.args)) except: ctx.got_exc = 1 PyGILState_Release(gil) DLT_NULL = 0 DLT_EN10MB = 1 DLT_EN3MB = 2 DLT_AX25 = 3 DLT_PRONET = 4 DLT_CHAOS = 5 DLT_IEEE802 = 6 DLT_ARCNET = 7 DLT_SLIP = 8 DLT_PPP = 9 DLT_FDDI = 10 # XXX - Linux DLT_LINUX_SLL = 113 # XXX - OpenBSD DLT_PFLOG = 117 DLT_PFSYNC = 18 if sys.platform.find('openbsd') != -1: DLT_LOOP = 12 DLT_RAW = 14 else: DLT_LOOP = 108 DLT_RAW = 12 PCAP_D_INOUT = 0 PCAP_D_IN = 1 PCAP_D_OUT = 2 dltoff = { DLT_NULL:4, DLT_EN10MB:14, DLT_IEEE802:22, DLT_ARCNET:6, DLT_SLIP:16, DLT_PPP:4, DLT_FDDI:21, DLT_PFLOG:48, DLT_PFSYNC:4, DLT_LOOP:4, DLT_RAW:0, DLT_LINUX_SLL:16 } cdef class bpf: """bpf(filter, dlt=DLT_RAW) -> BPF filter object""" cdef bpf_program fcode def __init__(self, char *filter, dlt=DLT_RAW): if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0: raise IOError, 'bad filter' def filter(self, buf): """Return boolean match for buf against our filter.""" cdef char *p cdef int n if PyObject_AsCharBuffer(buf, &p, &n) < 0: raise TypeError if bpf_filter(self.fcode.bf_insns, p, n, n) == 0: return False return True def __dealloc__(self): pcap_freecode(&self.fcode) cdef class pcap: """pcap(name=None, snaplen=65535, promisc=True, timeout_ms=None, immediate=False) -> packet capture object Open a handle to a packet capture descriptor. Keyword arguments: name -- name of a network interface or dumpfile to open, or None to open the first available up interface snaplen -- maximum number of bytes to capture for each packet promisc -- boolean to specify promiscuous mode sniffing timeout_ms -- requests for the next packet will return None if the timeout (in milliseconds) is reached and no packets were received (Default: no timeout) immediate -- disable buffering, if possible """ cdef pcap_t *__pcap cdef char *__name cdef char *__filter cdef char __ebuf[256] cdef int __dloff def __init__(self, name=None, snaplen=65535, promisc=True, timeout_ms=0, immediate=False): global dltoff cdef char *p if not name: p = pcap_ex_lookupdev(self.__ebuf) if p == NULL: raise OSError, self.__ebuf else: p = name self.__pcap = pcap_open_offline(p, self.__ebuf) if not self.__pcap: self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, timeout_ms, self.__ebuf) if not self.__pcap: raise OSError, self.__ebuf self.__name = strdup(p) self.__filter = strdup("") try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] except KeyError: pass if immediate and pcap_ex_immediate(self.__pcap) < 0: raise OSError, "couldn't enable immediate mode" property name: """Network interface or dumpfile name.""" def __get__(self): return self.__name property snaplen: """Maximum number of bytes to capture for each packet.""" def __get__(self): return pcap_snapshot(self.__pcap) property dloff: """Datalink offset (length of layer-2 frame header).""" def __get__(self): return self.__dloff property filter: """Current packet capture filter.""" def __get__(self): return self.__filter property fd: """File descriptor (or Win32 HANDLE) for capture handle.""" def __get__(self): return pcap_ex_fileno(self.__pcap) def fileno(self): """Return file descriptor (or Win32 HANDLE) for capture handle.""" return pcap_ex_fileno(self.__pcap) def setfilter(self, value, optimize=1): """Set BPF-format packet capture filter.""" cdef bpf_program fcode free(self.__filter) self.__filter = strdup(value) if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0: raise OSError, pcap_geterr(self.__pcap) if pcap_setfilter(self.__pcap, &fcode) < 0: raise OSError, pcap_geterr(self.__pcap) pcap_freecode(&fcode) def setdirection(self, direction): """Set capture direction.""" ret = pcap_ex_setdirection(self.__pcap, direction) if ret == 0: return True return False def setnonblock(self, nonblock=True): """Set non-blocking capture mode.""" pcap_ex_setnonblock(self.__pcap, nonblock, self.__ebuf) def getnonblock(self): """Return non-blocking capture mode as boolean.""" ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf) if ret < 0: raise OSError, self.__ebuf elif ret: return True return False def datalink(self): """Return datalink type (DLT_* values).""" return pcap_datalink(self.__pcap) def __add_pkts(self, ts, pkt, pkts): pkts.append((ts, pkt)) def readpkts(self): """Return a list of (timestamp, packet) tuples received in one buffer.""" pkts = [] self.dispatch(-1, self.__add_pkts, pkts) return pkts def dispatch(self, cnt, callback, *args): """Collect and process packets with a user callback, return the number of packets processed, or 0 for a savefile. Arguments: cnt -- number of packets to process; or 0 to process all packets until an error occurs, EOF is reached, or the read times out; or -1 to process all packets received in one buffer callback -- function with (timestamp, pkt, *args) prototype *args -- optional arguments passed to callback on execution """ cdef pcap_handler_ctx ctx cdef int n ctx.callback = callback ctx.args = args ctx.got_exc = 0 n = pcap_dispatch(self.__pcap, cnt, __pcap_handler, &ctx) if ctx.got_exc: exc = sys.exc_info() raise exc[0], exc[1], exc[2] return n def loop(self, cnt, callback, *args): """Processing packets with a user callback during a loop. The loop can be exited when cnt value is reached or with an exception, including KeyboardInterrupt. Arguments: cnt -- number of packets to process; 0 or -1 to process all packets until an error occurs, EOF is reached; callback -- function with (timestamp, pkt, *args) prototype *args -- optional arguments passed to callback on execution """ cdef pcap_pkthdr *hdr cdef char *pkt cdef int n cdef int i i = 1 pcap_ex_setup(self.__pcap) while 1: Py_BEGIN_ALLOW_THREADS n = pcap_ex_next(self.__pcap, &hdr, &pkt) Py_END_ALLOW_THREADS if n == 1: callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), PyBuffer_FromMemory(pkt, hdr.caplen), *args) elif n == 0: break elif n == -1: raise KeyboardInterrupt elif n == -2: break if i == cnt: break i = i + 1 def sendpacket(self, buf): """Send a raw network packet on the interface.""" ret = pcap_sendpacket(self.__pcap, buf, len(buf)) if ret == -1: raise OSError, pcap_geterr(self.__pcap) return len(buf) def geterr(self): """Return the last error message associated with this handle.""" return pcap_geterr(self.__pcap) def stats(self): """Return a 3-tuple of the total number of packets received, dropped, and dropped by the interface.""" cdef pcap_stat pstat if pcap_stats(self.__pcap, &pstat) < 0: raise OSError, pcap_geterr(self.__pcap) return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop) def __iter__(self): pcap_ex_setup(self.__pcap) return self def __next__(self): cdef pcap_pkthdr *hdr cdef char *pkt cdef int n while 1: Py_BEGIN_ALLOW_THREADS n = pcap_ex_next(self.__pcap, &hdr, &pkt) Py_END_ALLOW_THREADS if n == 1: return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), PyBuffer_FromMemory(pkt, hdr.caplen)) elif n == 0: return None elif n == -1: raise KeyboardInterrupt elif n == -2: raise StopIteration def __dealloc__(self): if self.__name: free(self.__name) if self.__filter: free(self.__filter) if self.__pcap: pcap_close(self.__pcap) def ex_name(char *foo): return pcap_ex_name(foo) def lookupdev(): """Return the name of a network device suitable for sniffing.""" cdef char *p cdef char ebuf[256] p = pcap_ex_lookupdev(ebuf) if p == NULL: raise OSError, ebuf return p def findalldevs(): """Return a list of capture devices.""" cdef pcap_if_t *devs cdef pcap_if_t *curr cdef char ebuf[256] status = pcap_findalldevs(&devs, ebuf) if status: raise OSError(ebuf) retval = [] if not devs: return retval curr = devs while 1: retval.append(curr.name) if not curr.next: break curr = curr.next pcap_freealldevs(devs) return retval def lookupnet(char *dev): """ Return the address and the netmask of a given device as network-byteorder integers. """ cdef unsigned int netp cdef unsigned int maskp cdef char ebuf[256] status = pcap_lookupnet(dev, &netp, &maskp, ebuf) if status: raise OSError(ebuf) return struct.pack('I', netp), struct.pack('I', maskp) pypcap-1.1.5/pcap_ex.c000066400000000000000000000150471270636626600146220ustar00rootroot00000000000000/* $Id$ */ #ifdef _WIN32 # include # include #else # include # include # include # include # include # include # include #endif #include #ifdef HAVE_PCAP_INT_H #include #endif #include "pcap_ex.h" /* XXX - hack around older Python versions */ #include "patchlevel.h" #if PY_VERSION_HEX < 0x02030000 int PyGILState_Ensure() { return (0); } void PyGILState_Release(int gil) { } #endif int pcap_ex_immediate(pcap_t *pcap) { #ifdef _WIN32 return pcap_setmintocopy(pcap, 1); #elif defined BIOCIMMEDIATE int n = 1; return ioctl(pcap_fileno(pcap), BIOCIMMEDIATE, &n); #elif defined __APPLE__ /* XXX On OSX Yosemite (10.10.3) BIOCIMMEDIATE is not defined) */ int n = 1; return ioctl(pcap_fileno(pcap), _IOW('B',112, u_int), &n); #else return 0; #endif } #ifdef _WIN32 /* XXX - set device list in libdnet order. */ static int _pcap_ex_findalldevs(pcap_if_t **dst, char *ebuf) { pcap_if_t *pifs, *cur, *prev, *next; int ret; if ((ret = pcap_findalldevs(&pifs, ebuf)) != -1) { /* XXX - flip script like a dyslexic actor */ for (prev = NULL, cur = pifs; cur != NULL; ) { next = cur->next, cur->next = prev; prev = cur, cur = next; } *dst = prev; } return (ret); } #endif char * pcap_ex_name(char *name) { #ifdef _WIN32 /* * XXX - translate from libdnet logical interface name to * WinPcap native interface name. */ static char pcap_name[256]; pcap_if_t *pifs, *pif; char ebuf[128]; int idx, i = 0; /* XXX - according to the WinPcap FAQ, no loopback support??? */ if (strncmp(name, "eth", 3) != 0 || sscanf(name+3, "%u", &idx) != 1 || _pcap_ex_findalldevs(&pifs, ebuf) == -1) { return (name); } for (pif = pifs; pif != NULL; pif = pif->next) { if (i++ == idx) { strncpy(pcap_name, pif->name, sizeof(pcap_name)-1); pcap_name[sizeof(pcap_name)-1] = '\0'; name = pcap_name; break; } } pcap_freealldevs(pifs); return (name); #else return (name); #endif } char * pcap_ex_lookupdev(char *ebuf) { #ifdef _WIN32 /* XXX - holy poo this sux */ static char _ifname[8]; MIB_IPADDRTABLE *ipaddrs; DWORD i, dsz, outip; pcap_if_t *pifs, *pif; struct pcap_addr *pa; char *name = NULL; int idx; /* Find our primary IP address. */ ipaddrs = malloc((dsz = sizeof(*ipaddrs))); while (GetIpAddrTable(ipaddrs, &dsz, 0) == ERROR_INSUFFICIENT_BUFFER) { free(ipaddrs); ipaddrs = malloc(dsz); } outip = 0; for (i = 0; i < ipaddrs->dwNumEntries; i++) { if (ipaddrs->table[i].dwAddr != 0 && ipaddrs->table[i].dwAddr != 0x100007f #if 0 /* XXX -no wType/MIB_IPADDR_PRIMARY in w32api/iprtrmib.h */ && ipaddrs->table[i].unused2 & 0x01 #endif ) { outip = ipaddrs->table[i].dwAddr; break; } } free(ipaddrs); if (outip == 0) { /* XXX - default to first Ethernet interface. */ return ("eth0"); } /* Find matching pcap interface by IP. */ if (_pcap_ex_findalldevs(&pifs, ebuf) == -1) return (name); for (pif = pifs, idx = 0; pif != NULL && name == NULL; pif = pif->next, idx++) { for (pa = pif->addresses; pa != NULL; pa = pa->next) { if (pa->addr->sa_family == AF_INET && ((struct sockaddr_in *)pa->addr)->sin_addr.S_un.S_addr == outip) { sprintf(_ifname, "eth%d", idx); name = _ifname; break; } } } pcap_freealldevs(pifs); return (name); #else return (pcap_lookupdev(ebuf)); #endif } int pcap_ex_fileno(pcap_t *pcap) { #ifdef _WIN32 /* XXX - how to handle savefiles? */ return ((int)pcap_getevent(pcap)); #else # ifdef HAVE_PCAP_FILE FILE *f = pcap_file(pcap); # else FILE *f = pcap->sf.rfile; # endif if (f != NULL) return (fileno(f)); return (pcap_fileno(pcap)); #endif /* !_WIN32 */ } static int __pcap_ex_gotsig; #ifdef _WIN32 static BOOL CALLBACK __pcap_ex_ctrl(DWORD sig) { __pcap_ex_gotsig = 1; return (TRUE); } #else static void __pcap_ex_signal(int sig) { __pcap_ex_gotsig = 1; } #endif /* XXX - hrr, this sux */ void pcap_ex_setup(pcap_t *pcap) { #ifdef _WIN32 SetConsoleCtrlHandler(__pcap_ex_ctrl, TRUE); #else #if 0 int fd, n; fd = pcap_fileno(pcap); n = fcntl(fd, F_GETFL, 0) | O_NONBLOCK; fcntl(fd, F_SETFL, n); #endif signal(SIGINT, __pcap_ex_signal); #endif } int pcap_ex_setdirection(pcap_t *pcap, int direction) { #ifdef HAVE_PCAP_SETDIRECTION return (pcap_setdirection(pcap, (pcap_direction_t) direction)); #else return (-2); #endif } void pcap_ex_setnonblock(pcap_t *pcap, int nonblock, char *ebuf) { #ifdef HAVE_PCAP_SETNONBLOCK pcap_setnonblock(pcap, nonblock, ebuf); #endif } int pcap_ex_getnonblock(pcap_t *pcap, char *ebuf) { #ifdef HAVE_PCAP_SETNONBLOCK return (pcap_getnonblock(pcap, ebuf)); #else return (0); #endif } /* return codes: 1 = pkt, 0 = timeout, -1 = error, -2 = EOF */ int pcap_ex_next(pcap_t *pcap, struct pcap_pkthdr **hdr, u_char **pkt) { #ifdef _WIN32 if (__pcap_ex_gotsig) { __pcap_ex_gotsig = 0; return (-1); } return (pcap_next_ex(pcap, hdr, pkt)); #else static u_char *__pkt; static struct pcap_pkthdr __hdr; struct timeval tv = { 1, 0 }; fd_set rfds; int fd, n; fd = pcap_fileno(pcap); for (;;) { if (__pcap_ex_gotsig) { __pcap_ex_gotsig = 0; return (-1); } if ((__pkt = (u_char *)pcap_next(pcap, &__hdr)) == NULL) { #ifdef HAVE_PCAP_FILE if (pcap_file(pcap) != NULL) #else if (pcap->sf.rfile != NULL) #endif return (-2); FD_ZERO(&rfds); FD_SET(fd, &rfds); n = select(fd + 1, &rfds, NULL, NULL, &tv); if (n <= 0) return (n); } else break; } *pkt = __pkt; *hdr = &__hdr; return (1); #endif } int pcap_ex_compile_nopcap(int snaplen, int dlt, struct bpf_program *fp, char *str, int optimize, unsigned int netmask) { #ifdef HAVE_PCAP_COMPILE_NOPCAP #ifdef __NetBSD__ /* We love consistent interfaces */ char errbuf[PCAP_ERRBUF_SIZE]; return (pcap_compile_nopcap(snaplen, dlt, fp, str, optimize, netmask, errbuf)); #else return (pcap_compile_nopcap(snaplen, dlt, fp, str, optimize, netmask)); #endif #else FILE *f; struct pcap_file_header hdr; pcap_t *pc; char path[] = "/tmp/.pypcapXXXXXX.pcap"; char ebuf[PCAP_ERRBUF_SIZE]; int ret = -1; mktemp(path); if ((f = fopen(path, "w")) != NULL) { hdr.magic = 0xa1b2c3d4; hdr.version_major = PCAP_VERSION_MAJOR; hdr.version_minor = PCAP_VERSION_MINOR; hdr.thiszone = 0; hdr.snaplen = snaplen; hdr.sigfigs = 0; hdr.linktype = dlt; fwrite(&hdr, sizeof(hdr), 1, f); fclose(f); if ((pc = pcap_open_offline(path, ebuf)) != NULL) { ret = pcap_compile(pc, fp, str, optimize, netmask); pcap_close(pc); } unlink(path); } return (ret); #endif } pypcap-1.1.5/pcap_ex.h000066400000000000000000000011741270636626600146230ustar00rootroot00000000000000/* $Id$ */ #ifndef PCAP_EX_H #define PCAP_EX_H int pcap_ex_immediate(pcap_t *pcap); char *pcap_ex_name(char *name); char *pcap_ex_lookupdev(char *ebuf); int pcap_ex_fileno(pcap_t *pcap); void pcap_ex_setup(pcap_t *pcap); void pcap_ex_setnonblock(pcap_t *pcap, int nonblock, char *ebuf); int pcap_ex_getnonblock(pcap_t *pcap, char *ebuf); int pcap_ex_next(pcap_t *pcap, struct pcap_pkthdr **hdr, u_char **pkt); int pcap_ex_setdirection(pcap_t *pcap, int direction); int pcap_ex_compile_nopcap(int snaplen, int dlt, struct bpf_program *fp, char *str, int optimize, unsigned int netmask); #endif /* PCAP_EX_H */ pypcap-1.1.5/setup.py000066400000000000000000000064751270636626600145560ustar00rootroot00000000000000"""Setup for pycapy""" from setuptools import setup, Extension import glob import os import sys import re def recursive_search_dirs(dirs, target_files): """Recursive search directories""" for d in dirs: r = recursive_search(d, target_files) if r: return r def recursive_search(path, target_files): """Recursively search for files""" for root, _dirs, files in os.walk(path): for filename in files: if filename in target_files: return os.path.join(root, filename) # A list of all the possible search directories dirs = ['/usr', sys.prefix] + glob.glob('/opt/libpcap*') + \ glob.glob('../libpcap*') + glob.glob('../wpdpack*') + \ glob.glob('/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/*') for d in dirs: # This makes sure that we first search inside of */include/pcap search_dirs = [os.path.join(d, 'usr', 'include', 'pcap'), os.path.join(d, 'include', 'pcap'), os.path.join(d, 'local', 'include', 'pcap'), d] pcap_h = recursive_search_dirs(search_dirs, ['pcap.h']) if pcap_h: print "Found pcap headers in %s" % pcap_h break if not pcap_h: print "pcap.h not found" sys.exit(1) include_dirs = [os.path.dirname(pcap_h)] # FIXME: This is super weird 'd' here is what? the last d in dir list? lib_sub_dirs = [os.path.join(d, sub_dir) \ for sub_dir in ('lib', 'lib64', \ 'lib/x86_64-linux-gnu', 'lib/i386-linux-gnu', '')] lib_files = [ 'libpcap.a', 'libpcap.so', 'libpcap.dylib', 'wpcap.lib' ] lib_file_path = recursive_search_dirs(lib_sub_dirs, lib_files) print "Found libraries in %s" % lib_file_path lib_file = os.path.basename(lib_file_path) extra_compile_args = [] if re.match(r"libpcap\.(a|so|dylib)", lib_file): libraries = ('pcap',) elif lib_file == "wpcap.lib": libraries = ('wpcap', 'iphlpapi') extra_compile_args = ['-DWIN32', '-DWPCAP'] define_macros = [] pcap_int_path = recursive_search_dirs(dirs, ['pcap-int.h']) if pcap_int_path: pcap_int_dir = os.path.dirname(pcap_int_path) if pcap_int_dir not in include_dirs: include_dirs.append(pcap_int_dir) define_macros.append(('HAVE_PCAP_INT_H', 1)) else: print "No pcap-int.h found" pcap_h_file = open(pcap_h).readlines() for line in pcap_h_file: if 'pcap_file(' in line: print "found pcap_file function" define_macros.append(('HAVE_PCAP_FILE', 1)) if 'pcap_compile_nopcap(' in line: print "found pcap_compile_nopcap function" define_macros.append(('HAVE_PCAP_COMPILE_NOPCAP', 1)) if 'pcap_setnonblock(' in line: print "found pcap_setnonblock" define_macros.append(('HAVE_PCAP_SETNONBLOCK', 1)) if 'pcap_setdirection(' in line: print "found pcap_setdirection" define_macros.append(('HAVE_PCAP_SETDIRECTION', 1)) pcap = Extension( name='pcap', sources=['pcap.c', 'pcap_ex.c'], include_dirs=include_dirs, define_macros=define_macros, libraries=list(libraries), extra_compile_args=extra_compile_args, ) setup( name='pypcap', version='1.1.5', author='Dug Song', author_email='dugsong@monkey.org', url='https://github.com/pynetwork/pypcap', description='packet capture library', ext_modules=[pcap], ) pypcap-1.1.5/test.pcap000066400000000000000000000007241270636626600146570ustar00rootroot00000000000000òaA[#>> `-aoE0&@<  }0pqaAp#66o `-aE(L@@  }1PbAl>> `-aoE0@:  }0pqbA66o `-aE(G~@@>  }1PbA1 >> `-aoE0K@9i  }0pqbAG 66o `-aE(>s@@I  }1Ppypcap-1.1.5/test.py000077500000000000000000000026271270636626600143730ustar00rootroot00000000000000#!/usr/bin/env python import glob, sys, unittest sys.path.insert(0, glob.glob('build/lib.*')[0]) import pcap class PcapTestCase(unittest.TestCase): def test_pcap_iter(self): l = [ (x[0], len(x[1])) for x in pcap.pcap('test.pcap') ] assert l == [(1092256609.9265549, 62), (1092256609.9265759, 54), (1092256610.332396, 62), (1092256610.3324161, 54), (1092256610.8330729, 62), (1092256610.8330951, 54)], 'pcap iter' def test_pcap_properties(self): p = pcap.pcap('test.pcap') assert (p.name, p.snaplen, p.dloff, p.filter) == ('test.pcap', 2000, 14, ''), 'pcap properties' def test_pcap_errors(self): p = pcap.pcap('test.pcap') try: print p.stats() except OSError: pass assert p.geterr() != '', 'pcap_geterr' def test_pcap_dispatch(self): def __cnt_handler(ts, pkt, d): d['cnt'] += 1 p = pcap.pcap('test.pcap') d = { 'cnt':0 } n = p.dispatch(-1, __cnt_handler, d) assert n == 0 assert d['cnt'] == 6 def __bad_handler(ts, pkt): raise NotImplementedError p = pcap.pcap('test.pcap') try: p.dispatch(-1, __bad_handler) except NotImplementedError: pass def test_pcap_readpkts(self): assert len(pcap.pcap('test.pcap').readpkts()) == 6 if __name__ == '__main__': unittest.main() pypcap-1.1.5/testsniff.py000077500000000000000000000016221270636626600154130ustar00rootroot00000000000000#!/usr/bin/env python import getopt, sys import dpkt, pcap def usage(): print >>sys.stderr, 'usage: %s [-i device] [pattern]' % sys.argv[0] sys.exit(1) def main(): opts, args = getopt.getopt(sys.argv[1:], 'i:h') name = None for o, a in opts: if o == '-i': name = a else: usage() pc = pcap.pcap(name) pc.setfilter(' '.join(args)) decode = { pcap.DLT_LOOP:dpkt.loopback.Loopback, pcap.DLT_NULL:dpkt.loopback.Loopback, pcap.DLT_EN10MB:dpkt.ethernet.Ethernet }[pc.datalink()] try: print 'listening on %s: %s' % (pc.name, pc.filter) for ts, pkt in pc: print ts, `decode(pkt)` except KeyboardInterrupt: nrecv, ndrop, nifdrop = pc.stats() print '\n%d packets received by filter' % nrecv print '%d packets dropped by kernel' % ndrop if __name__ == '__main__': main()