compatible with Python 3
This commit is contained in:
parent
6b8be8a5ec
commit
a008498677
6008
netfilterqueue.c
6008
netfilterqueue.c
File diff suppressed because it is too large
Load Diff
|
@ -47,6 +47,7 @@ cdef enum:
|
|||
IPPROTO_MAX
|
||||
|
||||
cdef extern from "Python.h":
|
||||
object PyBytes_FromStringAndSize(char *s, Py_ssize_t len)
|
||||
object PyString_FromStringAndSize(char *s, Py_ssize_t len)
|
||||
|
||||
cdef extern from "sys/time.h":
|
||||
|
|
|
@ -20,6 +20,8 @@ DEF BufferSize = 4096
|
|||
DEF MetadataSize = 80
|
||||
DEF MaxCopySize = BufferSize - MetadataSize
|
||||
|
||||
cimport cpython.version
|
||||
|
||||
cdef int global_callback(nfq_q_handle *qh, nfgenmsg *nfmsg,
|
||||
nfq_data *nfa, void *data) with gil:
|
||||
"""Create a Packet and pass it to appropriate callback."""
|
||||
|
@ -93,8 +95,13 @@ cdef class Packet:
|
|||
|
||||
def get_payload(self):
|
||||
"""Return payload as Python string."""
|
||||
cdef object py_string = PyString_FromStringAndSize(self.payload,
|
||||
self.payload_len)
|
||||
cdef object py_string
|
||||
if cpython.version.PY_MAJOR_VERSION >= 3:
|
||||
py_string = PyBytes_FromStringAndSize(
|
||||
self.payload, self.payload_len)
|
||||
else:
|
||||
py_string = PyString_FromStringAndSize(
|
||||
self.payload, self.payload_len)
|
||||
return py_string
|
||||
|
||||
cpdef Py_ssize_t get_payload_len(self):
|
||||
|
|
Loading…
Reference in New Issue