Index: nse_nsock.cc =================================================================== --- nse_nsock.cc (revision 6857) +++ nse_nsock.cc (working copy) @@ -55,6 +55,7 @@ static int l_nsock_ncap_open(lua_State* l); static int l_nsock_ncap_close(lua_State* l); static int l_nsock_ncap_register(lua_State *l); +static int l_nsock_ncap_unregister(lua_State *l); static int l_nsock_pcap_receive(lua_State* l); @@ -85,6 +86,7 @@ {"pcap_open", l_nsock_ncap_open}, {"pcap_close", l_nsock_ncap_close}, {"pcap_register", l_nsock_ncap_register}, + {"pcap_unregister", l_nsock_ncap_unregister}, {"pcap_receive", l_nsock_pcap_receive}, // {"callback_test", l_nsock_pcap_callback_test}, {NULL, NULL} @@ -1040,6 +1042,45 @@ return 0; } +static int l_nsock_ncap_unregister(lua_State *l){ + l_nsock_udata* udata = (l_nsock_udata*) auxiliar_checkclass(l, "nsock", 1); + + if(!udata->nsiod || !udata->ncap_socket) { + luaL_argerror(l, 1, "You can't unregister to nsock-pcap if it wasn't opened."); + return 0; + } + if(!udata->ncap_request){ + luaL_argerror(l, 1, "You are not registered to this socket."); + return 0; + } + struct ncap_request *nr = udata->ncap_request; + udata->ncap_request = NULL; + + assert(!nr->suspended); + + + /* results not received? */ + if(!nr->received){ + ncap_request_map_del(nr); + nsock_event_cancel(nsp, nr->nseid, 0); + nr->nseid = 0; + }else{ + if(nr->r_status) free(nr->r_status); + if(nr->r_layer2) free(nr->r_layer2); + } + + nr->l = NULL; + nr->ncap_cback_ref = 0; /* this ref is freed in different place (on udata->ncap_cback_ref) */ + if(nr->key) free(nr->key); + /* dont' free r_layer3, it's in the same block as r_layer2*/ + + free(nr); + + + /* that's it. return to lua */ + return 0; +} + /* (LUA) After "register" use this function to block, and wait for packet. * If packet is already captured, this function will return immidietly. *