Advertisement
triclops200

F*ck

Sep 5th, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include "bstd/easysock.hpp"
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <thread>
  5. using namespace std;
  6. using namespace bstd;
  7. int main(int argc, char**argv)
  8. {
  9.     if(argc != 3 && argc!=5)
  10.     {  
  11.         printf("Usage: %s <Remote address> <Remote Port> [<listen port> <dest port>]\n",argv[0]);
  12.         return 1;
  13.     }  
  14.     if(argc ==3)
  15.     {  
  16.         eclient rcv(7,atoi(argv[2]),argv[1]);
  17.         rcv.Connect();
  18.         while (true)
  19.         {
  20.             int port = *((int*)rcv.Read(4));
  21.             printf("Port recieved! Number: %d\n",port);
  22.             if(port==0)
  23.             {
  24.                 printf("Nullport recieved, continuing\n");
  25.                 continue;
  26.             }
  27.                 eclient lcl(4,port,"localhost");
  28.                 lcl.Connect();
  29.                 try{
  30.                 thread send([&](){while(true) rcv.Send(lcl.Read(1),1); });
  31.                 thread rec([&] (){while(true) lcl.Send(rcv.Read(1),1); });
  32.                 send.join();
  33.                 rec.join();
  34.                 }
  35.                 catch(int e){
  36.                     return 1;
  37.                 }
  38.         }
  39.     }
  40.     if(argc==5)
  41.     {  
  42.         eserver s(5,atoi(argv[3]));
  43.         s.Listen();
  44.         while (true)
  45.         {
  46.             printf("Waiting for connection...");
  47.             int id = s.Accept();
  48.             printf(" Connected!\n");
  49.             if(!fork())
  50.             {
  51.                 int rport = atoi(argv[4]);
  52.                 printf("Connecting to host %s with port %d and \nattempting to connect to %d on routed host...",argv[1],atoi(argv[2]),rport);
  53.                 eclient c(6,atoi(argv[2]),argv[1]);
  54.                 c.Connect();
  55.                 printf(" Connected!\nSending Port number...");
  56.                 c.Send((char*)&rport,4);
  57.                 printf(" sent %d\n",rport);
  58.                 printf("Attempting to route traffic...");
  59.                 thread send([&](){while(true) c.Send(s.Read(id,1),1);});
  60.                 thread recv([&](){while(true) s.Send(id,c.Read(1),1);});
  61.  
  62.                 printf(" Threads started\n");
  63.                 send.join();
  64.                 recv.join();
  65.                 printf("Closing\n");
  66.  
  67.           }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement