|
Revision 5895, 0.6 kB
(checked in by haypo, 3 years ago)
|
|
Write ConntrackBase?._error() to factorize error code
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | |
|---|
| 2 | from pynetfilter_conntrack import (Conntrack, ConntrackEntry, |
|---|
| 3 | NFCT_ALL_CT_GROUPS, |
|---|
| 4 | NFCT_CB_STOP, NFCT_CB_CONTINUE) |
|---|
| 5 | from socket import AF_INET |
|---|
| 6 | |
|---|
| 7 | counter = 0 |
|---|
| 8 | |
|---|
| 9 | def event_cb(msgtype, ct, data): |
|---|
| 10 | global counter |
|---|
| 11 | counter += 1 |
|---|
| 12 | if 10 <= counter: |
|---|
| 13 | return NFCT_CB_STOP |
|---|
| 14 | |
|---|
| 15 | entry = ConntrackEntry(data, ct, msgtype, destroy=False) |
|---|
| 16 | print entry |
|---|
| 17 | |
|---|
| 18 | return NFCT_CB_CONTINUE |
|---|
| 19 | |
|---|
| 20 | def main(): |
|---|
| 21 | conntrack = Conntrack(subscriptions=NFCT_ALL_CT_GROUPS) |
|---|
| 22 | event_cb.conntrack = conntrack |
|---|
| 23 | try: |
|---|
| 24 | conntrack.catch(event_cb) |
|---|
| 25 | except KeyboardInterrupt: |
|---|
| 26 | print "Interrupted." |
|---|
| 27 | |
|---|
| 28 | main() |
|---|