@@ -29,6 +29,26 @@ it. ::
29
29
30
30
nfqueue.unbind()
31
31
32
+ You can also make your own socket so that it can be used with gevent, for example. ::
33
+
34
+ from netfilterqueue import NetfilterQueue
35
+ import socket
36
+
37
+ def print_and_accept(pkt):
38
+ print(pkt)
39
+ pkt.accept()
40
+
41
+ nfqueue = NetfilterQueue()
42
+ nfqueue.bind(1, print_and_accept)
43
+ s = socket.fromfd(nfqueue.get_fd(), socket.AF_UNIX, socket.SOCK_STREAM)
44
+ try:
45
+ nfqueue.run_socket(s)
46
+ except KeyboardInterrupt:
47
+ print('')
48
+
49
+ s.close()
50
+ nfqueue.unbind()
51
+
32
52
To send packets destined for your LAN to the script, type something like::
33
53
34
54
iptables -I INPUT -d 192.168.0.0/24 -j NFQUEUE --queue-num 1
@@ -107,6 +127,12 @@ a call to ``bind``, then start receiving packets with a call to ``run``.
107
127
block=False to let your thread continue. You can get the file descriptor
108
128
of the socket with the ``get_fd `` method.
109
129
130
+ ``QueueHandler.run_socket(socket) ``
131
+ Send packets to your callback, but use the supplied socket instead of
132
+ recv, so that, for example, gevent can monkeypatch it. You can make a
133
+ socket with ``socket.fromfd(nfqueue.get_fd(), socket.AF_UNIX, socket.SOCK_STREAM) ``
134
+ and optionally make it non-blocking with ``socket.setblocking(False) ``.
135
+
110
136
Packet objects
111
137
--------------
112
138
@@ -191,8 +217,6 @@ The fields are:
191
217
Limitations
192
218
===========
193
219
194
- More details coming soon...
195
-
196
220
* Compiled with a 4096-byte buffer for packets, so it probably won't work on
197
221
loopback or Ethernet with jumbo packets. If this is a problem, either lower
198
222
MTU on your loopback, disable jumbo packets, or get Cython,
0 commit comments