File tree 3 files changed +14
-3
lines changed
3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,15 @@ cdef class Packet:
57
57
self ._given_payload = None
58
58
59
59
def __str__ (self ):
60
- cdef iphdr * hdr = < iphdr* > self .payload
60
+ cdef unsigned char * payload = NULL
61
+ if self ._owned_payload:
62
+ payload = self ._owned_payload
63
+ elif self .payload != NULL :
64
+ payload = self .payload
65
+ else :
66
+ return " %d byte packet, contents unretained" % (self .payload_len,)
67
+
68
+ cdef iphdr * hdr = < iphdr* > payload
61
69
protocol = PROTOCOLS.get(hdr.protocol, " Unknown protocol" )
62
70
return " %s packet, %s bytes" % (protocol, self .payload_len)
63
71
Original file line number Diff line number Diff line change 3
3
4
4
exec (open ("netfilterqueue/_version.py" , encoding = "utf-8" ).read ())
5
5
6
- setup_requires = []
6
+ setup_requires = ["wheel" ]
7
7
try :
8
8
# Use Cython
9
9
from Cython .Build import cythonize
21
21
if "egg_info" in sys .argv :
22
22
# We're being run by pip to figure out what we need. Request cython in
23
23
# setup_requires below.
24
- setup_requires = ["cython" ]
24
+ setup_requires + = ["cython" ]
25
25
elif not os .path .exists (
26
26
os .path .join (os .path .dirname (__file__ ), "netfilterqueue/_impl.c" )
27
27
):
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ async def test_comms_without_queue(harness):
23
23
async def test_queue_dropping (harness ):
24
24
async def drop (packets , msg ):
25
25
async for packet in packets :
26
+ assert "UDP packet" in str (packet )
26
27
if packet .get_payload ()[28 :] == msg :
27
28
packet .drop ()
28
29
else :
@@ -190,6 +191,7 @@ async def test_errors(harness):
190
191
async def test_unretained (harness ):
191
192
def cb (chan , pkt ):
192
193
# Can access payload within callback
194
+ assert "UDP packet" in str (pkt )
193
195
assert pkt .get_payload ()[- 3 :] in (b"one" , b"two" )
194
196
chan .send_nowait (pkt )
195
197
@@ -202,6 +204,7 @@ def cb(chan, pkt):
202
204
RuntimeError , match = "Payload data is no longer available"
203
205
):
204
206
p .get_payload ()
207
+ assert "contents unretained" in str (p )
205
208
# Can still issue verdicts though
206
209
if accept :
207
210
p .accept ()
You can’t perform that action at this time.
0 commit comments