Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bstd/easysock.hpp"
- #include <cstdio>
- #include <cstdlib>
- #include <thread>
- using namespace std;
- using namespace bstd;
- int main(int argc, char**argv)
- {
- if(argc != 3 && argc!=5)
- {
- printf("Usage: %s <Remote address> <Remote Port> [<listen port> <dest port>]\n",argv[0]);
- return 1;
- }
- if(argc ==3)
- {
- eclient rcv(7,atoi(argv[2]),argv[1]);
- rcv.Connect();
- while (true)
- {
- int port = *((int*)rcv.Read(4));
- printf("Port recieved! Number: %d\n",port);
- if(port==0)
- {
- printf("Nullport recieved, continuing\n");
- continue;
- }
- eclient lcl(4,port,"localhost");
- lcl.Connect();
- try{
- thread send([&](){while(true) rcv.Send(lcl.Read(1),1); });
- thread rec([&] (){while(true) lcl.Send(rcv.Read(1),1); });
- send.join();
- rec.join();
- }
- catch(int e){
- return 1;
- }
- }
- }
- if(argc==5)
- {
- eserver s(5,atoi(argv[3]));
- s.Listen();
- while (true)
- {
- printf("Waiting for connection...");
- int id = s.Accept();
- printf(" Connected!\n");
- if(!fork())
- {
- int rport = atoi(argv[4]);
- printf("Connecting to host %s with port %d and \nattempting to connect to %d on routed host...",argv[1],atoi(argv[2]),rport);
- eclient c(6,atoi(argv[2]),argv[1]);
- c.Connect();
- printf(" Connected!\nSending Port number...");
- c.Send((char*)&rport,4);
- printf(" sent %d\n",rport);
- printf("Attempting to route traffic...");
- thread send([&](){while(true) c.Send(s.Read(id,1),1);});
- thread recv([&](){while(true) s.Send(id,c.Read(1),1);});
- printf(" Threads started\n");
- send.join();
- recv.join();
- printf("Closing\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement