X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=tuntap%2Ftuntap.c;h=9deec5745a6cea82b4ae479d51dfa55bf6068f37;hp=8de8247416007bd913555a6dfeb2f91ed3330d5f;hb=a079a543a386bd6946e48a628d2f768b3057dcc0;hpb=2ca964a890a31ab4f14f17cfbd359271cd8c4ea3 diff --git a/tuntap/tuntap.c b/tuntap/tuntap.c index 8de8247..9deec57 100644 --- a/tuntap/tuntap.c +++ b/tuntap/tuntap.c @@ -12,7 +12,6 @@ #include "tables.h" #include "hbytes.h" -#include "hbytes.h" #include #include @@ -27,8 +26,6 @@ typedef struct TunSocket { char *ifname; } TuntapSocket; -IdDataTable tuntap_socks= { "tuntap" }; - int do_tuntap_socket_raw_create(ClientData cd, Tcl_Interp *ip, const char *ifname, void **sock_r) { int fd, r; @@ -133,7 +130,7 @@ int do_tuntap_socket_raw_on_transmit(ClientData cd, Tcl_Interp *ip, cancel(sock); if (newscript) { - rc= scriptinv_set(&sock->script,ip,newscript); + rc= scriptinv_set(&sock->script,ip,newscript,0); if (rc) return rc; sock->mtu= mtu; @@ -143,15 +140,24 @@ int do_tuntap_socket_raw_on_transmit(ClientData cd, Tcl_Interp *ip, return TCL_OK; } -int do_tuntap_socket_raw_close(ClientData cd, Tcl_Interp *ip, void *sock_v) { +static void destroy(void *sock_v) { TuntapSocket *sock= sock_v; - - int sockix; cancel(sock); close(sock->fd); /* nothing useful to be done with errors */ - sockix= sock->ix; TFREE(sock->msg_buf); TFREE(sock); - tuntap_socks.a[sockix]= 0; +} + +static void destroy_idtabcb(Tcl_Interp *ip, void *sock_v) { + destroy(sock_v); +} + +int do_tuntap_socket_raw_close(ClientData cd, Tcl_Interp *ip, void *sock) { + destroy(sock); + tabledataid_disposing(ip,sock,&tuntap_socks); return TCL_OK; } + +const IdDataSpec tuntap_socks= { + "tuntap", "tuntap-table", destroy_idtabcb +};