Lines 1-15
Link Here
|
1 |
--- ./pcap.pyx.orig 2011-10-01 22:35:33.141146678 -0400 |
1 |
--- pcap.pyx.orig 2005-10-17 00:08:17 UTC |
2 |
+++ ./pcap.pyx 2011-10-01 22:35:39.416147272 -0400 |
2 |
+++ pcap.pyx |
3 |
@@ -1,7 +1,7 @@ |
3 |
@@ -17,9 +17,11 @@ __url__ = 'http://monkey.org/~dugsong/py |
4 |
# |
|
|
5 |
# pcap.pyx |
6 |
# |
7 |
-# $Id: pcap.pyx,v 1.20 2005/10/16 23:00:11 dugsong Exp $ |
8 |
+# $Id: pcap.pyx 101 2010-07-16 08:20:16Z kosma@kosma.pl $ |
9 |
|
10 |
"""packet capture library |
11 |
|
12 |
@@ -17,9 +17,11 @@ |
13 |
__version__ = '1.1' |
4 |
__version__ = '1.1' |
14 |
|
5 |
|
15 |
import sys |
6 |
import sys |
Lines 21-27
Link Here
|
21 |
int PyGILState_Ensure() |
12 |
int PyGILState_Ensure() |
22 |
void PyGILState_Release(int gil) |
13 |
void PyGILState_Release(int gil) |
23 |
void Py_BEGIN_ALLOW_THREADS() |
14 |
void Py_BEGIN_ALLOW_THREADS() |
24 |
@@ -42,6 +44,10 @@ |
15 |
@@ -42,6 +44,10 @@ cdef extern from "pcap.h": |
25 |
unsigned int caplen |
16 |
unsigned int caplen |
26 |
ctypedef struct pcap_t: |
17 |
ctypedef struct pcap_t: |
27 |
int __xxx |
18 |
int __xxx |
Lines 32-38
Link Here
|
32 |
|
23 |
|
33 |
ctypedef void (*pcap_handler)(void *arg, pcap_pkthdr *hdr, char *pkt) |
24 |
ctypedef void (*pcap_handler)(void *arg, pcap_pkthdr *hdr, char *pkt) |
34 |
|
25 |
|
35 |
@@ -62,6 +68,13 @@ |
26 |
@@ -62,6 +68,13 @@ cdef extern from "pcap.h": |
36 |
char *pcap_geterr(pcap_t *p) |
27 |
char *pcap_geterr(pcap_t *p) |
37 |
void pcap_close(pcap_t *p) |
28 |
void pcap_close(pcap_t *p) |
38 |
int bpf_filter(bpf_insn *insns, char *buf, int len, int caplen) |
29 |
int bpf_filter(bpf_insn *insns, char *buf, int len, int caplen) |
Lines 46-52
Link Here
|
46 |
|
37 |
|
47 |
cdef extern from "pcap_ex.h": |
38 |
cdef extern from "pcap_ex.h": |
48 |
# XXX - hrr, sync with libdnet and libevent |
39 |
# XXX - hrr, sync with libdnet and libevent |
49 |
@@ -134,16 +147,18 @@ |
40 |
@@ -134,16 +147,18 @@ cdef class bpf: |
50 |
raise IOError, 'bad filter' |
41 |
raise IOError, 'bad filter' |
51 |
def filter(self, buf): |
42 |
def filter(self, buf): |
52 |
"""Return boolean match for buf against our filter.""" |
43 |
"""Return boolean match for buf against our filter.""" |
Lines 68-74
Link Here
|
68 |
|
59 |
|
69 |
Open a handle to a packet capture descriptor. |
60 |
Open a handle to a packet capture descriptor. |
70 |
|
61 |
|
71 |
@@ -152,6 +167,9 @@ |
62 |
@@ -152,6 +167,9 @@ cdef class pcap: |
72 |
or None to open the first available up interface |
63 |
or None to open the first available up interface |
73 |
snaplen -- maximum number of bytes to capture for each packet |
64 |
snaplen -- maximum number of bytes to capture for each packet |
74 |
promisc -- boolean to specify promiscuous mode sniffing |
65 |
promisc -- boolean to specify promiscuous mode sniffing |
Lines 78-84
Link Here
|
78 |
immediate -- disable buffering, if possible |
69 |
immediate -- disable buffering, if possible |
79 |
""" |
70 |
""" |
80 |
cdef pcap_t *__pcap |
71 |
cdef pcap_t *__pcap |
81 |
@@ -161,7 +179,7 @@ |
72 |
@@ -161,7 +179,7 @@ cdef class pcap: |
82 |
cdef int __dloff |
73 |
cdef int __dloff |
83 |
|
74 |
|
84 |
def __init__(self, name=None, snaplen=65535, promisc=True, |
75 |
def __init__(self, name=None, snaplen=65535, promisc=True, |
Lines 87-102
Link Here
|
87 |
global dltoff |
78 |
global dltoff |
88 |
cdef char *p |
79 |
cdef char *p |
89 |
|
80 |
|
90 |
@@ -171,7 +189,7 @@ |
81 |
@@ -171,7 +189,7 @@ cdef class pcap: |
91 |
raise OSError, self.__ebuf |
82 |
raise OSError, self.__ebuf |
92 |
else: |
83 |
else: |
93 |
p = name |
84 |
p = name |
94 |
- |
85 |
- |
95 |
+ |
86 |
+ |
96 |
self.__pcap = pcap_open_offline(p, self.__ebuf) |
87 |
self.__pcap = pcap_open_offline(p, self.__ebuf) |
97 |
if not self.__pcap: |
88 |
if not self.__pcap: |
98 |
self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, |
89 |
self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc, |
99 |
@@ -184,7 +202,7 @@ |
90 |
@@ -184,7 +202,7 @@ cdef class pcap: |
100 |
try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] |
91 |
try: self.__dloff = dltoff[pcap_datalink(self.__pcap)] |
101 |
except KeyError: pass |
92 |
except KeyError: pass |
102 |
if immediate and pcap_ex_immediate(self.__pcap) < 0: |
93 |
if immediate and pcap_ex_immediate(self.__pcap) < 0: |
Lines 105-111
Link Here
|
105 |
|
96 |
|
106 |
property name: |
97 |
property name: |
107 |
"""Network interface or dumpfile name.""" |
98 |
"""Network interface or dumpfile name.""" |
108 |
@@ -243,16 +261,6 @@ |
99 |
@@ -243,16 +261,6 @@ cdef class pcap: |
109 |
"""Return datalink type (DLT_* values).""" |
100 |
"""Return datalink type (DLT_* values).""" |
110 |
return pcap_datalink(self.__pcap) |
101 |
return pcap_datalink(self.__pcap) |
111 |
|
102 |
|
Lines 122-128
Link Here
|
122 |
def __add_pkts(self, ts, pkt, pkts): |
113 |
def __add_pkts(self, ts, pkt, pkts): |
123 |
pkts.append((ts, pkt)) |
114 |
pkts.append((ts, pkt)) |
124 |
|
115 |
|
125 |
@@ -288,18 +296,24 @@ |
116 |
@@ -288,18 +296,24 @@ cdef class pcap: |
126 |
raise exc[0], exc[1], exc[2] |
117 |
raise exc[0], exc[1], exc[2] |
127 |
return n |
118 |
return n |
128 |
|
119 |
|
Lines 150-156
Link Here
|
150 |
pcap_ex_setup(self.__pcap) |
141 |
pcap_ex_setup(self.__pcap) |
151 |
while 1: |
142 |
while 1: |
152 |
Py_BEGIN_ALLOW_THREADS |
143 |
Py_BEGIN_ALLOW_THREADS |
153 |
@@ -308,10 +322,22 @@ |
144 |
@@ -308,10 +322,22 @@ cdef class pcap: |
154 |
if n == 1: |
145 |
if n == 1: |
155 |
callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), |
146 |
callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), |
156 |
PyBuffer_FromMemory(pkt, hdr.caplen), *args) |
147 |
PyBuffer_FromMemory(pkt, hdr.caplen), *args) |
Lines 173-179
Link Here
|
173 |
|
164 |
|
174 |
def geterr(self): |
165 |
def geterr(self): |
175 |
"""Return the last error message associated with this handle.""" |
166 |
"""Return the last error message associated with this handle.""" |
176 |
@@ -340,6 +366,8 @@ |
167 |
@@ -340,6 +366,8 @@ cdef class pcap: |
177 |
if n == 1: |
168 |
if n == 1: |
178 |
return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), |
169 |
return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0), |
179 |
PyBuffer_FromMemory(pkt, hdr.caplen)) |
170 |
PyBuffer_FromMemory(pkt, hdr.caplen)) |
Lines 182-188
Link Here
|
182 |
elif n == -1: |
173 |
elif n == -1: |
183 |
raise KeyboardInterrupt |
174 |
raise KeyboardInterrupt |
184 |
elif n == -2: |
175 |
elif n == -2: |
185 |
@@ -364,3 +392,36 @@ |
176 |
@@ -364,3 +392,36 @@ def lookupdev(): |
186 |
raise OSError, ebuf |
177 |
raise OSError, ebuf |
187 |
return p |
178 |
return p |
188 |
|
179 |
|