@program tcpip.muf 1 1000 d i $include $lib/alynna $def INTERNET "$internet" match $def CLIDIR "/_ftc/" : client ( i -- s ) CLIDIR swap tostr "/" strcat strcat ; PUBLIC client : porthandle ( i -- i ) me @ swap client "handle" getprop toint ; PUBLIC porthandle : port2service ( i -- d ) INTERNET "/services/" rot tostr strcat getprop todbref ; PUBLIC port2service : ip2ref ( s -- d ) "." explode dup 3 = not if popn #-1 exit else pop then toint 65536 * -3 rotate toint 256 * -3 rotate toint + + dbref ; PUBLIC ip2ref : ref2ip ( d/i/s -- s ) var x toint x ! str x @ 65536 / "." x @ 256 / 256 % "." x @ 256 % cat ; PUBLIC ref2ip : getsock ( i(handle) s -- ? ) var handle var prop tostr prop ! toint handle ! INTERNET str "/sockets/" handle @ "/" prop @ cat getprop ; PUBLIC getsock : setsock ( i(handle) s ? -- ) var handle var prop var value value ! tostr prop ! toint handle ! INTERNET str "/sockets/" handle @ "/" prop @ cat value @ setprop ; PUBLIC setsock : getlsock ( i s -- ? ) var port var prop tostr prop ! toint port ! me @ str "/_ftc/" port @ "/" prop @ cat getprop ; PUBLIC getlsock : setlsock ( i s ? -- ) var port var prop var value value ! tostr prop ! toint port ! me @ str "/_ftc/" port @ "/" prop @ cat value @ setprop ; PUBLIC setlsock : opensock ( handle dest port -- ) var handle var dest var port port ! dest ! handle ! ( and set up socket ) handle @ "source" me @ setsock handle @ "sourceip" me @ ref2ip setsock handle @ "dest" dest @ setsock handle @ "destip" dest @ ref2ip setsock handle @ "port" port @ setsock handle @ "service" port @ port2service setsock ; PUBLIC opensock : them ( i -- d ) var handle handle ! me @ handle @ "source" getsock dbcmp if handle @ "dest" getsock else handle @ "source" getsock then ; PUBLIC them : closesock ( i -- ) var prop var handle toint handle ! ( remove all props on this handle ) INTERNET str "/sockets/" handle @ "/" cat array_get_propvals foreach pop prop ! INTERNET str "/sockets/" handle @ "/" prop @ cat 0 setprop repeat ; PUBLIC closesock : sendsock ( s i(handle) -- ) var handle var target var buffer handle ! buffer ! ( get the service name ) handle @ "service" getsock target ! handle @ "buffer" buffer @ setsock ( and hand it the string ) 0 target @ handle @ tostr queue ; PUBLIC sendsock : rpc ( ? ip port -- ? ) var port var ip var target var service toint port ! tostr ip ! ( translate IP to dbref ) ip @ ip2ref target ! ( translate port to service dbref ) port @ port2service service ! ( send and call rpc-event on this service ) target @ port @ service @ "rpc-event" call ; PUBLIC rpc : fpc ( ? func ip port -- ? ) var port var func var ip var target var service toint port ! tostr ip ! toint func ! ( translate IP to dbref ) ip @ ip2ref target ! ( translate port to service dbref ) port @ port2service service ! ( send and call a special function ) me @ target @ port @ func @ 0 = if service @ "rpc-event" call exit then func @ 1 = if target @ ok? exit then func @ 2 = if service @ "query-service" call exit then ; PUBLIC fpc : resolver ( s -- d ) var param param ! param @ ip2ref #-1 dbcmp if param @ "0.11.184" 53 rpc else param @ then ; PUBLIC resolver ( @set tcpip.muf.i386.so.1.0=L @set tcpip.muf.i386.so.1.0=W2 @set tcpip.muf.i386.so.1.0=/_defs/port2service:"$lib/tcpip" match "port2service" call @set tcpip.muf.i386.so.1.0=/_defs/porthandle:"$lib/tcpip" match "porthandle" call @set tcpip.muf.i386.so.1.0=/_defs/them:"$lib/tcpip" match "them" call @set tcpip.muf.i386.so.1.0=/_defs/client:"$lib/tcpip" match "client" call @set tcpip.muf.i386.so.1.0=/_defs/ip2ref:"$lib/tcpip" match "ip2ref" call @set tcpip.muf.i386.so.1.0=/_defs/ref2ip:"$lib/tcpip" match "ref2ip" call @set tcpip.muf.i386.so.1.0=/_defs/opensock:"$lib/tcpip" match "opensock" call @set tcpip.muf.i386.so.1.0=/_defs/closesock:"$lib/tcpip" match "closesock" call @set tcpip.muf.i386.so.1.0=/_defs/getsock:"$lib/tcpip" match "getsock" call @set tcpip.muf.i386.so.1.0=/_defs/setsock:"$lib/tcpip" match "setsock" call @set tcpip.muf.i386.so.1.0=/_defs/getlsock:"$lib/tcpip" match "getlsock" call @set tcpip.muf.i386.so.1.0=/_defs/setlsock:"$lib/tcpip" match "setlsock" call @set tcpip.muf.i386.so.1.0=/_defs/sendsock:"$lib/tcpip" match "sendsock" call @set tcpip.muf.i386.so.1.0=/_defs/resolver:"$lib/tcpip" match "resolver" call @set tcpip.muf.i386.so.1.0=/_defs/rpc:"$lib/tcpip" match "rpc" call @set tcpip.muf.i386.so.1.0=/_defs/fpc:"$lib/tcpip" match "fpc" call ) : main pop ; . c q @set tcpip.muf=L @set tcpip.muf=W2 @set tcpip.muf=/_defs/port2service:"$lib/tcpip" match "port2service" call @set tcpip.muf=/_defs/porthandle:"$lib/tcpip" match "porthandle" call @set tcpip.muf=/_defs/them:"$lib/tcpip" match "them" call @set tcpip.muf=/_defs/client:"$lib/tcpip" match "client" call @set tcpip.muf=/_defs/ip2ref:"$lib/tcpip" match "ip2ref" call @set tcpip.muf=/_defs/ref2ip:"$lib/tcpip" match "ref2ip" call @set tcpip.muf=/_defs/opensock:"$lib/tcpip" match "opensock" call @set tcpip.muf=/_defs/closesock:"$lib/tcpip" match "closesock" call @set tcpip.muf=/_defs/getsock:"$lib/tcpip" match "getsock" call @set tcpip.muf=/_defs/setsock:"$lib/tcpip" match "setsock" call @set tcpip.muf=/_defs/getlsock:"$lib/tcpip" match "getlsock" call @set tcpip.muf=/_defs/setlsock:"$lib/tcpip" match "setlsock" call @set tcpip.muf=/_defs/sendsock:"$lib/tcpip" match "sendsock" call @set tcpip.muf=/_defs/resolver:"$lib/tcpip" match "resolver" call @set tcpip.muf=/_defs/rpc:"$lib/tcpip" match "rpc" call @set tcpip.muf=/_defs/fpc:"$lib/tcpip" match "fpc" call