Esempio n. 1
0
 def __init__(self, group, reactor=None):
     FileDescriptor.__init__(self, reactor)
     self.wrapper = NFLog()
     self.wrapper.open()
     self.wrapper.bindProtocolFamily(AF_INET)
     self.group = group
     self.wrapper.bindGroup(group)
     self.wrapper.setMode(NFULNL_COPY_PACKET, 0xFFFF)
     self.wrapper.setCallback(self.nflogCallback)
Esempio n. 2
0
    def testWrapper(self):
        wrapper = NFLog()

        # open
        self.failUnlessEqual(wrapper.nflog_handle, 0)
        self.failUnlessEqual(wrapper.nfnl_handle, 0)
        wrapper.open()
        self.failIfEqual(wrapper.nflog_handle, 0)
        self.failIfEqual(wrapper.nfnl_handle, 0)

        # bindGroup
        self.failUnlessEqual(wrapper.nflog_g_handle, 0)
        wrapper.bindGroup(42)
        self.failIfEqual(wrapper.nflog_g_handle, 0)

        # if this is non blocking, it should hang and make the test fail
        self.failUnlessRaises(OSError, wrapper.catch)

        wrapper.close()
        
        self.failUnlessEqual(wrapper.nflog_handle, 0)
        self.failUnlessEqual(wrapper.nfnl_handle, 0)
        self.failUnlessEqual(wrapper.nflog_g_handle, 0)
Esempio n. 3
0
class NFLogDescriptor(FileDescriptor):
    def __init__(self, group, reactor=None):
        FileDescriptor.__init__(self, reactor)
        self.wrapper = NFLog()
        self.wrapper.open()
        self.wrapper.bindProtocolFamily(AF_INET)
        self.group = group
        self.wrapper.bindGroup(group)
        self.wrapper.setMode(NFULNL_COPY_PACKET, 0xFFFF)
        self.wrapper.setCallback(self.nflogCallback)

    def fileno(self):
        return self.wrapper.fd

    def doRead(self):
        try:
            # this will trigger our callback
            self.wrapper.catch()
        except (OSError, IOError), ioe:
            if ioe.args[0] in (errno.EAGAIN, errno.EINTR, errno.ENOBUFS):
                return
            else:
                return CONNECTION_LOST