1 /* Generated by Pyrex 0.9.3 on Sun Oct 16 19:38:39 2005 */
2
3 #include "Python.h"
4 #include "structmember.h"
5 #ifndef PY_LONG_LONG
6 #define PY_LONG_LONG LONG_LONG
7 #endif
8 #include "pcap.h"
9 #include "pcap_ex.h"
10
11
12 typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
13 typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
14 static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
15 static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
16 static int __Pyx_PrintItem(PyObject *); /*proto*/
17 static int __Pyx_PrintNewline(void); /*proto*/
18 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
19 static void __Pyx_ReRaise(void); /*proto*/
20 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
21 static PyObject *__Pyx_GetExcValue(void); /*proto*/
22 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
23 static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
24 static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
25 static void __Pyx_WriteUnraisable(char *name); /*proto*/
26 static void __Pyx_AddTraceback(char *funcname); /*proto*/
27 static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/
28 static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
29 static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
30 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
31 static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
32 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
33 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
34
35 static PyObject *__pyx_m;
36 static PyObject *__pyx_b;
37 static int __pyx_lineno;
38 static char *__pyx_filename;
39 staticforward char **__pyx_f;
40
41 static char __pyx_mdoc[] = "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";
42
43 /* Declarations from pcap */
44
45 struct __pyx_t_4pcap_pcap_handler_ctx {
46 void (*callback);
47 void (*args);
48 int got_exc;
49 };
50
51 staticforward PyTypeObject __pyx_type_4pcap_bpf;
52
53 struct __pyx_obj_4pcap_bpf {
54 PyObject_HEAD
55 struct bpf_program fcode;
56 };
57
58 staticforward PyTypeObject __pyx_type_4pcap_pcap;
59
60 struct __pyx_obj_4pcap_pcap {
61 PyObject_HEAD
62 pcap_t (*__pcap);
63 char (*__name);
64 char (*__filter);
65 char (__ebuf[256]);
66 int __dloff;
67 };
68
69 static PyTypeObject *__pyx_ptype_4pcap_bpf = 0;
70 static PyTypeObject *__pyx_ptype_4pcap_pcap = 0;
71 static PyObject *__pyx_k13;
72 static PyObject *__pyx_k14;
73 static PyObject *__pyx_k15;
74 static PyObject *__pyx_k16;
75 static PyObject *__pyx_k17;
76 static PyObject *__pyx_k18;
77 static PyObject *__pyx_k19;
78 static PyObject *__pyx_k20;
79 static void (__pyx_f_4pcap___pcap_handler(void (*),struct pcap_pkthdr (*),char (*))); /*proto*/
80
81 /* Implementation of pcap */
82
83 static char (__pyx_k1[]) = "Network interface or dumpfile name.";
84 static char (__pyx_k2[]) = "Maximum number of bytes to capture for each packet.";
85 static char (__pyx_k3[]) = "Datalink offset (length of layer-2 frame header).";
86 static char (__pyx_k4[]) = "Current packet capture filter.";
87 static char (__pyx_k5[]) = "File descriptor (or Win32 HANDLE) for capture handle.";
88 static char (__pyx_k6[]) = "Dug Song <dugsong@monkey.org>";
89 static char (__pyx_k7[]) = "Copyright (c) 2004 Dug Song";
90 static char (__pyx_k8[]) = "BSD license";
91 static char (__pyx_k9[]) = "http://monkey.org/~dugsong/pypcap/";
92 static char (__pyx_k10[]) = "1.1";
93
94 static PyObject *__pyx_n___author__;
95 static PyObject *__pyx_n___copyright__;
96 static PyObject *__pyx_n___license__;
97 static PyObject *__pyx_n___url__;
98 static PyObject *__pyx_n___version__;
99 static PyObject *__pyx_n_sys;
100 static PyObject *__pyx_n_DLT_NULL;
101 static PyObject *__pyx_n_DLT_EN10MB;
102 static PyObject *__pyx_n_DLT_EN3MB;
103 static PyObject *__pyx_n_DLT_AX25;
104 static PyObject *__pyx_n_DLT_PRONET;
105 static PyObject *__pyx_n_DLT_CHAOS;
106 static PyObject *__pyx_n_DLT_IEEE802;
107 static PyObject *__pyx_n_DLT_ARCNET;
108 static PyObject *__pyx_n_DLT_SLIP;
109 static PyObject *__pyx_n_DLT_PPP;
110 static PyObject *__pyx_n_DLT_FDDI;
111 static PyObject *__pyx_n_DLT_LINUX_SLL;
112 static PyObject *__pyx_n_DLT_PFLOG;
113 static PyObject *__pyx_n_DLT_PFSYNC;
114 static PyObject *__pyx_n_DLT_LOOP;
115 static PyObject *__pyx_n_DLT_RAW;
116 static PyObject *__pyx_n_dltoff;
117 static PyObject *__pyx_n_ex_name;
118 static PyObject *__pyx_n_lookupdev;
119 static PyObject *__pyx_n_platform;
120 static PyObject *__pyx_n_find;
121 static PyObject *__pyx_n_openbsd;
122 static PyObject *__pyx_n_True;
123 static PyObject *__pyx_n_False;
124
125 static PyObject *__pyx_k6p;
126 static PyObject *__pyx_k7p;
127 static PyObject *__pyx_k8p;
128 static PyObject *__pyx_k9p;
129 static PyObject *__pyx_k10p;
130
__pyx_f_4pcap___pcap_handler(void (* __pyx_v_arg),struct pcap_pkthdr (* __pyx_v_hdr),char (* __pyx_v_pkt))131 static void __pyx_f_4pcap___pcap_handler(void (*__pyx_v_arg),struct pcap_pkthdr (*__pyx_v_hdr),char (*__pyx_v_pkt)) {
132 struct __pyx_t_4pcap_pcap_handler_ctx (*__pyx_v_ctx);
133 int __pyx_v_gil;
134 PyObject *__pyx_1 = 0;
135 PyObject *__pyx_2 = 0;
136 PyObject *__pyx_3 = 0;
137 PyObject *__pyx_4 = 0;
138
139 /* "/Users/dugsong/projects/pypcap/pcap.pyx":92 */
140 __pyx_v_ctx = ((struct __pyx_t_4pcap_pcap_handler_ctx (*))__pyx_v_arg);
141
142 /* "/Users/dugsong/projects/pypcap/pcap.pyx":93 */
143 __pyx_v_gil = PyGILState_Ensure();
144
145 /* "/Users/dugsong/projects/pypcap/pcap.pyx":94 */
146 /*try:*/ {
147
148 /* "/Users/dugsong/projects/pypcap/pcap.pyx":95 */
149 __pyx_1 = (PyObject *)__pyx_v_ctx->callback;
150 Py_INCREF(__pyx_1);
151 __pyx_2 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L2;}
152 __pyx_3 = PyBuffer_FromMemory(__pyx_v_pkt,__pyx_v_hdr->caplen); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; goto __pyx_L2;}
153 __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L2;}
154 PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
155 PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
156 __pyx_2 = 0;
157 __pyx_3 = 0;
158 __pyx_2 = (PyObject *)__pyx_v_ctx->args;
159 Py_INCREF(__pyx_2);
160 __pyx_3 = PySequence_Tuple(__pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L2;}
161 Py_DECREF(__pyx_2); __pyx_2 = 0;
162 __pyx_2 = PyNumber_Add(__pyx_4, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L2;}
163 Py_DECREF(__pyx_4); __pyx_4 = 0;
164 Py_DECREF(__pyx_3); __pyx_3 = 0;
165 __pyx_4 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L2;}
166 Py_DECREF(__pyx_1); __pyx_1 = 0;
167 Py_DECREF(__pyx_2); __pyx_2 = 0;
168 Py_DECREF(__pyx_4); __pyx_4 = 0;
169 }
170 goto __pyx_L3;
171 __pyx_L2:;
172 Py_XDECREF(__pyx_3); __pyx_3 = 0;
173 Py_XDECREF(__pyx_1); __pyx_1 = 0;
174 Py_XDECREF(__pyx_2); __pyx_2 = 0;
175 Py_XDECREF(__pyx_4); __pyx_4 = 0;
176
177 /* "/Users/dugsong/projects/pypcap/pcap.pyx":98 */
178 /*except:*/ {
179 __Pyx_AddTraceback("pcap.__pcap_handler");
180 __pyx_3 = __Pyx_GetExcValue(); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; goto __pyx_L1;}
181 Py_DECREF(__pyx_3); __pyx_3 = 0;
182
183 /* "/Users/dugsong/projects/pypcap/pcap.pyx":99 */
184 __pyx_v_ctx->got_exc = 1;
185 goto __pyx_L3;
186 }
187 __pyx_L3:;
188
189 /* "/Users/dugsong/projects/pypcap/pcap.pyx":100 */
190 PyGILState_Release(__pyx_v_gil);
191
192 goto __pyx_L0;
193 __pyx_L1:;
194 Py_XDECREF(__pyx_1);
195 Py_XDECREF(__pyx_2);
196 Py_XDECREF(__pyx_3);
197 Py_XDECREF(__pyx_4);
198 __Pyx_WriteUnraisable("pcap.__pcap_handler");
199 __pyx_L0:;
200 }
201
202 static PyObject *__pyx_n_IOError;
203
204 static PyObject *__pyx_k21p;
205
206 static char (__pyx_k21[]) = "bad filter";
207
208 static int __pyx_f_4pcap_3bpf___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
__pyx_f_4pcap_3bpf___init__(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)209 static int __pyx_f_4pcap_3bpf___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
210 char (*__pyx_v_filter);
211 PyObject *__pyx_v_dlt = 0;
212 int __pyx_r;
213 int __pyx_1;
214 int __pyx_2;
215 PyObject *__pyx_3 = 0;
216 static char *__pyx_argnames[] = {"filter","dlt",0};
217 __pyx_v_dlt = __pyx_k13;
218 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "s|O", __pyx_argnames, &__pyx_v_filter, &__pyx_v_dlt)) return -1;
219 Py_INCREF(__pyx_v_self);
220 Py_INCREF(__pyx_v_dlt);
221
222 /* "/Users/dugsong/projects/pypcap/pcap.pyx":133 */
223 __pyx_1 = PyInt_AsLong(__pyx_v_dlt); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; goto __pyx_L1;}
224 __pyx_2 = (pcap_ex_compile_nopcap(65535,__pyx_1,(&((struct __pyx_obj_4pcap_bpf *)__pyx_v_self)->fcode),__pyx_v_filter,1,0) < 0);
225 if (__pyx_2) {
226
227 /* "/Users/dugsong/projects/pypcap/pcap.pyx":134 */
228 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_IOError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; goto __pyx_L1;}
229 __Pyx_Raise(__pyx_3, __pyx_k21p, 0);
230 Py_DECREF(__pyx_3); __pyx_3 = 0;
231 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; goto __pyx_L1;}
232 goto __pyx_L2;
233 }
234 __pyx_L2:;
235
236 __pyx_r = 0;
237 goto __pyx_L0;
238 __pyx_L1:;
239 Py_XDECREF(__pyx_3);
240 __Pyx_AddTraceback("pcap.bpf.__init__");
241 __pyx_r = -1;
242 __pyx_L0:;
243 Py_DECREF(__pyx_v_self);
244 Py_DECREF(__pyx_v_dlt);
245 return __pyx_r;
246 }
247
248 static PyObject *__pyx_n_len;
249
250 static PyObject *__pyx_f_4pcap_3bpf_filter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
251 static char __pyx_doc_4pcap_3bpf_filter[] = "Return boolean match for buf against our filter.";
__pyx_f_4pcap_3bpf_filter(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)252 static PyObject *__pyx_f_4pcap_3bpf_filter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
253 PyObject *__pyx_v_buf = 0;
254 int __pyx_v_n;
255 PyObject *__pyx_r;
256 PyObject *__pyx_1 = 0;
257 PyObject *__pyx_2 = 0;
258 PyObject *__pyx_3 = 0;
259 int __pyx_4;
260 char (*__pyx_5);
261 static char *__pyx_argnames[] = {"buf",0};
262 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_buf)) return 0;
263 Py_INCREF(__pyx_v_self);
264 Py_INCREF(__pyx_v_buf);
265
266 /* "/Users/dugsong/projects/pypcap/pcap.pyx":138 */
267 __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; goto __pyx_L1;}
268 __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; goto __pyx_L1;}
269 Py_INCREF(__pyx_v_buf);
270 PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_buf);
271 __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; goto __pyx_L1;}
272 Py_DECREF(__pyx_1); __pyx_1 = 0;
273 Py_DECREF(__pyx_2); __pyx_2 = 0;
274 __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; goto __pyx_L1;}
275 Py_DECREF(__pyx_3); __pyx_3 = 0;
276 __pyx_v_n = __pyx_4;
277
278 /* "/Users/dugsong/projects/pypcap/pcap.pyx":139 */
279 __pyx_5 = PyString_AsString(__pyx_v_buf); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; goto __pyx_L1;}
280 __pyx_4 = (bpf_filter(((struct __pyx_obj_4pcap_bpf *)__pyx_v_self)->fcode.bf_insns,__pyx_5,__pyx_v_n,__pyx_v_n) == 0);
281 if (__pyx_4) {
282
283 /* "/Users/dugsong/projects/pypcap/pcap.pyx":140 */
284 __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; goto __pyx_L1;}
285 __pyx_r = __pyx_1;
286 __pyx_1 = 0;
287 goto __pyx_L0;
288 goto __pyx_L2;
289 }
290 __pyx_L2:;
291
292 /* "/Users/dugsong/projects/pypcap/pcap.pyx":141 */
293 __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; goto __pyx_L1;}
294 __pyx_r = __pyx_2;
295 __pyx_2 = 0;
296 goto __pyx_L0;
297
298 __pyx_r = Py_None; Py_INCREF(__pyx_r);
299 goto __pyx_L0;
300 __pyx_L1:;
301 Py_XDECREF(__pyx_1);
302 Py_XDECREF(__pyx_2);
303 Py_XDECREF(__pyx_3);
304 __Pyx_AddTraceback("pcap.bpf.filter");
305 __pyx_r = 0;
306 __pyx_L0:;
307 Py_DECREF(__pyx_v_self);
308 Py_DECREF(__pyx_v_buf);
309 return __pyx_r;
310 }
311
312 static void __pyx_f_4pcap_3bpf___dealloc__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_3bpf___dealloc__(PyObject * __pyx_v_self)313 static void __pyx_f_4pcap_3bpf___dealloc__(PyObject *__pyx_v_self) {
314 Py_INCREF(__pyx_v_self);
315
316 /* "/Users/dugsong/projects/pypcap/pcap.pyx":143 */
317 pcap_freecode((&((struct __pyx_obj_4pcap_bpf *)__pyx_v_self)->fcode));
318
319 goto __pyx_L0;
320 __pyx_L1:;
321 __Pyx_AddTraceback("pcap.bpf.__dealloc__");
322 __pyx_L0:;
323 Py_DECREF(__pyx_v_self);
324 }
325
326 static PyObject *__pyx_n_OSError;
327 static PyObject *__pyx_n_KeyError;
328
329 static PyObject *__pyx_k23p;
330
331 static char (__pyx_k22[]) = "";
332 static char (__pyx_k23[]) = "couldn't set BPF immediate mode";
333
334 static int __pyx_f_4pcap_4pcap___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
__pyx_f_4pcap_4pcap___init__(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)335 static int __pyx_f_4pcap_4pcap___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
336 PyObject *__pyx_v_name = 0;
337 PyObject *__pyx_v_snaplen = 0;
338 PyObject *__pyx_v_promisc = 0;
339 PyObject *__pyx_v_timeout_ms = 0;
340 PyObject *__pyx_v_immediate = 0;
341 char (*__pyx_v_p);
342 int __pyx_r;
343 int __pyx_1;
344 int __pyx_2;
345 PyObject *__pyx_3 = 0;
346 PyObject *__pyx_4 = 0;
347 char (*__pyx_5);
348 int __pyx_6;
349 PyObject *__pyx_7 = 0;
350 static char *__pyx_argnames[] = {"name","snaplen","promisc","timeout_ms","immediate",0};
351 __pyx_v_name = __pyx_k14;
352 __pyx_v_snaplen = __pyx_k15;
353 __pyx_v_promisc = __pyx_k16;
354 __pyx_v_timeout_ms = __pyx_k17;
355 __pyx_v_immediate = __pyx_k18;
356 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|OOOOO", __pyx_argnames, &__pyx_v_name, &__pyx_v_snaplen, &__pyx_v_promisc, &__pyx_v_timeout_ms, &__pyx_v_immediate)) return -1;
357 Py_INCREF(__pyx_v_self);
358 Py_INCREF(__pyx_v_name);
359 Py_INCREF(__pyx_v_snaplen);
360 Py_INCREF(__pyx_v_promisc);
361 Py_INCREF(__pyx_v_timeout_ms);
362 Py_INCREF(__pyx_v_immediate);
363
364 /* "/Users/dugsong/projects/pypcap/pcap.pyx":168 */
365 __pyx_1 = PyObject_IsTrue(__pyx_v_name); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; goto __pyx_L1;}
366 __pyx_2 = (!__pyx_1);
367 if (__pyx_2) {
368
369 /* "/Users/dugsong/projects/pypcap/pcap.pyx":169 */
370 __pyx_v_p = pcap_ex_lookupdev(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf);
371
372 /* "/Users/dugsong/projects/pypcap/pcap.pyx":170 */
373 __pyx_1 = (__pyx_v_p == 0);
374 if (__pyx_1) {
375
376 /* "/Users/dugsong/projects/pypcap/pcap.pyx":171 */
377 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; goto __pyx_L1;}
378 __pyx_4 = PyString_FromString(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; goto __pyx_L1;}
379 __Pyx_Raise(__pyx_3, __pyx_4, 0);
380 Py_DECREF(__pyx_3); __pyx_3 = 0;
381 Py_DECREF(__pyx_4); __pyx_4 = 0;
382 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; goto __pyx_L1;}
383 goto __pyx_L3;
384 }
385 __pyx_L3:;
386 goto __pyx_L2;
387 }
388 /*else*/ {
389
390 /* "/Users/dugsong/projects/pypcap/pcap.pyx":173 */
391 __pyx_5 = PyString_AsString(__pyx_v_name); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; goto __pyx_L1;}
392 __pyx_v_p = __pyx_5;
393 }
394 __pyx_L2:;
395
396 /* "/Users/dugsong/projects/pypcap/pcap.pyx":175 */
397 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap = pcap_open_offline(__pyx_v_p,((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf);
398
399 /* "/Users/dugsong/projects/pypcap/pcap.pyx":176 */
400 __pyx_2 = (!(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap != 0));
401 if (__pyx_2) {
402
403 /* "/Users/dugsong/projects/pypcap/pcap.pyx":177 */
404 __pyx_1 = PyInt_AsLong(__pyx_v_snaplen); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; goto __pyx_L1;}
405 __pyx_2 = PyInt_AsLong(__pyx_v_promisc); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; goto __pyx_L1;}
406 __pyx_6 = PyInt_AsLong(__pyx_v_timeout_ms); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}
407 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap = pcap_open_live(pcap_ex_name(__pyx_v_p),__pyx_1,__pyx_2,__pyx_6,((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf);
408 goto __pyx_L4;
409 }
410 __pyx_L4:;
411
412 /* "/Users/dugsong/projects/pypcap/pcap.pyx":179 */
413 __pyx_1 = (!(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap != 0));
414 if (__pyx_1) {
415
416 /* "/Users/dugsong/projects/pypcap/pcap.pyx":180 */
417 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;}
418 __pyx_4 = PyString_FromString(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;}
419 __Pyx_Raise(__pyx_3, __pyx_4, 0);
420 Py_DECREF(__pyx_3); __pyx_3 = 0;
421 Py_DECREF(__pyx_4); __pyx_4 = 0;
422 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;}
423 goto __pyx_L5;
424 }
425 __pyx_L5:;
426
427 /* "/Users/dugsong/projects/pypcap/pcap.pyx":182 */
428 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__name = strdup(__pyx_v_p);
429
430 /* "/Users/dugsong/projects/pypcap/pcap.pyx":183 */
431 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter = strdup(__pyx_k22);
432
433 /* "/Users/dugsong/projects/pypcap/pcap.pyx":184 */
434 /*try:*/ {
435 __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n_dltoff); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L6;}
436 __pyx_4 = PyInt_FromLong(pcap_datalink(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L6;}
437 __pyx_7 = PyObject_GetItem(__pyx_3, __pyx_4); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L6;}
438 Py_DECREF(__pyx_3); __pyx_3 = 0;
439 Py_DECREF(__pyx_4); __pyx_4 = 0;
440 __pyx_2 = PyInt_AsLong(__pyx_7); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L6;}
441 Py_DECREF(__pyx_7); __pyx_7 = 0;
442 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__dloff = __pyx_2;
443 }
444 goto __pyx_L7;
445 __pyx_L6:;
446 Py_XDECREF(__pyx_3); __pyx_3 = 0;
447 Py_XDECREF(__pyx_4); __pyx_4 = 0;
448 Py_XDECREF(__pyx_7); __pyx_7 = 0;
449
450 /* "/Users/dugsong/projects/pypcap/pcap.pyx":185 */
451 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_KeyError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
452 __pyx_6 = PyErr_ExceptionMatches(__pyx_3);
453 Py_DECREF(__pyx_3); __pyx_3 = 0;
454 if (__pyx_6) {
455 __Pyx_AddTraceback("pcap.__init__");
456 __pyx_4 = __Pyx_GetExcValue(); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; goto __pyx_L1;}
457 Py_DECREF(__pyx_4); __pyx_4 = 0;
458 goto __pyx_L7;
459 }
460 goto __pyx_L1;
461 __pyx_L7:;
462
463 /* "/Users/dugsong/projects/pypcap/pcap.pyx":186 */
464 __pyx_7 = __pyx_v_immediate;
465 Py_INCREF(__pyx_7);
466 __pyx_1 = PyObject_IsTrue(__pyx_7); if (__pyx_1 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
467 if (__pyx_1) {
468 Py_DECREF(__pyx_7); __pyx_7 = 0;
469 __pyx_7 = PyInt_FromLong((pcap_ex_immediate(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap) < 0)); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
470 }
471 __pyx_2 = PyObject_IsTrue(__pyx_7); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
472 Py_DECREF(__pyx_7); __pyx_7 = 0;
473 if (__pyx_2) {
474
475 /* "/Users/dugsong/projects/pypcap/pcap.pyx":187 */
476 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
477 __Pyx_Raise(__pyx_3, __pyx_k23p, 0);
478 Py_DECREF(__pyx_3); __pyx_3 = 0;
479 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
480 goto __pyx_L8;
481 }
482 __pyx_L8:;
483
484 __pyx_r = 0;
485 goto __pyx_L0;
486 __pyx_L1:;
487 Py_XDECREF(__pyx_3);
488 Py_XDECREF(__pyx_4);
489 Py_XDECREF(__pyx_7);
490 __Pyx_AddTraceback("pcap.pcap.__init__");
491 __pyx_r = -1;
492 __pyx_L0:;
493 Py_DECREF(__pyx_v_self);
494 Py_DECREF(__pyx_v_name);
495 Py_DECREF(__pyx_v_snaplen);
496 Py_DECREF(__pyx_v_promisc);
497 Py_DECREF(__pyx_v_timeout_ms);
498 Py_DECREF(__pyx_v_immediate);
499 return __pyx_r;
500 }
501
502 static PyObject *__pyx_f_4pcap_4pcap_4name___get__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap_4name___get__(PyObject * __pyx_v_self)503 static PyObject *__pyx_f_4pcap_4pcap_4name___get__(PyObject *__pyx_v_self) {
504 PyObject *__pyx_r;
505 PyObject *__pyx_1 = 0;
506 Py_INCREF(__pyx_v_self);
507
508 /* "/Users/dugsong/projects/pypcap/pcap.pyx":192 */
509 __pyx_1 = PyString_FromString(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__name); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; goto __pyx_L1;}
510 __pyx_r = __pyx_1;
511 __pyx_1 = 0;
512 goto __pyx_L0;
513
514 __pyx_r = Py_None; Py_INCREF(__pyx_r);
515 goto __pyx_L0;
516 __pyx_L1:;
517 Py_XDECREF(__pyx_1);
518 __Pyx_AddTraceback("pcap.pcap.name.__get__");
519 __pyx_r = 0;
520 __pyx_L0:;
521 Py_DECREF(__pyx_v_self);
522 return __pyx_r;
523 }
524
525 static PyObject *__pyx_f_4pcap_4pcap_7snaplen___get__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap_7snaplen___get__(PyObject * __pyx_v_self)526 static PyObject *__pyx_f_4pcap_4pcap_7snaplen___get__(PyObject *__pyx_v_self) {
527 PyObject *__pyx_r;
528 PyObject *__pyx_1 = 0;
529 Py_INCREF(__pyx_v_self);
530
531 /* "/Users/dugsong/projects/pypcap/pcap.pyx":197 */
532 __pyx_1 = PyInt_FromLong(pcap_snapshot(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; goto __pyx_L1;}
533 __pyx_r = __pyx_1;
534 __pyx_1 = 0;
535 goto __pyx_L0;
536
537 __pyx_r = Py_None; Py_INCREF(__pyx_r);
538 goto __pyx_L0;
539 __pyx_L1:;
540 Py_XDECREF(__pyx_1);
541 __Pyx_AddTraceback("pcap.pcap.snaplen.__get__");
542 __pyx_r = 0;
543 __pyx_L0:;
544 Py_DECREF(__pyx_v_self);
545 return __pyx_r;
546 }
547
548 static PyObject *__pyx_f_4pcap_4pcap_5dloff___get__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap_5dloff___get__(PyObject * __pyx_v_self)549 static PyObject *__pyx_f_4pcap_4pcap_5dloff___get__(PyObject *__pyx_v_self) {
550 PyObject *__pyx_r;
551 PyObject *__pyx_1 = 0;
552 Py_INCREF(__pyx_v_self);
553
554 /* "/Users/dugsong/projects/pypcap/pcap.pyx":202 */
555 __pyx_1 = PyInt_FromLong(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__dloff); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; goto __pyx_L1;}
556 __pyx_r = __pyx_1;
557 __pyx_1 = 0;
558 goto __pyx_L0;
559
560 __pyx_r = Py_None; Py_INCREF(__pyx_r);
561 goto __pyx_L0;
562 __pyx_L1:;
563 Py_XDECREF(__pyx_1);
564 __Pyx_AddTraceback("pcap.pcap.dloff.__get__");
565 __pyx_r = 0;
566 __pyx_L0:;
567 Py_DECREF(__pyx_v_self);
568 return __pyx_r;
569 }
570
571 static PyObject *__pyx_f_4pcap_4pcap_6filter___get__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap_6filter___get__(PyObject * __pyx_v_self)572 static PyObject *__pyx_f_4pcap_4pcap_6filter___get__(PyObject *__pyx_v_self) {
573 PyObject *__pyx_r;
574 PyObject *__pyx_1 = 0;
575 Py_INCREF(__pyx_v_self);
576
577 /* "/Users/dugsong/projects/pypcap/pcap.pyx":207 */
578 __pyx_1 = PyString_FromString(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; goto __pyx_L1;}
579 __pyx_r = __pyx_1;
580 __pyx_1 = 0;
581 goto __pyx_L0;
582
583 __pyx_r = Py_None; Py_INCREF(__pyx_r);
584 goto __pyx_L0;
585 __pyx_L1:;
586 Py_XDECREF(__pyx_1);
587 __Pyx_AddTraceback("pcap.pcap.filter.__get__");
588 __pyx_r = 0;
589 __pyx_L0:;
590 Py_DECREF(__pyx_v_self);
591 return __pyx_r;
592 }
593
594 static PyObject *__pyx_f_4pcap_4pcap_2fd___get__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap_2fd___get__(PyObject * __pyx_v_self)595 static PyObject *__pyx_f_4pcap_4pcap_2fd___get__(PyObject *__pyx_v_self) {
596 PyObject *__pyx_r;
597 PyObject *__pyx_1 = 0;
598 Py_INCREF(__pyx_v_self);
599
600 /* "/Users/dugsong/projects/pypcap/pcap.pyx":212 */
601 __pyx_1 = PyInt_FromLong(pcap_ex_fileno(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
602 __pyx_r = __pyx_1;
603 __pyx_1 = 0;
604 goto __pyx_L0;
605
606 __pyx_r = Py_None; Py_INCREF(__pyx_r);
607 goto __pyx_L0;
608 __pyx_L1:;
609 Py_XDECREF(__pyx_1);
610 __Pyx_AddTraceback("pcap.pcap.fd.__get__");
611 __pyx_r = 0;
612 __pyx_L0:;
613 Py_DECREF(__pyx_v_self);
614 return __pyx_r;
615 }
616
617 static PyObject *__pyx_f_4pcap_4pcap_fileno(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
618 static char __pyx_doc_4pcap_4pcap_fileno[] = "Return file descriptor (or Win32 HANDLE) for capture handle.";
__pyx_f_4pcap_4pcap_fileno(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)619 static PyObject *__pyx_f_4pcap_4pcap_fileno(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
620 PyObject *__pyx_r;
621 PyObject *__pyx_1 = 0;
622 static char *__pyx_argnames[] = {0};
623 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
624 Py_INCREF(__pyx_v_self);
625
626 /* "/Users/dugsong/projects/pypcap/pcap.pyx":216 */
627 __pyx_1 = PyInt_FromLong(pcap_ex_fileno(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
628 __pyx_r = __pyx_1;
629 __pyx_1 = 0;
630 goto __pyx_L0;
631
632 __pyx_r = Py_None; Py_INCREF(__pyx_r);
633 goto __pyx_L0;
634 __pyx_L1:;
635 Py_XDECREF(__pyx_1);
636 __Pyx_AddTraceback("pcap.pcap.fileno");
637 __pyx_r = 0;
638 __pyx_L0:;
639 Py_DECREF(__pyx_v_self);
640 return __pyx_r;
641 }
642
643 static PyObject *__pyx_f_4pcap_4pcap_setfilter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
644 static char __pyx_doc_4pcap_4pcap_setfilter[] = "Set BPF-format packet capture filter.";
__pyx_f_4pcap_4pcap_setfilter(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)645 static PyObject *__pyx_f_4pcap_4pcap_setfilter(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
646 PyObject *__pyx_v_value = 0;
647 PyObject *__pyx_v_optimize = 0;
648 struct bpf_program __pyx_v_fcode;
649 PyObject *__pyx_r;
650 char (*__pyx_1);
651 int __pyx_2;
652 int __pyx_3;
653 PyObject *__pyx_4 = 0;
654 PyObject *__pyx_5 = 0;
655 static char *__pyx_argnames[] = {"value","optimize",0};
656 __pyx_v_optimize = __pyx_k19;
657 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_value, &__pyx_v_optimize)) return 0;
658 Py_INCREF(__pyx_v_self);
659 Py_INCREF(__pyx_v_value);
660 Py_INCREF(__pyx_v_optimize);
661
662 /* "/Users/dugsong/projects/pypcap/pcap.pyx":221 */
663 free(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter);
664
665 /* "/Users/dugsong/projects/pypcap/pcap.pyx":222 */
666 __pyx_1 = PyString_AsString(__pyx_v_value); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
667 ((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter = strdup(__pyx_1);
668
669 /* "/Users/dugsong/projects/pypcap/pcap.pyx":223 */
670 __pyx_2 = PyInt_AsLong(__pyx_v_optimize); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; goto __pyx_L1;}
671 __pyx_3 = (pcap_compile(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_fcode),((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter,__pyx_2,0) < 0);
672 if (__pyx_3) {
673
674 /* "/Users/dugsong/projects/pypcap/pcap.pyx":224 */
675 __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
676 __pyx_5 = PyString_FromString(pcap_geterr(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
677 __Pyx_Raise(__pyx_4, __pyx_5, 0);
678 Py_DECREF(__pyx_4); __pyx_4 = 0;
679 Py_DECREF(__pyx_5); __pyx_5 = 0;
680 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
681 goto __pyx_L2;
682 }
683 __pyx_L2:;
684
685 /* "/Users/dugsong/projects/pypcap/pcap.pyx":225 */
686 __pyx_2 = (pcap_setfilter(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_fcode)) < 0);
687 if (__pyx_2) {
688
689 /* "/Users/dugsong/projects/pypcap/pcap.pyx":226 */
690 __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
691 __pyx_5 = PyString_FromString(pcap_geterr(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
692 __Pyx_Raise(__pyx_4, __pyx_5, 0);
693 Py_DECREF(__pyx_4); __pyx_4 = 0;
694 Py_DECREF(__pyx_5); __pyx_5 = 0;
695 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
696 goto __pyx_L3;
697 }
698 __pyx_L3:;
699
700 /* "/Users/dugsong/projects/pypcap/pcap.pyx":227 */
701 pcap_freecode((&__pyx_v_fcode));
702
703 __pyx_r = Py_None; Py_INCREF(__pyx_r);
704 goto __pyx_L0;
705 __pyx_L1:;
706 Py_XDECREF(__pyx_4);
707 Py_XDECREF(__pyx_5);
708 __Pyx_AddTraceback("pcap.pcap.setfilter");
709 __pyx_r = 0;
710 __pyx_L0:;
711 Py_DECREF(__pyx_v_self);
712 Py_DECREF(__pyx_v_value);
713 Py_DECREF(__pyx_v_optimize);
714 return __pyx_r;
715 }
716
717 static PyObject *__pyx_f_4pcap_4pcap_setnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
718 static char __pyx_doc_4pcap_4pcap_setnonblock[] = "Set non-blocking capture mode.";
__pyx_f_4pcap_4pcap_setnonblock(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)719 static PyObject *__pyx_f_4pcap_4pcap_setnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
720 PyObject *__pyx_v_nonblock = 0;
721 PyObject *__pyx_r;
722 int __pyx_1;
723 static char *__pyx_argnames[] = {"nonblock",0};
724 __pyx_v_nonblock = __pyx_k20;
725 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|O", __pyx_argnames, &__pyx_v_nonblock)) return 0;
726 Py_INCREF(__pyx_v_self);
727 Py_INCREF(__pyx_v_nonblock);
728
729 /* "/Users/dugsong/projects/pypcap/pcap.pyx":231 */
730 __pyx_1 = PyInt_AsLong(__pyx_v_nonblock); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; goto __pyx_L1;}
731 pcap_ex_setnonblock(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,__pyx_1,((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf);
732
733 __pyx_r = Py_None; Py_INCREF(__pyx_r);
734 goto __pyx_L0;
735 __pyx_L1:;
736 __Pyx_AddTraceback("pcap.pcap.setnonblock");
737 __pyx_r = 0;
738 __pyx_L0:;
739 Py_DECREF(__pyx_v_self);
740 Py_DECREF(__pyx_v_nonblock);
741 return __pyx_r;
742 }
743
744 static PyObject *__pyx_f_4pcap_4pcap_getnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
745 static char __pyx_doc_4pcap_4pcap_getnonblock[] = "Return non-blocking capture mode as boolean.";
__pyx_f_4pcap_4pcap_getnonblock(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)746 static PyObject *__pyx_f_4pcap_4pcap_getnonblock(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
747 PyObject *__pyx_v_ret;
748 PyObject *__pyx_r;
749 PyObject *__pyx_1 = 0;
750 int __pyx_2;
751 PyObject *__pyx_3 = 0;
752 static char *__pyx_argnames[] = {0};
753 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
754 Py_INCREF(__pyx_v_self);
755 __pyx_v_ret = Py_None; Py_INCREF(__pyx_v_ret);
756
757 /* "/Users/dugsong/projects/pypcap/pcap.pyx":235 */
758 __pyx_1 = PyInt_FromLong(pcap_ex_getnonblock(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; goto __pyx_L1;}
759 Py_DECREF(__pyx_v_ret);
760 __pyx_v_ret = __pyx_1;
761 __pyx_1 = 0;
762
763 /* "/Users/dugsong/projects/pypcap/pcap.pyx":236 */
764 __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; goto __pyx_L1;}
765 if (PyObject_Cmp(__pyx_v_ret, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; goto __pyx_L1;}
766 __pyx_2 = __pyx_2 < 0;
767 Py_DECREF(__pyx_1); __pyx_1 = 0;
768 if (__pyx_2) {
769
770 /* "/Users/dugsong/projects/pypcap/pcap.pyx":237 */
771 __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
772 __pyx_3 = PyString_FromString(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__ebuf); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
773 __Pyx_Raise(__pyx_1, __pyx_3, 0);
774 Py_DECREF(__pyx_1); __pyx_1 = 0;
775 Py_DECREF(__pyx_3); __pyx_3 = 0;
776 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
777 goto __pyx_L2;
778 }
779 __pyx_2 = PyObject_IsTrue(__pyx_v_ret); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; goto __pyx_L1;}
780 if (__pyx_2) {
781
782 /* "/Users/dugsong/projects/pypcap/pcap.pyx":239 */
783 __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; goto __pyx_L1;}
784 __pyx_r = __pyx_1;
785 __pyx_1 = 0;
786 goto __pyx_L0;
787 goto __pyx_L2;
788 }
789 __pyx_L2:;
790
791 /* "/Users/dugsong/projects/pypcap/pcap.pyx":240 */
792 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; goto __pyx_L1;}
793 __pyx_r = __pyx_3;
794 __pyx_3 = 0;
795 goto __pyx_L0;
796
797 __pyx_r = Py_None; Py_INCREF(__pyx_r);
798 goto __pyx_L0;
799 __pyx_L1:;
800 Py_XDECREF(__pyx_1);
801 Py_XDECREF(__pyx_3);
802 __Pyx_AddTraceback("pcap.pcap.getnonblock");
803 __pyx_r = 0;
804 __pyx_L0:;
805 Py_DECREF(__pyx_v_ret);
806 Py_DECREF(__pyx_v_self);
807 return __pyx_r;
808 }
809
810 static PyObject *__pyx_f_4pcap_4pcap_datalink(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
811 static char __pyx_doc_4pcap_4pcap_datalink[] = "Return datalink type (DLT_* values).";
__pyx_f_4pcap_4pcap_datalink(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)812 static PyObject *__pyx_f_4pcap_4pcap_datalink(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
813 PyObject *__pyx_r;
814 PyObject *__pyx_1 = 0;
815 static char *__pyx_argnames[] = {0};
816 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
817 Py_INCREF(__pyx_v_self);
818
819 /* "/Users/dugsong/projects/pypcap/pcap.pyx":244 */
820 __pyx_1 = PyInt_FromLong(pcap_datalink(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
821 __pyx_r = __pyx_1;
822 __pyx_1 = 0;
823 goto __pyx_L0;
824
825 __pyx_r = Py_None; Py_INCREF(__pyx_r);
826 goto __pyx_L0;
827 __pyx_L1:;
828 Py_XDECREF(__pyx_1);
829 __Pyx_AddTraceback("pcap.pcap.datalink");
830 __pyx_r = 0;
831 __pyx_L0:;
832 Py_DECREF(__pyx_v_self);
833 return __pyx_r;
834 }
835
836 static PyObject *__pyx_f_4pcap_4pcap_next(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
837 static char __pyx_doc_4pcap_4pcap_next[] = "Return the next (timestamp, packet) tuple, or None on error.";
__pyx_f_4pcap_4pcap_next(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)838 static PyObject *__pyx_f_4pcap_4pcap_next(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
839 struct pcap_pkthdr __pyx_v_hdr;
840 char (*__pyx_v_pkt);
841 PyObject *__pyx_r;
842 int __pyx_1;
843 PyObject *__pyx_2 = 0;
844 PyObject *__pyx_3 = 0;
845 PyObject *__pyx_4 = 0;
846 static char *__pyx_argnames[] = {0};
847 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
848 Py_INCREF(__pyx_v_self);
849
850 /* "/Users/dugsong/projects/pypcap/pcap.pyx":250 */
851 __pyx_v_pkt = ((char (*))pcap_next(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_hdr)));
852
853 /* "/Users/dugsong/projects/pypcap/pcap.pyx":251 */
854 __pyx_1 = (!(__pyx_v_pkt != 0));
855 if (__pyx_1) {
856
857 /* "/Users/dugsong/projects/pypcap/pcap.pyx":252 */
858 Py_INCREF(Py_None);
859 __pyx_r = Py_None;
860 goto __pyx_L0;
861 goto __pyx_L2;
862 }
863 __pyx_L2:;
864
865 /* "/Users/dugsong/projects/pypcap/pcap.pyx":253 */
866 __pyx_2 = PyFloat_FromDouble((__pyx_v_hdr.ts.tv_sec + (__pyx_v_hdr.ts.tv_usec / 1000000.0))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
867 __pyx_3 = PyBuffer_FromMemory(__pyx_v_pkt,__pyx_v_hdr.caplen); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; goto __pyx_L1;}
868 __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
869 PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
870 PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
871 __pyx_2 = 0;
872 __pyx_3 = 0;
873 __pyx_r = __pyx_4;
874 __pyx_4 = 0;
875 goto __pyx_L0;
876
877 __pyx_r = Py_None; Py_INCREF(__pyx_r);
878 goto __pyx_L0;
879 __pyx_L1:;
880 Py_XDECREF(__pyx_2);
881 Py_XDECREF(__pyx_3);
882 Py_XDECREF(__pyx_4);
883 __Pyx_AddTraceback("pcap.pcap.next");
884 __pyx_r = 0;
885 __pyx_L0:;
886 Py_DECREF(__pyx_v_self);
887 return __pyx_r;
888 }
889
890 static PyObject *__pyx_n_append;
891
892 static PyObject *__pyx_f_4pcap_4pcap___add_pkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
__pyx_f_4pcap_4pcap___add_pkts(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)893 static PyObject *__pyx_f_4pcap_4pcap___add_pkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
894 PyObject *__pyx_v_ts = 0;
895 PyObject *__pyx_v_pkt = 0;
896 PyObject *__pyx_v_pkts = 0;
897 PyObject *__pyx_r;
898 PyObject *__pyx_1 = 0;
899 PyObject *__pyx_2 = 0;
900 PyObject *__pyx_3 = 0;
901 static char *__pyx_argnames[] = {"ts","pkt","pkts",0};
902 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_ts, &__pyx_v_pkt, &__pyx_v_pkts)) return 0;
903 Py_INCREF(__pyx_v_self);
904 Py_INCREF(__pyx_v_ts);
905 Py_INCREF(__pyx_v_pkt);
906 Py_INCREF(__pyx_v_pkts);
907
908 /* "/Users/dugsong/projects/pypcap/pcap.pyx":257 */
909 __pyx_1 = PyObject_GetAttr(__pyx_v_pkts, __pyx_n_append); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
910 __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
911 Py_INCREF(__pyx_v_ts);
912 PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_ts);
913 Py_INCREF(__pyx_v_pkt);
914 PyTuple_SET_ITEM(__pyx_2, 1, __pyx_v_pkt);
915 __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
916 PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
917 __pyx_2 = 0;
918 __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
919 Py_DECREF(__pyx_1); __pyx_1 = 0;
920 Py_DECREF(__pyx_3); __pyx_3 = 0;
921 Py_DECREF(__pyx_2); __pyx_2 = 0;
922
923 __pyx_r = Py_None; Py_INCREF(__pyx_r);
924 goto __pyx_L0;
925 __pyx_L1:;
926 Py_XDECREF(__pyx_1);
927 Py_XDECREF(__pyx_2);
928 Py_XDECREF(__pyx_3);
929 __Pyx_AddTraceback("pcap.pcap.__add_pkts");
930 __pyx_r = 0;
931 __pyx_L0:;
932 Py_DECREF(__pyx_v_self);
933 Py_DECREF(__pyx_v_ts);
934 Py_DECREF(__pyx_v_pkt);
935 Py_DECREF(__pyx_v_pkts);
936 return __pyx_r;
937 }
938
939 static PyObject *__pyx_n_dispatch;
940 static PyObject *__pyx_n___add_pkts;
941
942 static PyObject *__pyx_f_4pcap_4pcap_readpkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
943 static char __pyx_doc_4pcap_4pcap_readpkts[] = "Return a list of (timestamp, packet) tuples received in one buffer.";
__pyx_f_4pcap_4pcap_readpkts(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)944 static PyObject *__pyx_f_4pcap_4pcap_readpkts(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
945 PyObject *__pyx_v_pkts;
946 PyObject *__pyx_r;
947 PyObject *__pyx_1 = 0;
948 PyObject *__pyx_2 = 0;
949 PyObject *__pyx_3 = 0;
950 PyObject *__pyx_4 = 0;
951 static char *__pyx_argnames[] = {0};
952 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
953 Py_INCREF(__pyx_v_self);
954 __pyx_v_pkts = Py_None; Py_INCREF(__pyx_v_pkts);
955
956 /* "/Users/dugsong/projects/pypcap/pcap.pyx":261 */
957 __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; goto __pyx_L1;}
958 Py_DECREF(__pyx_v_pkts);
959 __pyx_v_pkts = __pyx_1;
960 __pyx_1 = 0;
961
962 /* "/Users/dugsong/projects/pypcap/pcap.pyx":262 */
963 __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_dispatch); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; goto __pyx_L1;}
964 __pyx_2 = PyInt_FromLong((-1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; goto __pyx_L1;}
965 __pyx_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n___add_pkts); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; goto __pyx_L1;}
966 __pyx_4 = PyTuple_New(3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; goto __pyx_L1;}
967 PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
968 PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
969 Py_INCREF(__pyx_v_pkts);
970 PyTuple_SET_ITEM(__pyx_4, 2, __pyx_v_pkts);
971 __pyx_2 = 0;
972 __pyx_3 = 0;
973 __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; goto __pyx_L1;}
974 Py_DECREF(__pyx_1); __pyx_1 = 0;
975 Py_DECREF(__pyx_4); __pyx_4 = 0;
976 Py_DECREF(__pyx_2); __pyx_2 = 0;
977
978 /* "/Users/dugsong/projects/pypcap/pcap.pyx":263 */
979 Py_INCREF(__pyx_v_pkts);
980 __pyx_r = __pyx_v_pkts;
981 goto __pyx_L0;
982
983 __pyx_r = Py_None; Py_INCREF(__pyx_r);
984 goto __pyx_L0;
985 __pyx_L1:;
986 Py_XDECREF(__pyx_1);
987 Py_XDECREF(__pyx_2);
988 Py_XDECREF(__pyx_3);
989 Py_XDECREF(__pyx_4);
990 __Pyx_AddTraceback("pcap.pcap.readpkts");
991 __pyx_r = 0;
992 __pyx_L0:;
993 Py_DECREF(__pyx_v_pkts);
994 Py_DECREF(__pyx_v_self);
995 return __pyx_r;
996 }
997
998 static PyObject *__pyx_n_exc_info;
999
1000 static PyObject *__pyx_f_4pcap_4pcap_dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1001 static char __pyx_doc_4pcap_4pcap_dispatch[] = "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 ";
__pyx_f_4pcap_4pcap_dispatch(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1002 static PyObject *__pyx_f_4pcap_4pcap_dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1003 PyObject *__pyx_v_cnt = 0;
1004 PyObject *__pyx_v_callback = 0;
1005 PyObject *__pyx_v_args = 0;
1006 struct __pyx_t_4pcap_pcap_handler_ctx __pyx_v_ctx;
1007 int __pyx_v_n;
1008 PyObject *__pyx_v_exc;
1009 PyObject *__pyx_r;
1010 int __pyx_1;
1011 PyObject *__pyx_2 = 0;
1012 PyObject *__pyx_3 = 0;
1013 PyObject *__pyx_4 = 0;
1014 PyObject *__pyx_5 = 0;
1015 static char *__pyx_argnames[] = {"cnt","callback",0};
1016 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 2, &__pyx_v_args, 0) < 0) return 0;
1017 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_cnt, &__pyx_v_callback)) {
1018 Py_XDECREF(__pyx_args);
1019 Py_XDECREF(__pyx_kwds);
1020 Py_XDECREF(__pyx_v_args);
1021 return 0;
1022 }
1023 Py_INCREF(__pyx_v_self);
1024 Py_INCREF(__pyx_v_cnt);
1025 Py_INCREF(__pyx_v_callback);
1026 __pyx_v_exc = Py_None; Py_INCREF(__pyx_v_exc);
1027
1028 /* "/Users/dugsong/projects/pypcap/pcap.pyx":281 */
1029 __pyx_v_ctx.callback = ((void (*))__pyx_v_callback);
1030
1031 /* "/Users/dugsong/projects/pypcap/pcap.pyx":282 */
1032 __pyx_v_ctx.args = ((void (*))__pyx_v_args);
1033
1034 /* "/Users/dugsong/projects/pypcap/pcap.pyx":283 */
1035 __pyx_v_ctx.got_exc = 0;
1036
1037 /* "/Users/dugsong/projects/pypcap/pcap.pyx":284 */
1038 __pyx_1 = PyInt_AsLong(__pyx_v_cnt); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; goto __pyx_L1;}
1039 __pyx_v_n = pcap_dispatch(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,__pyx_1,__pyx_f_4pcap___pcap_handler,((unsigned char (*))(&__pyx_v_ctx)));
1040
1041 /* "/Users/dugsong/projects/pypcap/pcap.pyx":286 */
1042 __pyx_1 = __pyx_v_ctx.got_exc;
1043 if (__pyx_1) {
1044
1045 /* "/Users/dugsong/projects/pypcap/pcap.pyx":287 */
1046 __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_n_sys); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; goto __pyx_L1;}
1047 __pyx_3 = PyObject_GetAttr(__pyx_2, __pyx_n_exc_info); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; goto __pyx_L1;}
1048 Py_DECREF(__pyx_2); __pyx_2 = 0;
1049 __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; goto __pyx_L1;}
1050 __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; goto __pyx_L1;}
1051 Py_DECREF(__pyx_3); __pyx_3 = 0;
1052 Py_DECREF(__pyx_2); __pyx_2 = 0;
1053 Py_DECREF(__pyx_v_exc);
1054 __pyx_v_exc = __pyx_4;
1055 __pyx_4 = 0;
1056
1057 /* "/Users/dugsong/projects/pypcap/pcap.pyx":288 */
1058 __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1059 __pyx_2 = PyObject_GetItem(__pyx_v_exc, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1060 Py_DECREF(__pyx_3); __pyx_3 = 0;
1061 __pyx_4 = PyInt_FromLong(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1062 __pyx_3 = PyObject_GetItem(__pyx_v_exc, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1063 Py_DECREF(__pyx_4); __pyx_4 = 0;
1064 __pyx_4 = PyInt_FromLong(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1065 __pyx_5 = PyObject_GetItem(__pyx_v_exc, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1066 Py_DECREF(__pyx_4); __pyx_4 = 0;
1067 __Pyx_Raise(__pyx_2, __pyx_3, __pyx_5);
1068 Py_DECREF(__pyx_2); __pyx_2 = 0;
1069 Py_DECREF(__pyx_3); __pyx_3 = 0;
1070 Py_DECREF(__pyx_5); __pyx_5 = 0;
1071 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
1072 goto __pyx_L2;
1073 }
1074 __pyx_L2:;
1075
1076 /* "/Users/dugsong/projects/pypcap/pcap.pyx":289 */
1077 __pyx_4 = PyInt_FromLong(__pyx_v_n); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
1078 __pyx_r = __pyx_4;
1079 __pyx_4 = 0;
1080 goto __pyx_L0;
1081
1082 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1083 goto __pyx_L0;
1084 __pyx_L1:;
1085 Py_XDECREF(__pyx_2);
1086 Py_XDECREF(__pyx_3);
1087 Py_XDECREF(__pyx_4);
1088 Py_XDECREF(__pyx_5);
1089 __Pyx_AddTraceback("pcap.pcap.dispatch");
1090 __pyx_r = 0;
1091 __pyx_L0:;
1092 Py_XDECREF(__pyx_v_args);
1093 Py_DECREF(__pyx_v_exc);
1094 Py_DECREF(__pyx_v_self);
1095 Py_DECREF(__pyx_v_cnt);
1096 Py_DECREF(__pyx_v_callback);
1097 Py_XDECREF(__pyx_args);
1098 Py_XDECREF(__pyx_kwds);
1099 return __pyx_r;
1100 }
1101
1102 static PyObject *__pyx_n_KeyboardInterrupt;
1103
1104 static PyObject *__pyx_f_4pcap_4pcap_loop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1105 static char __pyx_doc_4pcap_4pcap_loop[] = "Loop forever, processing packets with a user callback.\n The loop can be exited with an exception, including KeyboardInterrupt.\n \n Arguments:\n\n callback -- function with (timestamp, pkt, *args) prototype\n *args -- optional arguments passed to callback on execution\n ";
__pyx_f_4pcap_4pcap_loop(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1106 static PyObject *__pyx_f_4pcap_4pcap_loop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1107 PyObject *__pyx_v_callback = 0;
1108 PyObject *__pyx_v_args = 0;
1109 struct pcap_pkthdr (*__pyx_v_hdr);
1110 char (*__pyx_v_pkt);
1111 int __pyx_v_n;
1112 PyObject *__pyx_r;
1113 long __pyx_1;
1114 int __pyx_2;
1115 PyObject *__pyx_3 = 0;
1116 PyObject *__pyx_4 = 0;
1117 PyObject *__pyx_5 = 0;
1118 static char *__pyx_argnames[] = {"callback",0};
1119 if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 1, &__pyx_v_args, 0) < 0) return 0;
1120 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_callback)) {
1121 Py_XDECREF(__pyx_args);
1122 Py_XDECREF(__pyx_kwds);
1123 Py_XDECREF(__pyx_v_args);
1124 return 0;
1125 }
1126 Py_INCREF(__pyx_v_self);
1127 Py_INCREF(__pyx_v_callback);
1128
1129 /* "/Users/dugsong/projects/pypcap/pcap.pyx":303 */
1130 pcap_ex_setup(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap);
1131
1132 /* "/Users/dugsong/projects/pypcap/pcap.pyx":304 */
1133 while (1) {
1134 __pyx_L2:;
1135 __pyx_1 = 1;
1136 if (!__pyx_1) break;
1137
1138 /* "/Users/dugsong/projects/pypcap/pcap.pyx":305 */
1139 Py_BEGIN_ALLOW_THREADS;
1140
1141 /* "/Users/dugsong/projects/pypcap/pcap.pyx":306 */
1142 __pyx_v_n = pcap_ex_next(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_hdr),(&__pyx_v_pkt));
1143
1144 /* "/Users/dugsong/projects/pypcap/pcap.pyx":307 */
1145 Py_END_ALLOW_THREADS;
1146
1147 /* "/Users/dugsong/projects/pypcap/pcap.pyx":308 */
1148 __pyx_2 = (__pyx_v_n == 1);
1149 if (__pyx_2) {
1150
1151 /* "/Users/dugsong/projects/pypcap/pcap.pyx":309 */
1152 __pyx_3 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
1153 __pyx_4 = PyBuffer_FromMemory(__pyx_v_pkt,__pyx_v_hdr->caplen); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; goto __pyx_L1;}
1154 __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
1155 PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
1156 PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
1157 __pyx_3 = 0;
1158 __pyx_4 = 0;
1159 __pyx_3 = PySequence_Tuple(__pyx_v_args); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
1160 __pyx_4 = PyNumber_Add(__pyx_5, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
1161 Py_DECREF(__pyx_5); __pyx_5 = 0;
1162 Py_DECREF(__pyx_3); __pyx_3 = 0;
1163 __pyx_5 = PyObject_CallObject(__pyx_v_callback, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
1164 Py_DECREF(__pyx_4); __pyx_4 = 0;
1165 Py_DECREF(__pyx_5); __pyx_5 = 0;
1166 goto __pyx_L4;
1167 }
1168 __pyx_2 = (__pyx_v_n == (-1));
1169 if (__pyx_2) {
1170
1171 /* "/Users/dugsong/projects/pypcap/pcap.pyx":312 */
1172 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_KeyboardInterrupt); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; goto __pyx_L1;}
1173 __Pyx_Raise(__pyx_3, 0, 0);
1174 Py_DECREF(__pyx_3); __pyx_3 = 0;
1175 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; goto __pyx_L1;}
1176 goto __pyx_L4;
1177 }
1178 __pyx_2 = (__pyx_v_n == (-2));
1179 if (__pyx_2) {
1180
1181 /* "/Users/dugsong/projects/pypcap/pcap.pyx":314 */
1182 goto __pyx_L3;
1183 goto __pyx_L4;
1184 }
1185 __pyx_L4:;
1186 }
1187 __pyx_L3:;
1188
1189 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1190 goto __pyx_L0;
1191 __pyx_L1:;
1192 Py_XDECREF(__pyx_3);
1193 Py_XDECREF(__pyx_4);
1194 Py_XDECREF(__pyx_5);
1195 __Pyx_AddTraceback("pcap.pcap.loop");
1196 __pyx_r = 0;
1197 __pyx_L0:;
1198 Py_XDECREF(__pyx_v_args);
1199 Py_DECREF(__pyx_v_self);
1200 Py_DECREF(__pyx_v_callback);
1201 Py_XDECREF(__pyx_args);
1202 Py_XDECREF(__pyx_kwds);
1203 return __pyx_r;
1204 }
1205
1206 static PyObject *__pyx_f_4pcap_4pcap_geterr(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1207 static char __pyx_doc_4pcap_4pcap_geterr[] = "Return the last error message associated with this handle.";
__pyx_f_4pcap_4pcap_geterr(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1208 static PyObject *__pyx_f_4pcap_4pcap_geterr(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1209 PyObject *__pyx_r;
1210 PyObject *__pyx_1 = 0;
1211 static char *__pyx_argnames[] = {0};
1212 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
1213 Py_INCREF(__pyx_v_self);
1214
1215 /* "/Users/dugsong/projects/pypcap/pcap.pyx":318 */
1216 __pyx_1 = PyString_FromString(pcap_geterr(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 318; goto __pyx_L1;}
1217 __pyx_r = __pyx_1;
1218 __pyx_1 = 0;
1219 goto __pyx_L0;
1220
1221 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1222 goto __pyx_L0;
1223 __pyx_L1:;
1224 Py_XDECREF(__pyx_1);
1225 __Pyx_AddTraceback("pcap.pcap.geterr");
1226 __pyx_r = 0;
1227 __pyx_L0:;
1228 Py_DECREF(__pyx_v_self);
1229 return __pyx_r;
1230 }
1231
1232 static PyObject *__pyx_f_4pcap_4pcap_stats(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1233 static char __pyx_doc_4pcap_4pcap_stats[] = "Return a 3-tuple of the total number of packets received,\n dropped, and dropped by the interface.";
__pyx_f_4pcap_4pcap_stats(PyObject * __pyx_v_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1234 static PyObject *__pyx_f_4pcap_4pcap_stats(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1235 struct pcap_stat __pyx_v_pstat;
1236 PyObject *__pyx_r;
1237 int __pyx_1;
1238 PyObject *__pyx_2 = 0;
1239 PyObject *__pyx_3 = 0;
1240 PyObject *__pyx_4 = 0;
1241 PyObject *__pyx_5 = 0;
1242 static char *__pyx_argnames[] = {0};
1243 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
1244 Py_INCREF(__pyx_v_self);
1245
1246 /* "/Users/dugsong/projects/pypcap/pcap.pyx":324 */
1247 __pyx_1 = (pcap_stats(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_pstat)) < 0);
1248 if (__pyx_1) {
1249
1250 /* "/Users/dugsong/projects/pypcap/pcap.pyx":325 */
1251 __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; goto __pyx_L1;}
1252 __pyx_3 = PyString_FromString(pcap_geterr(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; goto __pyx_L1;}
1253 __Pyx_Raise(__pyx_2, __pyx_3, 0);
1254 Py_DECREF(__pyx_2); __pyx_2 = 0;
1255 Py_DECREF(__pyx_3); __pyx_3 = 0;
1256 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; goto __pyx_L1;}
1257 goto __pyx_L2;
1258 }
1259 __pyx_L2:;
1260
1261 /* "/Users/dugsong/projects/pypcap/pcap.pyx":326 */
1262 __pyx_2 = PyInt_FromLong(__pyx_v_pstat.ps_recv); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
1263 __pyx_3 = PyInt_FromLong(__pyx_v_pstat.ps_drop); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
1264 __pyx_4 = PyInt_FromLong(__pyx_v_pstat.ps_ifdrop); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
1265 __pyx_5 = PyTuple_New(3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
1266 PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
1267 PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3);
1268 PyTuple_SET_ITEM(__pyx_5, 2, __pyx_4);
1269 __pyx_2 = 0;
1270 __pyx_3 = 0;
1271 __pyx_4 = 0;
1272 __pyx_r = __pyx_5;
1273 __pyx_5 = 0;
1274 goto __pyx_L0;
1275
1276 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1277 goto __pyx_L0;
1278 __pyx_L1:;
1279 Py_XDECREF(__pyx_2);
1280 Py_XDECREF(__pyx_3);
1281 Py_XDECREF(__pyx_4);
1282 Py_XDECREF(__pyx_5);
1283 __Pyx_AddTraceback("pcap.pcap.stats");
1284 __pyx_r = 0;
1285 __pyx_L0:;
1286 Py_DECREF(__pyx_v_self);
1287 return __pyx_r;
1288 }
1289
1290 static PyObject *__pyx_f_4pcap_4pcap___iter__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap___iter__(PyObject * __pyx_v_self)1291 static PyObject *__pyx_f_4pcap_4pcap___iter__(PyObject *__pyx_v_self) {
1292 PyObject *__pyx_r;
1293 Py_INCREF(__pyx_v_self);
1294
1295 /* "/Users/dugsong/projects/pypcap/pcap.pyx":329 */
1296 pcap_ex_setup(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap);
1297
1298 /* "/Users/dugsong/projects/pypcap/pcap.pyx":330 */
1299 Py_INCREF(__pyx_v_self);
1300 __pyx_r = __pyx_v_self;
1301 goto __pyx_L0;
1302
1303 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1304 goto __pyx_L0;
1305 __pyx_L1:;
1306 __Pyx_AddTraceback("pcap.pcap.__iter__");
1307 __pyx_r = 0;
1308 __pyx_L0:;
1309 Py_DECREF(__pyx_v_self);
1310 return __pyx_r;
1311 }
1312
1313 static PyObject *__pyx_n_StopIteration;
1314
1315 static PyObject *__pyx_f_4pcap_4pcap___next__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap___next__(PyObject * __pyx_v_self)1316 static PyObject *__pyx_f_4pcap_4pcap___next__(PyObject *__pyx_v_self) {
1317 struct pcap_pkthdr (*__pyx_v_hdr);
1318 char (*__pyx_v_pkt);
1319 int __pyx_v_n;
1320 PyObject *__pyx_r;
1321 long __pyx_1;
1322 int __pyx_2;
1323 PyObject *__pyx_3 = 0;
1324 PyObject *__pyx_4 = 0;
1325 PyObject *__pyx_5 = 0;
1326 Py_INCREF(__pyx_v_self);
1327
1328 /* "/Users/dugsong/projects/pypcap/pcap.pyx":336 */
1329 while (1) {
1330 __pyx_L2:;
1331 __pyx_1 = 1;
1332 if (!__pyx_1) break;
1333
1334 /* "/Users/dugsong/projects/pypcap/pcap.pyx":337 */
1335 Py_BEGIN_ALLOW_THREADS;
1336
1337 /* "/Users/dugsong/projects/pypcap/pcap.pyx":338 */
1338 __pyx_v_n = pcap_ex_next(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap,(&__pyx_v_hdr),(&__pyx_v_pkt));
1339
1340 /* "/Users/dugsong/projects/pypcap/pcap.pyx":339 */
1341 Py_END_ALLOW_THREADS;
1342
1343 /* "/Users/dugsong/projects/pypcap/pcap.pyx":340 */
1344 __pyx_2 = (__pyx_v_n == 1);
1345 if (__pyx_2) {
1346
1347 /* "/Users/dugsong/projects/pypcap/pcap.pyx":341 */
1348 __pyx_3 = PyFloat_FromDouble((__pyx_v_hdr->ts.tv_sec + (__pyx_v_hdr->ts.tv_usec / 1000000.0))); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; goto __pyx_L1;}
1349 __pyx_4 = PyBuffer_FromMemory(__pyx_v_pkt,__pyx_v_hdr->caplen); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; goto __pyx_L1;}
1350 __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; goto __pyx_L1;}
1351 PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
1352 PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
1353 __pyx_3 = 0;
1354 __pyx_4 = 0;
1355 __pyx_r = __pyx_5;
1356 __pyx_5 = 0;
1357 goto __pyx_L0;
1358 goto __pyx_L4;
1359 }
1360 __pyx_2 = (__pyx_v_n == (-1));
1361 if (__pyx_2) {
1362
1363 /* "/Users/dugsong/projects/pypcap/pcap.pyx":344 */
1364 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_KeyboardInterrupt); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; goto __pyx_L1;}
1365 __Pyx_Raise(__pyx_3, 0, 0);
1366 Py_DECREF(__pyx_3); __pyx_3 = 0;
1367 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; goto __pyx_L1;}
1368 goto __pyx_L4;
1369 }
1370 __pyx_2 = (__pyx_v_n == (-2));
1371 if (__pyx_2) {
1372
1373 /* "/Users/dugsong/projects/pypcap/pcap.pyx":346 */
1374 __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_StopIteration); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; goto __pyx_L1;}
1375 __Pyx_Raise(__pyx_4, 0, 0);
1376 Py_DECREF(__pyx_4); __pyx_4 = 0;
1377 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; goto __pyx_L1;}
1378 goto __pyx_L4;
1379 }
1380 __pyx_L4:;
1381 }
1382 __pyx_L3:;
1383
1384 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1385 goto __pyx_L0;
1386 __pyx_L1:;
1387 Py_XDECREF(__pyx_3);
1388 Py_XDECREF(__pyx_4);
1389 Py_XDECREF(__pyx_5);
1390 __Pyx_AddTraceback("pcap.pcap.__next__");
1391 __pyx_r = 0;
1392 __pyx_L0:;
1393 Py_DECREF(__pyx_v_self);
1394 return __pyx_r;
1395 }
1396
1397 static void __pyx_f_4pcap_4pcap___dealloc__(PyObject *__pyx_v_self); /*proto*/
__pyx_f_4pcap_4pcap___dealloc__(PyObject * __pyx_v_self)1398 static void __pyx_f_4pcap_4pcap___dealloc__(PyObject *__pyx_v_self) {
1399 int __pyx_1;
1400 Py_INCREF(__pyx_v_self);
1401
1402 /* "/Users/dugsong/projects/pypcap/pcap.pyx":349 */
1403 __pyx_1 = (((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__name != 0);
1404 if (__pyx_1) {
1405
1406 /* "/Users/dugsong/projects/pypcap/pcap.pyx":350 */
1407 free(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__name);
1408 goto __pyx_L2;
1409 }
1410 __pyx_L2:;
1411
1412 /* "/Users/dugsong/projects/pypcap/pcap.pyx":351 */
1413 __pyx_1 = (((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter != 0);
1414 if (__pyx_1) {
1415
1416 /* "/Users/dugsong/projects/pypcap/pcap.pyx":352 */
1417 free(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__filter);
1418 goto __pyx_L3;
1419 }
1420 __pyx_L3:;
1421
1422 /* "/Users/dugsong/projects/pypcap/pcap.pyx":353 */
1423 __pyx_1 = (((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap != 0);
1424 if (__pyx_1) {
1425
1426 /* "/Users/dugsong/projects/pypcap/pcap.pyx":354 */
1427 pcap_close(((struct __pyx_obj_4pcap_pcap *)__pyx_v_self)->__pcap);
1428 goto __pyx_L4;
1429 }
1430 __pyx_L4:;
1431
1432 goto __pyx_L0;
1433 __pyx_L1:;
1434 __Pyx_AddTraceback("pcap.pcap.__dealloc__");
1435 __pyx_L0:;
1436 Py_DECREF(__pyx_v_self);
1437 }
1438
1439 static PyObject *__pyx_f_4pcap_ex_name(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
__pyx_f_4pcap_ex_name(PyObject * __pyx_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1440 static PyObject *__pyx_f_4pcap_ex_name(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1441 char (*__pyx_v_foo);
1442 PyObject *__pyx_r;
1443 PyObject *__pyx_1 = 0;
1444 static char *__pyx_argnames[] = {"foo",0};
1445 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "s", __pyx_argnames, &__pyx_v_foo)) return 0;
1446
1447 /* "/Users/dugsong/projects/pypcap/pcap.pyx":357 */
1448 __pyx_1 = PyString_FromString(pcap_ex_name(__pyx_v_foo)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; goto __pyx_L1;}
1449 __pyx_r = __pyx_1;
1450 __pyx_1 = 0;
1451 goto __pyx_L0;
1452
1453 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1454 goto __pyx_L0;
1455 __pyx_L1:;
1456 Py_XDECREF(__pyx_1);
1457 __Pyx_AddTraceback("pcap.ex_name");
1458 __pyx_r = 0;
1459 __pyx_L0:;
1460 return __pyx_r;
1461 }
1462
1463 static PyObject *__pyx_f_4pcap_lookupdev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1464 static char __pyx_doc_4pcap_lookupdev[] = "Return the name of a network device suitable for sniffing.";
__pyx_f_4pcap_lookupdev(PyObject * __pyx_self,PyObject * __pyx_args,PyObject * __pyx_kwds)1465 static PyObject *__pyx_f_4pcap_lookupdev(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1466 char (*__pyx_v_p);
1467 char (__pyx_v_ebuf[256]);
1468 PyObject *__pyx_r;
1469 int __pyx_1;
1470 PyObject *__pyx_2 = 0;
1471 PyObject *__pyx_3 = 0;
1472 static char *__pyx_argnames[] = {0};
1473 if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
1474
1475 /* "/Users/dugsong/projects/pypcap/pcap.pyx":362 */
1476 __pyx_v_p = pcap_ex_lookupdev(__pyx_v_ebuf);
1477
1478 /* "/Users/dugsong/projects/pypcap/pcap.pyx":363 */
1479 __pyx_1 = (__pyx_v_p == 0);
1480 if (__pyx_1) {
1481
1482 /* "/Users/dugsong/projects/pypcap/pcap.pyx":364 */
1483 __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; goto __pyx_L1;}
1484 __pyx_3 = PyString_FromString(__pyx_v_ebuf); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; goto __pyx_L1;}
1485 __Pyx_Raise(__pyx_2, __pyx_3, 0);
1486 Py_DECREF(__pyx_2); __pyx_2 = 0;
1487 Py_DECREF(__pyx_3); __pyx_3 = 0;
1488 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; goto __pyx_L1;}
1489 goto __pyx_L2;
1490 }
1491 __pyx_L2:;
1492
1493 /* "/Users/dugsong/projects/pypcap/pcap.pyx":365 */
1494 __pyx_2 = PyString_FromString(__pyx_v_p); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; goto __pyx_L1;}
1495 __pyx_r = __pyx_2;
1496 __pyx_2 = 0;
1497 goto __pyx_L0;
1498
1499 __pyx_r = Py_None; Py_INCREF(__pyx_r);
1500 goto __pyx_L0;
1501 __pyx_L1:;
1502 Py_XDECREF(__pyx_2);
1503 Py_XDECREF(__pyx_3);
1504 __Pyx_AddTraceback("pcap.lookupdev");
1505 __pyx_r = 0;
1506 __pyx_L0:;
1507 return __pyx_r;
1508 }
1509
1510 static __Pyx_InternTabEntry __pyx_intern_tab[] = {
1511 {&__pyx_n_DLT_ARCNET, "DLT_ARCNET"},
1512 {&__pyx_n_DLT_AX25, "DLT_AX25"},
1513 {&__pyx_n_DLT_CHAOS, "DLT_CHAOS"},
1514 {&__pyx_n_DLT_EN10MB, "DLT_EN10MB"},
1515 {&__pyx_n_DLT_EN3MB, "DLT_EN3MB"},
1516 {&__pyx_n_DLT_FDDI, "DLT_FDDI"},
1517 {&__pyx_n_DLT_IEEE802, "DLT_IEEE802"},
1518 {&__pyx_n_DLT_LINUX_SLL, "DLT_LINUX_SLL"},
1519 {&__pyx_n_DLT_LOOP, "DLT_LOOP"},
1520 {&__pyx_n_DLT_NULL, "DLT_NULL"},
1521 {&__pyx_n_DLT_PFLOG, "DLT_PFLOG"},
1522 {&__pyx_n_DLT_PFSYNC, "DLT_PFSYNC"},
1523 {&__pyx_n_DLT_PPP, "DLT_PPP"},
1524 {&__pyx_n_DLT_PRONET, "DLT_PRONET"},
1525 {&__pyx_n_DLT_RAW, "DLT_RAW"},
1526 {&__pyx_n_DLT_SLIP, "DLT_SLIP"},
1527 {&__pyx_n_False, "False"},
1528 {&__pyx_n_IOError, "IOError"},
1529 {&__pyx_n_KeyError, "KeyError"},
1530 {&__pyx_n_KeyboardInterrupt, "KeyboardInterrupt"},
1531 {&__pyx_n_OSError, "OSError"},
1532 {&__pyx_n_StopIteration, "StopIteration"},
1533 {&__pyx_n_True, "True"},
1534 {&__pyx_n___add_pkts, "__add_pkts"},
1535 {&__pyx_n___author__, "__author__"},
1536 {&__pyx_n___copyright__, "__copyright__"},
1537 {&__pyx_n___license__, "__license__"},
1538 {&__pyx_n___url__, "__url__"},
1539 {&__pyx_n___version__, "__version__"},
1540 {&__pyx_n_append, "append"},
1541 {&__pyx_n_dispatch, "dispatch"},
1542 {&__pyx_n_dltoff, "dltoff"},
1543 {&__pyx_n_ex_name, "ex_name"},
1544 {&__pyx_n_exc_info, "exc_info"},
1545 {&__pyx_n_find, "find"},
1546 {&__pyx_n_len, "len"},
1547 {&__pyx_n_lookupdev, "lookupdev"},
1548 {&__pyx_n_openbsd, "openbsd"},
1549 {&__pyx_n_platform, "platform"},
1550 {&__pyx_n_sys, "sys"},
1551 {0, 0}
1552 };
1553
1554 static __Pyx_StringTabEntry __pyx_string_tab[] = {
1555 {&__pyx_k6p, __pyx_k6, sizeof(__pyx_k6)},
1556 {&__pyx_k7p, __pyx_k7, sizeof(__pyx_k7)},
1557 {&__pyx_k8p, __pyx_k8, sizeof(__pyx_k8)},
1558 {&__pyx_k9p, __pyx_k9, sizeof(__pyx_k9)},
1559 {&__pyx_k10p, __pyx_k10, sizeof(__pyx_k10)},
1560 {&__pyx_k21p, __pyx_k21, sizeof(__pyx_k21)},
1561 {&__pyx_k23p, __pyx_k23, sizeof(__pyx_k23)},
1562 {0, 0, 0}
1563 };
1564
__pyx_tp_new_4pcap_bpf(PyTypeObject * t,PyObject * a,PyObject * k)1565 static PyObject *__pyx_tp_new_4pcap_bpf(PyTypeObject *t, PyObject *a, PyObject *k) {
1566 PyObject *o = (*t->tp_alloc)(t, 0);
1567 struct __pyx_obj_4pcap_bpf *p = (struct __pyx_obj_4pcap_bpf *)o;
1568 return o;
1569 }
1570
__pyx_tp_dealloc_4pcap_bpf(PyObject * o)1571 static void __pyx_tp_dealloc_4pcap_bpf(PyObject *o) {
1572 struct __pyx_obj_4pcap_bpf *p = (struct __pyx_obj_4pcap_bpf *)o;
1573 {
1574 PyObject *etype, *eval, *etb;
1575 PyErr_Fetch(&etype, &eval, &etb);
1576 ++o->ob_refcnt;
1577 __pyx_f_4pcap_3bpf___dealloc__(o);
1578 if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
1579 --o->ob_refcnt;
1580 PyErr_Restore(etype, eval, etb);
1581 }
1582 (*o->ob_type->tp_free)(o);
1583 }
1584
__pyx_tp_traverse_4pcap_bpf(PyObject * o,visitproc v,void * a)1585 static int __pyx_tp_traverse_4pcap_bpf(PyObject *o, visitproc v, void *a) {
1586 int e;
1587 struct __pyx_obj_4pcap_bpf *p = (struct __pyx_obj_4pcap_bpf *)o;
1588 return 0;
1589 }
1590
__pyx_tp_clear_4pcap_bpf(PyObject * o)1591 static int __pyx_tp_clear_4pcap_bpf(PyObject *o) {
1592 struct __pyx_obj_4pcap_bpf *p = (struct __pyx_obj_4pcap_bpf *)o;
1593 return 0;
1594 }
1595
1596 static struct PyMethodDef __pyx_methods_4pcap_bpf[] = {
1597 {"filter", (PyCFunction)__pyx_f_4pcap_3bpf_filter, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_3bpf_filter},
1598 {0, 0, 0, 0}
1599 };
1600
1601 static PyNumberMethods __pyx_tp_as_number_bpf = {
1602 0, /*nb_add*/
1603 0, /*nb_subtract*/
1604 0, /*nb_multiply*/
1605 0, /*nb_divide*/
1606 0, /*nb_remainder*/
1607 0, /*nb_divmod*/
1608 0, /*nb_power*/
1609 0, /*nb_negative*/
1610 0, /*nb_positive*/
1611 0, /*nb_absolute*/
1612 0, /*nb_nonzero*/
1613 0, /*nb_invert*/
1614 0, /*nb_lshift*/
1615 0, /*nb_rshift*/
1616 0, /*nb_and*/
1617 0, /*nb_xor*/
1618 0, /*nb_or*/
1619 0, /*nb_coerce*/
1620 0, /*nb_int*/
1621 0, /*nb_long*/
1622 0, /*nb_float*/
1623 0, /*nb_oct*/
1624 0, /*nb_hex*/
1625 0, /*nb_inplace_add*/
1626 0, /*nb_inplace_subtract*/
1627 0, /*nb_inplace_multiply*/
1628 0, /*nb_inplace_divide*/
1629 0, /*nb_inplace_remainder*/
1630 0, /*nb_inplace_power*/
1631 0, /*nb_inplace_lshift*/
1632 0, /*nb_inplace_rshift*/
1633 0, /*nb_inplace_and*/
1634 0, /*nb_inplace_xor*/
1635 0, /*nb_inplace_or*/
1636 0, /*nb_floor_divide*/
1637 0, /*nb_true_divide*/
1638 0, /*nb_inplace_floor_divide*/
1639 0, /*nb_inplace_true_divide*/
1640 };
1641
1642 static PySequenceMethods __pyx_tp_as_sequence_bpf = {
1643 0, /*sq_length*/
1644 0, /*sq_concat*/
1645 0, /*sq_repeat*/
1646 0, /*sq_item*/
1647 0, /*sq_slice*/
1648 0, /*sq_ass_item*/
1649 0, /*sq_ass_slice*/
1650 0, /*sq_contains*/
1651 0, /*sq_inplace_concat*/
1652 0, /*sq_inplace_repeat*/
1653 };
1654
1655 static PyMappingMethods __pyx_tp_as_mapping_bpf = {
1656 0, /*mp_length*/
1657 0, /*mp_subscript*/
1658 0, /*mp_ass_subscript*/
1659 };
1660
1661 static PyBufferProcs __pyx_tp_as_buffer_bpf = {
1662 0, /*bf_getreadbuffer*/
1663 0, /*bf_getwritebuffer*/
1664 0, /*bf_getsegcount*/
1665 0, /*bf_getcharbuffer*/
1666 };
1667
1668 statichere PyTypeObject __pyx_type_4pcap_bpf = {
1669 PyObject_HEAD_INIT(0)
1670 0, /*ob_size*/
1671 "pcap.bpf", /*tp_name*/
1672 sizeof(struct __pyx_obj_4pcap_bpf), /*tp_basicsize*/
1673 0, /*tp_itemsize*/
1674 __pyx_tp_dealloc_4pcap_bpf, /*tp_dealloc*/
1675 0, /*tp_print*/
1676 0, /*tp_getattr*/
1677 0, /*tp_setattr*/
1678 0, /*tp_compare*/
1679 0, /*tp_repr*/
1680 &__pyx_tp_as_number_bpf, /*tp_as_number*/
1681 &__pyx_tp_as_sequence_bpf, /*tp_as_sequence*/
1682 &__pyx_tp_as_mapping_bpf, /*tp_as_mapping*/
1683 0, /*tp_hash*/
1684 0, /*tp_call*/
1685 0, /*tp_str*/
1686 0, /*tp_getattro*/
1687 0, /*tp_setattro*/
1688 &__pyx_tp_as_buffer_bpf, /*tp_as_buffer*/
1689 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
1690 "bpf(filter, dlt=DLT_RAW) -> BPF filter object", /*tp_doc*/
1691 __pyx_tp_traverse_4pcap_bpf, /*tp_traverse*/
1692 __pyx_tp_clear_4pcap_bpf, /*tp_clear*/
1693 0, /*tp_richcompare*/
1694 0, /*tp_weaklistoffset*/
1695 0, /*tp_iter*/
1696 0, /*tp_iternext*/
1697 __pyx_methods_4pcap_bpf, /*tp_methods*/
1698 0, /*tp_members*/
1699 0, /*tp_getset*/
1700 0, /*tp_base*/
1701 0, /*tp_dict*/
1702 0, /*tp_descr_get*/
1703 0, /*tp_descr_set*/
1704 0, /*tp_dictoffset*/
1705 __pyx_f_4pcap_3bpf___init__, /*tp_init*/
1706 0, /*tp_alloc*/
1707 __pyx_tp_new_4pcap_bpf, /*tp_new*/
1708 0, /*tp_free*/
1709 0, /*tp_is_gc*/
1710 0, /*tp_bases*/
1711 0, /*tp_mro*/
1712 0, /*tp_cache*/
1713 0, /*tp_subclasses*/
1714 0, /*tp_weaklist*/
1715 };
1716
__pyx_tp_new_4pcap_pcap(PyTypeObject * t,PyObject * a,PyObject * k)1717 static PyObject *__pyx_tp_new_4pcap_pcap(PyTypeObject *t, PyObject *a, PyObject *k) {
1718 PyObject *o = (*t->tp_alloc)(t, 0);
1719 struct __pyx_obj_4pcap_pcap *p = (struct __pyx_obj_4pcap_pcap *)o;
1720 return o;
1721 }
1722
__pyx_tp_dealloc_4pcap_pcap(PyObject * o)1723 static void __pyx_tp_dealloc_4pcap_pcap(PyObject *o) {
1724 struct __pyx_obj_4pcap_pcap *p = (struct __pyx_obj_4pcap_pcap *)o;
1725 {
1726 PyObject *etype, *eval, *etb;
1727 PyErr_Fetch(&etype, &eval, &etb);
1728 ++o->ob_refcnt;
1729 __pyx_f_4pcap_4pcap___dealloc__(o);
1730 if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
1731 --o->ob_refcnt;
1732 PyErr_Restore(etype, eval, etb);
1733 }
1734 (*o->ob_type->tp_free)(o);
1735 }
1736
__pyx_tp_traverse_4pcap_pcap(PyObject * o,visitproc v,void * a)1737 static int __pyx_tp_traverse_4pcap_pcap(PyObject *o, visitproc v, void *a) {
1738 int e;
1739 struct __pyx_obj_4pcap_pcap *p = (struct __pyx_obj_4pcap_pcap *)o;
1740 return 0;
1741 }
1742
__pyx_tp_clear_4pcap_pcap(PyObject * o)1743 static int __pyx_tp_clear_4pcap_pcap(PyObject *o) {
1744 struct __pyx_obj_4pcap_pcap *p = (struct __pyx_obj_4pcap_pcap *)o;
1745 return 0;
1746 }
1747
__pyx_getprop_4pcap_4pcap_name(PyObject * o,void * x)1748 static PyObject *__pyx_getprop_4pcap_4pcap_name(PyObject *o, void *x) {
1749 return __pyx_f_4pcap_4pcap_4name___get__(o);
1750 }
1751
__pyx_getprop_4pcap_4pcap_snaplen(PyObject * o,void * x)1752 static PyObject *__pyx_getprop_4pcap_4pcap_snaplen(PyObject *o, void *x) {
1753 return __pyx_f_4pcap_4pcap_7snaplen___get__(o);
1754 }
1755
__pyx_getprop_4pcap_4pcap_dloff(PyObject * o,void * x)1756 static PyObject *__pyx_getprop_4pcap_4pcap_dloff(PyObject *o, void *x) {
1757 return __pyx_f_4pcap_4pcap_5dloff___get__(o);
1758 }
1759
__pyx_getprop_4pcap_4pcap_filter(PyObject * o,void * x)1760 static PyObject *__pyx_getprop_4pcap_4pcap_filter(PyObject *o, void *x) {
1761 return __pyx_f_4pcap_4pcap_6filter___get__(o);
1762 }
1763
__pyx_getprop_4pcap_4pcap_fd(PyObject * o,void * x)1764 static PyObject *__pyx_getprop_4pcap_4pcap_fd(PyObject *o, void *x) {
1765 return __pyx_f_4pcap_4pcap_2fd___get__(o);
1766 }
1767
1768 static struct PyMethodDef __pyx_methods_4pcap_pcap[] = {
1769 {"fileno", (PyCFunction)__pyx_f_4pcap_4pcap_fileno, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_fileno},
1770 {"setfilter", (PyCFunction)__pyx_f_4pcap_4pcap_setfilter, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_setfilter},
1771 {"setnonblock", (PyCFunction)__pyx_f_4pcap_4pcap_setnonblock, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_setnonblock},
1772 {"getnonblock", (PyCFunction)__pyx_f_4pcap_4pcap_getnonblock, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_getnonblock},
1773 {"datalink", (PyCFunction)__pyx_f_4pcap_4pcap_datalink, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_datalink},
1774 {"next", (PyCFunction)__pyx_f_4pcap_4pcap_next, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_next},
1775 {"__add_pkts", (PyCFunction)__pyx_f_4pcap_4pcap___add_pkts, METH_VARARGS|METH_KEYWORDS, 0},
1776 {"readpkts", (PyCFunction)__pyx_f_4pcap_4pcap_readpkts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_readpkts},
1777 {"dispatch", (PyCFunction)__pyx_f_4pcap_4pcap_dispatch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_dispatch},
1778 {"loop", (PyCFunction)__pyx_f_4pcap_4pcap_loop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_loop},
1779 {"geterr", (PyCFunction)__pyx_f_4pcap_4pcap_geterr, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_geterr},
1780 {"stats", (PyCFunction)__pyx_f_4pcap_4pcap_stats, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_4pcap_stats},
1781 {0, 0, 0, 0}
1782 };
1783
1784 static struct PyGetSetDef __pyx_getsets_4pcap_pcap[] = {
1785 {"name", __pyx_getprop_4pcap_4pcap_name, 0, __pyx_k1, 0},
1786 {"snaplen", __pyx_getprop_4pcap_4pcap_snaplen, 0, __pyx_k2, 0},
1787 {"dloff", __pyx_getprop_4pcap_4pcap_dloff, 0, __pyx_k3, 0},
1788 {"filter", __pyx_getprop_4pcap_4pcap_filter, 0, __pyx_k4, 0},
1789 {"fd", __pyx_getprop_4pcap_4pcap_fd, 0, __pyx_k5, 0},
1790 {0, 0, 0, 0, 0}
1791 };
1792
1793 static PyNumberMethods __pyx_tp_as_number_pcap = {
1794 0, /*nb_add*/
1795 0, /*nb_subtract*/
1796 0, /*nb_multiply*/
1797 0, /*nb_divide*/
1798 0, /*nb_remainder*/
1799 0, /*nb_divmod*/
1800 0, /*nb_power*/
1801 0, /*nb_negative*/
1802 0, /*nb_positive*/
1803 0, /*nb_absolute*/
1804 0, /*nb_nonzero*/
1805 0, /*nb_invert*/
1806 0, /*nb_lshift*/
1807 0, /*nb_rshift*/
1808 0, /*nb_and*/
1809 0, /*nb_xor*/
1810 0, /*nb_or*/
1811 0, /*nb_coerce*/
1812 0, /*nb_int*/
1813 0, /*nb_long*/
1814 0, /*nb_float*/
1815 0, /*nb_oct*/
1816 0, /*nb_hex*/
1817 0, /*nb_inplace_add*/
1818 0, /*nb_inplace_subtract*/
1819 0, /*nb_inplace_multiply*/
1820 0, /*nb_inplace_divide*/
1821 0, /*nb_inplace_remainder*/
1822 0, /*nb_inplace_power*/
1823 0, /*nb_inplace_lshift*/
1824 0, /*nb_inplace_rshift*/
1825 0, /*nb_inplace_and*/
1826 0, /*nb_inplace_xor*/
1827 0, /*nb_inplace_or*/
1828 0, /*nb_floor_divide*/
1829 0, /*nb_true_divide*/
1830 0, /*nb_inplace_floor_divide*/
1831 0, /*nb_inplace_true_divide*/
1832 };
1833
1834 static PySequenceMethods __pyx_tp_as_sequence_pcap = {
1835 0, /*sq_length*/
1836 0, /*sq_concat*/
1837 0, /*sq_repeat*/
1838 0, /*sq_item*/
1839 0, /*sq_slice*/
1840 0, /*sq_ass_item*/
1841 0, /*sq_ass_slice*/
1842 0, /*sq_contains*/
1843 0, /*sq_inplace_concat*/
1844 0, /*sq_inplace_repeat*/
1845 };
1846
1847 static PyMappingMethods __pyx_tp_as_mapping_pcap = {
1848 0, /*mp_length*/
1849 0, /*mp_subscript*/
1850 0, /*mp_ass_subscript*/
1851 };
1852
1853 static PyBufferProcs __pyx_tp_as_buffer_pcap = {
1854 0, /*bf_getreadbuffer*/
1855 0, /*bf_getwritebuffer*/
1856 0, /*bf_getsegcount*/
1857 0, /*bf_getcharbuffer*/
1858 };
1859
1860 statichere PyTypeObject __pyx_type_4pcap_pcap = {
1861 PyObject_HEAD_INIT(0)
1862 0, /*ob_size*/
1863 "pcap.pcap", /*tp_name*/
1864 sizeof(struct __pyx_obj_4pcap_pcap), /*tp_basicsize*/
1865 0, /*tp_itemsize*/
1866 __pyx_tp_dealloc_4pcap_pcap, /*tp_dealloc*/
1867 0, /*tp_print*/
1868 0, /*tp_getattr*/
1869 0, /*tp_setattr*/
1870 0, /*tp_compare*/
1871 0, /*tp_repr*/
1872 &__pyx_tp_as_number_pcap, /*tp_as_number*/
1873 &__pyx_tp_as_sequence_pcap, /*tp_as_sequence*/
1874 &__pyx_tp_as_mapping_pcap, /*tp_as_mapping*/
1875 0, /*tp_hash*/
1876 0, /*tp_call*/
1877 0, /*tp_str*/
1878 0, /*tp_getattro*/
1879 0, /*tp_setattro*/
1880 &__pyx_tp_as_buffer_pcap, /*tp_as_buffer*/
1881 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
1882 "pcap(name=None, snaplen=65535, promisc=True, 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 immediate -- disable buffering, if possible\n ", /*tp_doc*/
1883 __pyx_tp_traverse_4pcap_pcap, /*tp_traverse*/
1884 __pyx_tp_clear_4pcap_pcap, /*tp_clear*/
1885 0, /*tp_richcompare*/
1886 0, /*tp_weaklistoffset*/
1887 __pyx_f_4pcap_4pcap___iter__, /*tp_iter*/
1888 __pyx_f_4pcap_4pcap___next__, /*tp_iternext*/
1889 __pyx_methods_4pcap_pcap, /*tp_methods*/
1890 0, /*tp_members*/
1891 __pyx_getsets_4pcap_pcap, /*tp_getset*/
1892 0, /*tp_base*/
1893 0, /*tp_dict*/
1894 0, /*tp_descr_get*/
1895 0, /*tp_descr_set*/
1896 0, /*tp_dictoffset*/
1897 __pyx_f_4pcap_4pcap___init__, /*tp_init*/
1898 0, /*tp_alloc*/
1899 __pyx_tp_new_4pcap_pcap, /*tp_new*/
1900 0, /*tp_free*/
1901 0, /*tp_is_gc*/
1902 0, /*tp_bases*/
1903 0, /*tp_mro*/
1904 0, /*tp_cache*/
1905 0, /*tp_subclasses*/
1906 0, /*tp_weaklist*/
1907 };
1908
1909 static struct PyMethodDef __pyx_methods[] = {
1910 {"ex_name", (PyCFunction)__pyx_f_4pcap_ex_name, METH_VARARGS|METH_KEYWORDS, 0},
1911 {"lookupdev", (PyCFunction)__pyx_f_4pcap_lookupdev, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4pcap_lookupdev},
1912 {0, 0, 0, 0}
1913 };
1914
1915 DL_EXPORT(void) initpcap(void); /*proto*/
initpcap(void)1916 DL_EXPORT(void) initpcap(void) {
1917 PyObject *__pyx_1 = 0;
1918 PyObject *__pyx_2 = 0;
1919 PyObject *__pyx_3 = 0;
1920 int __pyx_4;
1921 PyObject *__pyx_5 = 0;
1922 PyObject *__pyx_6 = 0;
1923 PyObject *__pyx_7 = 0;
1924 PyObject *__pyx_8 = 0;
1925 __pyx_m = Py_InitModule4("pcap", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
1926 if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;};
1927 __pyx_b = PyImport_AddModule("__builtin__");
1928 if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;};
1929 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;};
1930 if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;};
1931 if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; goto __pyx_L1;};
1932 if (PyType_Ready(&__pyx_type_4pcap_bpf) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
1933 if (PyObject_SetAttrString(__pyx_m, "bpf", (PyObject *)&__pyx_type_4pcap_bpf) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
1934 __pyx_ptype_4pcap_bpf = &__pyx_type_4pcap_bpf;
1935 if (PyType_Ready(&__pyx_type_4pcap_pcap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
1936 if (PyObject_SetAttrString(__pyx_m, "pcap", (PyObject *)&__pyx_type_4pcap_pcap) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
1937 __pyx_ptype_4pcap_pcap = &__pyx_type_4pcap_pcap;
1938
1939 /* "/Users/dugsong/projects/pypcap/pcap.pyx":13 */
1940 if (PyObject_SetAttr(__pyx_m, __pyx_n___author__, __pyx_k6p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;}
1941
1942 /* "/Users/dugsong/projects/pypcap/pcap.pyx":14 */
1943 if (PyObject_SetAttr(__pyx_m, __pyx_n___copyright__, __pyx_k7p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}
1944
1945 /* "/Users/dugsong/projects/pypcap/pcap.pyx":15 */
1946 if (PyObject_SetAttr(__pyx_m, __pyx_n___license__, __pyx_k8p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;}
1947
1948 /* "/Users/dugsong/projects/pypcap/pcap.pyx":16 */
1949 if (PyObject_SetAttr(__pyx_m, __pyx_n___url__, __pyx_k9p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
1950
1951 /* "/Users/dugsong/projects/pypcap/pcap.pyx":17 */
1952 if (PyObject_SetAttr(__pyx_m, __pyx_n___version__, __pyx_k10p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;}
1953
1954 /* "/Users/dugsong/projects/pypcap/pcap.pyx":19 */
1955 __pyx_1 = __Pyx_Import(__pyx_n_sys, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;}
1956 if (PyObject_SetAttr(__pyx_m, __pyx_n_sys, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;}
1957 Py_DECREF(__pyx_1); __pyx_1 = 0;
1958
1959 /* "/Users/dugsong/projects/pypcap/pcap.pyx":102 */
1960 __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; goto __pyx_L1;}
1961 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_NULL, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; goto __pyx_L1;}
1962 Py_DECREF(__pyx_1); __pyx_1 = 0;
1963
1964 /* "/Users/dugsong/projects/pypcap/pcap.pyx":103 */
1965 __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; goto __pyx_L1;}
1966 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_EN10MB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; goto __pyx_L1;}
1967 Py_DECREF(__pyx_1); __pyx_1 = 0;
1968
1969 /* "/Users/dugsong/projects/pypcap/pcap.pyx":104 */
1970 __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; goto __pyx_L1;}
1971 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_EN3MB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; goto __pyx_L1;}
1972 Py_DECREF(__pyx_1); __pyx_1 = 0;
1973
1974 /* "/Users/dugsong/projects/pypcap/pcap.pyx":105 */
1975 __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; goto __pyx_L1;}
1976 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_AX25, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; goto __pyx_L1;}
1977 Py_DECREF(__pyx_1); __pyx_1 = 0;
1978
1979 /* "/Users/dugsong/projects/pypcap/pcap.pyx":106 */
1980 __pyx_1 = PyInt_FromLong(4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
1981 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_PRONET, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; goto __pyx_L1;}
1982 Py_DECREF(__pyx_1); __pyx_1 = 0;
1983
1984 /* "/Users/dugsong/projects/pypcap/pcap.pyx":107 */
1985 __pyx_1 = PyInt_FromLong(5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L1;}
1986 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_CHAOS, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L1;}
1987 Py_DECREF(__pyx_1); __pyx_1 = 0;
1988
1989 /* "/Users/dugsong/projects/pypcap/pcap.pyx":108 */
1990 __pyx_1 = PyInt_FromLong(6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
1991 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_IEEE802, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
1992 Py_DECREF(__pyx_1); __pyx_1 = 0;
1993
1994 /* "/Users/dugsong/projects/pypcap/pcap.pyx":109 */
1995 __pyx_1 = PyInt_FromLong(7); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
1996 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_ARCNET, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; goto __pyx_L1;}
1997 Py_DECREF(__pyx_1); __pyx_1 = 0;
1998
1999 /* "/Users/dugsong/projects/pypcap/pcap.pyx":110 */
2000 __pyx_1 = PyInt_FromLong(8); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
2001 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_SLIP, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
2002 Py_DECREF(__pyx_1); __pyx_1 = 0;
2003
2004 /* "/Users/dugsong/projects/pypcap/pcap.pyx":111 */
2005 __pyx_1 = PyInt_FromLong(9); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; goto __pyx_L1;}
2006 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_PPP, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; goto __pyx_L1;}
2007 Py_DECREF(__pyx_1); __pyx_1 = 0;
2008
2009 /* "/Users/dugsong/projects/pypcap/pcap.pyx":112 */
2010 __pyx_1 = PyInt_FromLong(10); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
2011 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_FDDI, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
2012 Py_DECREF(__pyx_1); __pyx_1 = 0;
2013
2014 /* "/Users/dugsong/projects/pypcap/pcap.pyx":114 */
2015 __pyx_1 = PyInt_FromLong(113); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
2016 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_LINUX_SLL, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
2017 Py_DECREF(__pyx_1); __pyx_1 = 0;
2018
2019 /* "/Users/dugsong/projects/pypcap/pcap.pyx":116 */
2020 __pyx_1 = PyInt_FromLong(117); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; goto __pyx_L1;}
2021 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_PFLOG, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; goto __pyx_L1;}
2022 Py_DECREF(__pyx_1); __pyx_1 = 0;
2023
2024 /* "/Users/dugsong/projects/pypcap/pcap.pyx":117 */
2025 __pyx_1 = PyInt_FromLong(18); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
2026 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_PFSYNC, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; goto __pyx_L1;}
2027 Py_DECREF(__pyx_1); __pyx_1 = 0;
2028
2029 /* "/Users/dugsong/projects/pypcap/pcap.pyx":118 */
2030 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_sys); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2031 __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_n_platform); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2032 Py_DECREF(__pyx_1); __pyx_1 = 0;
2033 __pyx_1 = PyObject_GetAttr(__pyx_2, __pyx_n_find); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2034 Py_DECREF(__pyx_2); __pyx_2 = 0;
2035 __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2036 Py_INCREF(__pyx_n_openbsd);
2037 PyTuple_SET_ITEM(__pyx_2, 0, __pyx_n_openbsd);
2038 __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2039 Py_DECREF(__pyx_1); __pyx_1 = 0;
2040 Py_DECREF(__pyx_2); __pyx_2 = 0;
2041 __pyx_1 = PyInt_FromLong((-1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2042 if (PyObject_Cmp(__pyx_3, __pyx_1, &__pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L1;}
2043 __pyx_4 = __pyx_4 != 0;
2044 Py_DECREF(__pyx_3); __pyx_3 = 0;
2045 Py_DECREF(__pyx_1); __pyx_1 = 0;
2046 if (__pyx_4) {
2047
2048 /* "/Users/dugsong/projects/pypcap/pcap.pyx":119 */
2049 __pyx_2 = PyInt_FromLong(12); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
2050 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_LOOP, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; goto __pyx_L1;}
2051 Py_DECREF(__pyx_2); __pyx_2 = 0;
2052
2053 /* "/Users/dugsong/projects/pypcap/pcap.pyx":120 */
2054 __pyx_3 = PyInt_FromLong(14); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
2055 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_RAW, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}
2056 Py_DECREF(__pyx_3); __pyx_3 = 0;
2057 goto __pyx_L3;
2058 }
2059 /*else*/ {
2060
2061 /* "/Users/dugsong/projects/pypcap/pcap.pyx":122 */
2062 __pyx_1 = PyInt_FromLong(108); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L1;}
2063 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_LOOP, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L1;}
2064 Py_DECREF(__pyx_1); __pyx_1 = 0;
2065
2066 /* "/Users/dugsong/projects/pypcap/pcap.pyx":123 */
2067 __pyx_2 = PyInt_FromLong(12); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
2068 if (PyObject_SetAttr(__pyx_m, __pyx_n_DLT_RAW, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
2069 Py_DECREF(__pyx_2); __pyx_2 = 0;
2070 }
2071 __pyx_L3:;
2072
2073 /* "/Users/dugsong/projects/pypcap/pcap.pyx":125 */
2074 __pyx_3 = PyDict_New(); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2075 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_NULL); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2076 __pyx_2 = PyInt_FromLong(4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2077 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2078 Py_DECREF(__pyx_1); __pyx_1 = 0;
2079 Py_DECREF(__pyx_2); __pyx_2 = 0;
2080 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_EN10MB); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2081 __pyx_2 = PyInt_FromLong(14); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2082 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2083 Py_DECREF(__pyx_1); __pyx_1 = 0;
2084 Py_DECREF(__pyx_2); __pyx_2 = 0;
2085 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_IEEE802); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2086 __pyx_2 = PyInt_FromLong(22); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2087 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2088 Py_DECREF(__pyx_1); __pyx_1 = 0;
2089 Py_DECREF(__pyx_2); __pyx_2 = 0;
2090 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_ARCNET); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2091 __pyx_2 = PyInt_FromLong(6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2092 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2093 Py_DECREF(__pyx_1); __pyx_1 = 0;
2094 Py_DECREF(__pyx_2); __pyx_2 = 0;
2095 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_SLIP); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2096 __pyx_2 = PyInt_FromLong(16); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2097 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2098 Py_DECREF(__pyx_1); __pyx_1 = 0;
2099 Py_DECREF(__pyx_2); __pyx_2 = 0;
2100 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_PPP); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2101 __pyx_2 = PyInt_FromLong(4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2102 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2103 Py_DECREF(__pyx_1); __pyx_1 = 0;
2104 Py_DECREF(__pyx_2); __pyx_2 = 0;
2105 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_FDDI); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2106 __pyx_2 = PyInt_FromLong(21); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2107 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2108 Py_DECREF(__pyx_1); __pyx_1 = 0;
2109 Py_DECREF(__pyx_2); __pyx_2 = 0;
2110 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_PFLOG); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2111 __pyx_2 = PyInt_FromLong(48); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2112 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2113 Py_DECREF(__pyx_1); __pyx_1 = 0;
2114 Py_DECREF(__pyx_2); __pyx_2 = 0;
2115 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_PFSYNC); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2116 __pyx_2 = PyInt_FromLong(4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L1;}
2117 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2118 Py_DECREF(__pyx_1); __pyx_1 = 0;
2119 Py_DECREF(__pyx_2); __pyx_2 = 0;
2120 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_LOOP); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2121 __pyx_2 = PyInt_FromLong(4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2122 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2123 Py_DECREF(__pyx_1); __pyx_1 = 0;
2124 Py_DECREF(__pyx_2); __pyx_2 = 0;
2125 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_RAW); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2126 __pyx_2 = PyInt_FromLong(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2127 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2128 Py_DECREF(__pyx_1); __pyx_1 = 0;
2129 Py_DECREF(__pyx_2); __pyx_2 = 0;
2130 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_LINUX_SLL); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2131 __pyx_2 = PyInt_FromLong(16); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; goto __pyx_L1;}
2132 if (PyDict_SetItem(__pyx_3, __pyx_1, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2133 Py_DECREF(__pyx_1); __pyx_1 = 0;
2134 Py_DECREF(__pyx_2); __pyx_2 = 0;
2135 if (PyObject_SetAttr(__pyx_m, __pyx_n_dltoff, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; goto __pyx_L1;}
2136 Py_DECREF(__pyx_3); __pyx_3 = 0;
2137
2138 /* "/Users/dugsong/projects/pypcap/pcap.pyx":132 */
2139 __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_DLT_RAW); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; goto __pyx_L1;}
2140 __pyx_k13 = __pyx_1;
2141 __pyx_1 = 0;
2142
2143 /* "/Users/dugsong/projects/pypcap/pcap.pyx":163 */
2144 Py_INCREF(Py_None);
2145 __pyx_k14 = Py_None;
2146 __pyx_2 = PyInt_FromLong(65535); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; goto __pyx_L1;}
2147 __pyx_k15 = __pyx_2;
2148 __pyx_2 = 0;
2149 __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; goto __pyx_L1;}
2150 __pyx_k16 = __pyx_3;
2151 __pyx_3 = 0;
2152 __pyx_5 = PyInt_FromLong(500); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; goto __pyx_L1;}
2153 __pyx_k17 = __pyx_5;
2154 __pyx_5 = 0;
2155 __pyx_6 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; goto __pyx_L1;}
2156 __pyx_k18 = __pyx_6;
2157 __pyx_6 = 0;
2158
2159 /* "/Users/dugsong/projects/pypcap/pcap.pyx":218 */
2160 __pyx_7 = PyInt_FromLong(1); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; goto __pyx_L1;}
2161 __pyx_k19 = __pyx_7;
2162 __pyx_7 = 0;
2163
2164 /* "/Users/dugsong/projects/pypcap/pcap.pyx":229 */
2165 __pyx_8 = __Pyx_GetName(__pyx_b, __pyx_n_True); if (!__pyx_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; goto __pyx_L1;}
2166 __pyx_k20 = __pyx_8;
2167 __pyx_8 = 0;
2168
2169 /* "/Users/dugsong/projects/pypcap/pcap.pyx":359 */
2170 return;
2171 __pyx_L1:;
2172 Py_XDECREF(__pyx_1);
2173 Py_XDECREF(__pyx_2);
2174 Py_XDECREF(__pyx_3);
2175 Py_XDECREF(__pyx_5);
2176 Py_XDECREF(__pyx_6);
2177 Py_XDECREF(__pyx_7);
2178 Py_XDECREF(__pyx_8);
2179 __Pyx_AddTraceback("pcap");
2180 }
2181
2182 static char *__pyx_filenames[] = {
2183 "pcap.pyx",
2184 };
2185 statichere char **__pyx_f = __pyx_filenames;
2186
2187 /* Runtime support code */
2188
__Pyx_GetStarArgs(PyObject ** args,PyObject ** kwds,char * kwd_list[],int nargs,PyObject ** args2,PyObject ** kwds2)2189 static int __Pyx_GetStarArgs(
2190 PyObject **args,
2191 PyObject **kwds,
2192 char *kwd_list[],
2193 int nargs,
2194 PyObject **args2,
2195 PyObject **kwds2)
2196 {
2197 PyObject *x = 0, *args1 = 0, *kwds1 = 0;
2198
2199 if (args2)
2200 *args2 = 0;
2201 if (kwds2)
2202 *kwds2 = 0;
2203
2204 if (args2) {
2205 args1 = PyTuple_GetSlice(*args, 0, nargs);
2206 if (!args1)
2207 goto bad;
2208 *args2 = PyTuple_GetSlice(*args, nargs, PyTuple_Size(*args));
2209 if (!*args2)
2210 goto bad;
2211 }
2212 else {
2213 args1 = *args;
2214 Py_INCREF(args1);
2215 }
2216
2217 if (kwds2) {
2218 if (*kwds) {
2219 char **p;
2220 kwds1 = PyDict_New();
2221 if (!kwds)
2222 goto bad;
2223 *kwds2 = PyDict_Copy(*kwds);
2224 if (!*kwds2)
2225 goto bad;
2226 for (p = kwd_list; *p; p++) {
2227 x = PyDict_GetItemString(*kwds, *p);
2228 if (x) {
2229 if (PyDict_SetItemString(kwds1, *p, x) < 0)
2230 goto bad;
2231 if (PyDict_DelItemString(*kwds2, *p) < 0)
2232 goto bad;
2233 }
2234 }
2235 }
2236 else {
2237 *kwds2 = PyDict_New();
2238 if (!*kwds2)
2239 goto bad;
2240 }
2241 }
2242 else {
2243 kwds1 = *kwds;
2244 Py_XINCREF(kwds1);
2245 }
2246
2247 *args = args1;
2248 *kwds = kwds1;
2249 return 0;
2250 bad:
2251 Py_XDECREF(args1);
2252 Py_XDECREF(kwds1);
2253 if (*args2)
2254 Py_XDECREF(*args2);
2255 if (*kwds2)
2256 Py_XDECREF(*kwds2);
2257 return -1;
2258 }
2259
__Pyx_Import(PyObject * name,PyObject * from_list)2260 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
2261 PyObject *__import__ = 0;
2262 PyObject *empty_list = 0;
2263 PyObject *module = 0;
2264 PyObject *global_dict = 0;
2265 PyObject *empty_dict = 0;
2266 PyObject *list;
2267 __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
2268 if (!__import__)
2269 goto bad;
2270 if (from_list)
2271 list = from_list;
2272 else {
2273 empty_list = PyList_New(0);
2274 if (!empty_list)
2275 goto bad;
2276 list = empty_list;
2277 }
2278 global_dict = PyModule_GetDict(__pyx_m);
2279 if (!global_dict)
2280 goto bad;
2281 empty_dict = PyDict_New();
2282 if (!empty_dict)
2283 goto bad;
2284 module = PyObject_CallFunction(__import__, "OOOO",
2285 name, global_dict, empty_dict, list);
2286 bad:
2287 Py_XDECREF(empty_list);
2288 Py_XDECREF(__import__);
2289 Py_XDECREF(empty_dict);
2290 return module;
2291 }
2292
__Pyx_GetName(PyObject * dict,PyObject * name)2293 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
2294 PyObject *result;
2295 result = PyObject_GetAttr(dict, name);
2296 if (!result)
2297 PyErr_SetObject(PyExc_NameError, name);
2298 return result;
2299 }
2300
__Pyx_GetExcValue(void)2301 static PyObject *__Pyx_GetExcValue(void) {
2302 PyObject *type = 0, *value = 0, *tb = 0;
2303 PyObject *result = 0;
2304 PyThreadState *tstate = PyThreadState_Get();
2305 PyErr_Fetch(&type, &value, &tb);
2306 PyErr_NormalizeException(&type, &value, &tb);
2307 if (PyErr_Occurred())
2308 goto bad;
2309 if (!value) {
2310 value = Py_None;
2311 Py_INCREF(value);
2312 }
2313 Py_XDECREF(tstate->exc_type);
2314 Py_XDECREF(tstate->exc_value);
2315 Py_XDECREF(tstate->exc_traceback);
2316 tstate->exc_type = type;
2317 tstate->exc_value = value;
2318 tstate->exc_traceback = tb;
2319 result = value;
2320 Py_XINCREF(result);
2321 type = 0;
2322 value = 0;
2323 tb = 0;
2324 bad:
2325 Py_XDECREF(type);
2326 Py_XDECREF(value);
2327 Py_XDECREF(tb);
2328 return result;
2329 }
2330
__Pyx_WriteUnraisable(char * name)2331 static void __Pyx_WriteUnraisable(char *name) {
2332 PyObject *old_exc, *old_val, *old_tb;
2333 PyObject *ctx;
2334 PyErr_Fetch(&old_exc, &old_val, &old_tb);
2335 ctx = PyString_FromString(name);
2336 PyErr_Restore(old_exc, old_val, old_tb);
2337 if (!ctx)
2338 ctx = Py_None;
2339 PyErr_WriteUnraisable(ctx);
2340 }
2341
__Pyx_Raise(PyObject * type,PyObject * value,PyObject * tb)2342 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
2343 Py_XINCREF(type);
2344 Py_XINCREF(value);
2345 Py_XINCREF(tb);
2346 /* First, check the traceback argument, replacing None with NULL. */
2347 if (tb == Py_None) {
2348 Py_DECREF(tb);
2349 tb = 0;
2350 }
2351 else if (tb != NULL && !PyTraceBack_Check(tb)) {
2352 PyErr_SetString(PyExc_TypeError,
2353 "raise: arg 3 must be a traceback or None");
2354 goto raise_error;
2355 }
2356 /* Next, replace a missing value with None */
2357 if (value == NULL) {
2358 value = Py_None;
2359 Py_INCREF(value);
2360 }
2361 /* Next, repeatedly, replace a tuple exception with its first item */
2362 while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
2363 PyObject *tmp = type;
2364 type = PyTuple_GET_ITEM(type, 0);
2365 Py_INCREF(type);
2366 Py_DECREF(tmp);
2367 }
2368 if (PyString_Check(type))
2369 ;
2370 else if (PyClass_Check(type))
2371 ; /*PyErr_NormalizeException(&type, &value, &tb);*/
2372 else if (PyInstance_Check(type)) {
2373 /* Raising an instance. The value should be a dummy. */
2374 if (value != Py_None) {
2375 PyErr_SetString(PyExc_TypeError,
2376 "instance exception may not have a separate value");
2377 goto raise_error;
2378 }
2379 else {
2380 /* Normalize to raise <class>, <instance> */
2381 Py_DECREF(value);
2382 value = type;
2383 type = (PyObject*) ((PyInstanceObject*)type)->in_class;
2384 Py_INCREF(type);
2385 }
2386 }
2387 else {
2388 /* Not something you can raise. You get an exception
2389 anyway, just not what you specified :-) */
2390 PyErr_Format(PyExc_TypeError,
2391 "exceptions must be strings, classes, or "
2392 "instances, not %s", type->ob_type->tp_name);
2393 goto raise_error;
2394 }
2395 PyErr_Restore(type, value, tb);
2396 return;
2397 raise_error:
2398 Py_XDECREF(value);
2399 Py_XDECREF(type);
2400 Py_XDECREF(tb);
2401 return;
2402 }
2403
__Pyx_InternStrings(__Pyx_InternTabEntry * t)2404 static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
2405 while (t->p) {
2406 *t->p = PyString_InternFromString(t->s);
2407 if (!*t->p)
2408 return -1;
2409 ++t;
2410 }
2411 return 0;
2412 }
2413
__Pyx_InitStrings(__Pyx_StringTabEntry * t)2414 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
2415 while (t->p) {
2416 *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
2417 if (!*t->p)
2418 return -1;
2419 ++t;
2420 }
2421 return 0;
2422 }
2423
2424 #include "compile.h"
2425 #include "frameobject.h"
2426 #include "traceback.h"
2427
__Pyx_AddTraceback(char * funcname)2428 static void __Pyx_AddTraceback(char *funcname) {
2429 PyObject *py_srcfile = 0;
2430 PyObject *py_funcname = 0;
2431 PyObject *py_globals = 0;
2432 PyObject *empty_tuple = 0;
2433 PyObject *empty_string = 0;
2434 PyCodeObject *py_code = 0;
2435 PyFrameObject *py_frame = 0;
2436
2437 py_srcfile = PyString_FromString(__pyx_filename);
2438 if (!py_srcfile) goto bad;
2439 py_funcname = PyString_FromString(funcname);
2440 if (!py_funcname) goto bad;
2441 py_globals = PyModule_GetDict(__pyx_m);
2442 if (!py_globals) goto bad;
2443 empty_tuple = PyTuple_New(0);
2444 if (!empty_tuple) goto bad;
2445 empty_string = PyString_FromString("");
2446 if (!empty_string) goto bad;
2447 py_code = PyCode_New(
2448 0, /*int argcount,*/
2449 0, /*int nlocals,*/
2450 0, /*int stacksize,*/
2451 0, /*int flags,*/
2452 empty_string, /*PyObject *code,*/
2453 empty_tuple, /*PyObject *consts,*/
2454 empty_tuple, /*PyObject *names,*/
2455 empty_tuple, /*PyObject *varnames,*/
2456 empty_tuple, /*PyObject *freevars,*/
2457 empty_tuple, /*PyObject *cellvars,*/
2458 py_srcfile, /*PyObject *filename,*/
2459 py_funcname, /*PyObject *name,*/
2460 __pyx_lineno, /*int firstlineno,*/
2461 empty_string /*PyObject *lnotab*/
2462 );
2463 if (!py_code) goto bad;
2464 py_frame = PyFrame_New(
2465 PyThreadState_Get(), /*PyThreadState *tstate,*/
2466 py_code, /*PyCodeObject *code,*/
2467 py_globals, /*PyObject *globals,*/
2468 0 /*PyObject *locals*/
2469 );
2470 if (!py_frame) goto bad;
2471 py_frame->f_lineno = __pyx_lineno;
2472 PyTraceBack_Here(py_frame);
2473 bad:
2474 Py_XDECREF(py_srcfile);
2475 Py_XDECREF(py_funcname);
2476 Py_XDECREF(empty_tuple);
2477 Py_XDECREF(empty_string);
2478 Py_XDECREF(py_code);
2479 Py_XDECREF(py_frame);
2480 }
2481