From b6017ccf067a7fefa893c8bf19288a1909f17263 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 26 Dec 2002 12:08:04 +0000 Subject: [PATCH] new socket id arrangements, working on tun --- base/chiark-tcl.h | 19 ++- base/hook.c | 15 ++- base/idtable.c | 126 ++++++++++++++++++ base/tables-examples.tct | 33 ++++- base/tcmdifgen | 67 ++++++---- base/troglodyte-Makefile | 1 + dgram/dgram.c | 114 +++------------- hbytes/hbytes.h | 19 ++- hbytes/hook.c | 15 ++- tuntap/tuntap.c | 276 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 549 insertions(+), 136 deletions(-) create mode 100644 base/idtable.c create mode 100644 tuntap/tuntap.c diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index f8f59fd..f7d0110 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -175,10 +175,25 @@ int sockaddr_len(const SockAddr_Value*); const struct sockaddr *sockaddr_addr(const SockAddr_Value*); void sockaddr_free(const SockAddr_Value*); +/* from idtable.c */ + +typedef struct { + const char *const prefix; + int n; + void **a; +} IdDataTable; + +extern Tcl_ObjType tabledataid_nearlytype; +int tabledataid_parse(Tcl_Interp *ip, Tcl_Obj *o, IdDataTable *tab); + /* from dgram.c */ -extern Tcl_ObjType dgramsockid_type; -typedef struct DgramSocket *DgramSockID; +extern IdDataTable dgram_socks; +int newfdposixerr(Tcl_Interp *ip, int fd, const char *m); + +/* from tuntap.c */ + +extern IdDataTable tuntap_socks; /* from hook.c */ diff --git a/base/hook.c b/base/hook.c index a9d0316..b84306a 100644 --- a/base/hook.c +++ b/base/hook.c @@ -22,6 +22,13 @@ int posixerr(Tcl_Interp *ip, int errnoval, const char *m) { return TCL_ERROR; } +int newfdposixerr(Tcl_Interp *ip, int fd, const char *m) { + int e; + e= errno; + close(fd); + return posixerr(ip,e,m); +} + void objfreeir(Tcl_Obj *o) { if (o->typePtr && o->typePtr->freeIntRepProc) o->typePtr->freeIntRepProc(o); @@ -361,6 +368,12 @@ int do_toplevel_dgram_socket(ClientData cd, Tcl_Interp *ip, return subcmd->func(0,ip,objc,objv); } +int do_toplevel_tuntap_socket(ClientData cd, Tcl_Interp *ip, + const TunSocket_SubCommand *subcmd, + int objc, Tcl_Obj *const *objv) { + return subcmd->func(0,ip,objc,objv); +} + int do_toplevel_ulong(ClientData cd, Tcl_Interp *ip, const ULong_SubCommand *subcmd, int objc, Tcl_Obj *const *objv) { @@ -400,7 +413,7 @@ int Hbytes_Init(Tcl_Interp *ip) { Tcl_RegisterObjType(&enum_nearlytype); Tcl_RegisterObjType(&enum1_nearlytype); Tcl_RegisterObjType(&sockaddr_type); - Tcl_RegisterObjType(&dgramsockid_type); + Tcl_RegisterObjType(&tabledataid_nearlytype); Tcl_RegisterObjType(&ulong_type); for (cmd=toplevel_commands; diff --git a/base/idtable.c b/base/idtable.c new file mode 100644 index 0000000..c2f3aaa --- /dev/null +++ b/base/idtable.c @@ -0,0 +1,126 @@ +/* + */ +/* + * dgram-socket create => + * dgram-socket close + * dgram-socket transmit + * dgram-socket on-receive [