#include #include #include #include #include #include #include #include #include using namespace std; struct CLIENTDATA: public ARRAY_OBJ{ bool horizon; // This is connected to the horizon int copyto; // Copy to this handle bool waitok; CLIENTDATA(){ horizon = false; copyto = -1; waitok = true; } }; /* Execute a command but replace the #port# token by the port number */ static void proxyclient_exec (int argc, char *argv[], int port) { string tb[argc]; for (int i=0; i int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *port = "9000"; glocal const char *horizon = "192.168.2.1"; glocal const char *target = NULL; glocal const char *targetport = NULL; glocal.ret = (argc,argv); setproginfo ("proxyclient",VERSION ,"Allow a normal TCP base client to connect to the horizon\n" "using a proxyport\n" "\n" "proxyclient [ option ] command arg #PORT# ...\n"); setarg ('p',"port","Proxy port on the horizon",glocal.port,false); setarg ('h',"horizon","Ip of the horizon",glocal.horizon,false); setarg ('t',"target","Target name on the horizon",glocal.target,true); setarg ('P',"targetport","Target port on the horizon",glocal.targetport,true); glocal bool connected = false; (0,10); if (glocal.connected){ tlmp_error ("Multiple connection rejected\n"); endclient = true; }else{ glocal.connected = true; CLIENTDATA *d = new CLIENTDATA; d->horizon = false; info.data = d; setrawmode (true); int fd = cmdsock_connect (glocal.horizon,glocal.port,10,1); if (fd != -1){ SSTRING tmp; tmp.setfromf ("connect %s %s\n",glocal.target,glocal.targetport); write (fd,tmp.c_str(),tmp.getlen()); CLIENTDATA *dd = new CLIENTDATA; dd->horizon = true; dd->copyto = no; inject (fd,dd); d->copyto = fd; }else{ tlmp_error ("Can't connect to horizon %s on proxy port %s (%s)\n" ,glocal.horizon,glocal.port,strerror(errno)); endserver = true; } } endserver = true; CLIENTDATA *c = (CLIENTDATA*)info.data; // fprintf (stderr,"receive %d horizon=%d waitok=%d: %s\n",info.linelen,c->horizon,c->waitok,line); if (c->horizon){ if (c->waitok){ c->waitok = false; if (strcmp(line,"Ok")==0){ setrawmode (true); }else{ tlmp_error ("No Ok received from Horizon, ending\n"); endserver = true; } }else{ sendto (c->copyto,line,info.linelen); } }else{ sendto (c->copyto,line,info.linelen); } int port = o.getlistenport(); //printf ("port=%d\n",port); proxyclient_exec (argc,argv,port); o.loop(); return glocal.ret; return glocal.ret; }