NF_EventHandler

The client application must implement this interface and pass the object pointer to nf_init function. nfapi code calls the methods of NF_EventHandler from separate thread(s) to indicate the driver notifications. The interface is defined as an abstract class with pure virtual functions for C++. If the symbol _C_API is defined, the interface is a structure with function pointers.

C++ (_C_API is not defined)

class NF_EventHandler
{
public:
        virtual void threadStart() = 0;
        virtual void threadEnd() = 0;

        //
        // TCP events
        //
        virtual void tcpConnectRequest(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo) = 0;
        virtual void tcpConnected(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo) = 0;
        virtual void tcpClosed(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo) = 0;
        virtual void tcpReceive(ENDPOINT_ID id, const char * buf, int len) = 0;
        virtual void tcpSend(ENDPOINT_ID id, const char * buf, int len) = 0;
        virtual void tcpCanReceive(ENDPOINT_ID id) = 0;
        virtual void tcpCanSend(ENDPOINT_ID id) = 0;

        //
        // UDP events
        //
        virtual void udpCreated(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo) = 0;
        virtual void udpConnectRequest(ENDPOINT_ID id, PNF_UDP_CONN_REQUEST pConnReq) = 0;
        virtual void udpClosed(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo) = 0;
        virtual void udpReceive(ENDPOINT_ID id, const unsigned char * remoteAddress, const char * buf, int len, PNF_UDP_OPTIONS options) = 0;
        virtual void udpSend(ENDPOINT_ID id, const unsigned char * remoteAddress, const char * buf, int len, PNF_UDP_OPTIONS options) = 0;
        virtual void udpCanReceive(ENDPOINT_ID id) = 0;
        virtual void udpCanSend(ENDPOINT_ID id) = 0;
};

C (_C_API is defined)

typedef struct _NF_EventHandler
{
        void (NFAPI_CC *threadStart)();
        void (NFAPI_CC *threadEnd)();

         //
         // TCP events
         //
         void (NFAPI_CC *tcpConnectRequest)(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo);
         void (NFAPI_CC *tcpConnected)(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo);
         void (NFAPI_CC *tcpClosed)(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo);
         void (NFAPI_CC *tcpReceive)(ENDPOINT_ID id, const char * buf, int len);
         void (NFAPI_CC *tcpSend)(ENDPOINT_ID id, const char * buf, int len);
         void (NFAPI_CC *tcpCanReceive)(ENDPOINT_ID id);
         void (NFAPI_CC *tcpCanSend)(ENDPOINT_ID id);

         //
         // UDP events
         //
         void (NFAPI_CC *udpCreated)(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo);
         void (NFAPI_CC *udpConnectRequest)(ENDPOINT_ID id, PNF_UDP_CONN_REQUEST pConnReq);
         void (NFAPI_CC *udpClosed)(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo);
         void (NFAPI_CC *udpReceive)(ENDPOINT_ID id, const unsigned char * remoteAddress, const char * buf, int len, PNF_UDP_OPTIONS options);
         void (NFAPI_CC *udpSend)(ENDPOINT_ID id, const unsigned char * remoteAddress, const char * buf, int len, PNF_UDP_OPTIONS options);
         void (NFAPI_CC *udpCanReceive)(ENDPOINT_ID id);
         void (NFAPI_CC *udpCanSend)(ENDPOINT_ID id);
} NF_EventHandler, *PNF_EventHandler;
void threadStart()

Called immediately after starting the filtering thread. Use this event for thread-specific initialization, e.g. calling CoInitialize() etc.

void threadEnd()

Called before stopping the thread.

void tcpConnectRequest(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo)
Parameters:
  • id – Connection identifier.

  • pConnInfo – Connection parameters, see NF_TCP_CONN_INFO.

Called before establishing an outgoing TCP connection, when NF_INDICATE_CONNECT_REQUESTS flag is enabled in an appropriate rule. It is possible to modify the fields filteringFlag and remoteAddress in pConnInfo structure. The changes are applied to the connection. It is possible to pend the operation and continue it later from any thread. To process the request asynchronously, specify the flag NF_PEND_CONNECT_REQUEST in NF_TCP_CONN_INFO.filteringFlag, then call nf_completeTCPConnectRequest later.

void tcpConnected(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo)
Parameters:
  • id – Connection identifier.

  • pConnInfo – Connection parameters, see NF_TCP_CONN_INFO.

Called after establishing incoming or outgoing TCP connection.

void tcpClosed(ENDPOINT_ID id, PNF_TCP_CONN_INFO pConnInfo)
Parameters:
  • id – Connection identifier.

  • pConnInfo – Connection parameters, see NF_TCP_CONN_INFO.

Called after closing a TCP connection.

void tcpReceive(ENDPOINT_ID id, const char *buf, int len)
Parameters:
  • id – Connection identifier.

  • buf – Pointer to data buffer.

  • len – Buffer length

Indicates the buffer received from server.

void tcpSend(ENDPOINT_ID id, const char *buf, int len)
Parameters:
  • id – Connection identifier.

  • buf – Pointer to data buffer.

  • len – Buffer length

Indicates the buffer sent from a local socket.

void tcpCanReceive(ENDPOINT_ID id)
Parameters:

id – Connection identifier.

Notifies that the internal buffer for inbound packets is empty and it is possible to call nf_tcpPostReceive for pushing receives via specified connection.

void tcpCanSend(ENDPOINT_ID id)
Parameters:

id – Connection identifier.

Notifies that the internal buffer for outbound packets is empty and it is possible to call nf_tcpPostSend for pushing sends via specified connection.

void udpCreated(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo)
Parameters:
  • id – Socket identifier.

  • pConnInfo – Socket parameters, see NF_UDP_CONN_INFO.

Called after creating UDP socket.

void udpConnectRequest(ENDPOINT_ID id, PNF_UDP_CONN_REQUEST pConnReq)

Not used.

void udpClosed(ENDPOINT_ID id, PNF_UDP_CONN_INFO pConnInfo)
Parameters:
  • id – Socket identifier.

  • pConnInfo – Socket parameters, see NF_UDP_CONN_INFO.

Called after closing a socket.

void udpReceive(ENDPOINT_ID id, const unsigned char *remoteAddress, const char *buf, int len, PNF_UDP_OPTIONS options)
Parameters:
  • id – Socket identifier.

  • remoteAddress – Source address.

  • buf – Pointer to data buffer.

  • len – Buffer length.

  • options – Pointer to NF_UDP_OPTIONS.

Indicates the buffer received from server.

void udpSend(ENDPOINT_ID id, const unsigned char *remoteAddress, const char *buf, int len, PNF_UDP_OPTIONS options)
Parameters:
  • id – Socket identifier.

  • remoteAddress – Source address.

  • buf – Pointer to data buffer.

  • len – Buffer length.

  • options – Pointer to NF_UDP_OPTIONS.

Indicates the buffer sent from a local socket.

void udpCanReceive(ENDPOINT_ID id)
Parameters:

id – Socket identifier.

Notifies that the internal buffer for inbound packets is empty, and it is possible to call nf_udpPostReceive for indicating receives via specified socket.

void udpCanSend(ENDPOINT_ID id)
Parameters:

id – Socket identifier.

Notifies that the internal buffer for outbound packets is empty, and it is possible to call nf_udpPostSend for indicating sends via specified socket.