Skip to content

Instantly share code, notes, and snippets.

@mattfox
mattfox / gist:46b6b6da081f4cb065f0e40e49cd783f
Created June 29, 2016 03:42
python-netfilterqueue run2
def run2(self):
"Version of the run method which uses normal socket.recv so that gevent can monkeypatch it"
import socket
cdef int fd = nfq_fd(self.h)
s = socket.fromfd(fd, socket.AF_UNIX, socket.SOCK_STREAM)
while True:
d = s.recv(BufferSize)
d_len = len(d)
if d_len >= 0:
nfq_handle_packet(self.h, d, d_len)
@mattfox
mattfox / gist:3ea31317a050b163a90b36d88c3e252b
Created June 29, 2016 03:40
python-netfilterqueue/gevent proof of concept
#!/usr/bin/env python
from gevent.server import StreamServer
from netfilterqueue import NetfilterQueue
from gevent import monkey; monkey.patch_socket()
def print_and_accept(pkt):
print(pkt)
pkt.accept()
def echo(socket, address):