Esempio n. 1
0
int exec_shell(int fd)
{
    printf("\n\n[i] Enjoy the real world.\n");
    forwarder(STDIN_FILENO,fd);
    close(fd);
    printf("Connection lost\n");
    return 0;
}
Esempio n. 2
0
int socks5_worker(void *fdptr)
{
    int fd = *(int *)fdptr;
    int srv_fd = init_connection(ip,port,2);
    if(srv_fd<0){
        printf("[E] init_connection failed\n");
        return -1;
    }
    forwarder(fd,srv_fd);
    close(fd);
    close(srv_fd);
    printf("Connection lost\n");
    return 0;
}
Esempio n. 3
0
void factor_vm::forward_object_xts()
{
	begin_scan();

	cell obj;

	while(to_boolean(obj = next_object()))
	{
		switch(tagged<object>(obj).type())
		{
		case WORD_TYPE:
			{
				word *w = untag<word>(obj);

				if(w->code)
					w->code = code->forward_code_block(w->code);
				if(w->profiling)
					w->profiling = code->forward_code_block(w->profiling);

				update_word_xt(obj);
			}
			break;
		case QUOTATION_TYPE:
			{
				quotation *quot = untag<quotation>(obj);

				if(quot->code)
				{
					quot->code = code->forward_code_block(quot->code);
					set_quot_xt(quot,quot->code);
				}
			}
			break;
		case CALLSTACK_TYPE:
			{
				callstack *stack = untag<callstack>(obj);
				callframe_forwarder forwarder(this);
				iterate_callstack_object(stack,forwarder);
			}
			break;
		default:
			break;
		}
	}

	end_scan();
}
int main(int argc, char *argv[])
{

  Aria::init();
  ArVideo::init();


  ArArgumentParser argParser(&argc, argv);

  ArServerBase server;
  ArServerSimpleOpener openServer(&argParser);

  argParser.loadDefaultArguments();
  if(!Aria::parseArgs() || !argParser.checkHelpAndWarnUnparsed()) {
    Aria::logOptions();
    Aria::exit(-1);
  }


  if(!openServer.open(&server))
  {
    std::cout << "error opening ArNetworking server" << std::endl;
    Aria::exit(5);
    return 5;
  }
  server.runAsync();
  std::cout << "ArNetworking server running on port " << server.getTcpPort() << std::endl;

  /* Set up ArNetworking services */

  ArVideoRemoteForwarder forwarder(&server, "localhost", 7070);
  if(!forwarder.connected())
  {
    std::cout << "ERror connecting to server localhost:7070" << std::endl;
    Aria::exit(1);
  }
  std::cout << "ArNetworking server running on port " << server.getTcpPort() << std::endl;
  
  while(true) ArUtil::sleep(10000);

  Aria::exit(0);
  return 0;
}
Esempio n. 5
0
void factor_vm::forward_object_xts()
{
	begin_scan();

	cell obj;

	while((obj = next_object()) != F)
	{
		switch(tagged<object>(obj).type())
		{
		case WORD_TYPE:
			{
				word *w = untag<word>(obj);

				if(w->code)
					w->code = forward_xt(w->code);
				if(w->profiling)
					w->profiling = forward_xt(w->profiling);
			}
			break;
		case QUOTATION_TYPE:
			{
				quotation *quot = untag<quotation>(obj);

				if(quot->code)
					quot->code = forward_xt(quot->code);
			}
			break;
		case CALLSTACK_TYPE:
			{
				callstack *stack = untag<callstack>(obj);
				xt_forwarder forwarder(this);
				iterate_callstack_object(stack,forwarder);
			}
			break;
		default:
			break;
		}
	}

	end_scan();
}
Esempio n. 6
0
int main(int argc, char **argv)
{
  ros::init(argc, argv, ROS_PACKAGE_NAME);
  ros::NodeHandle node;

  ros::Publisher cmd_pub = node.advertise<ackermann_msgs::AckermannDriveStamped>(
      "ackermann_cmd",
      1000
    );
  ros::Publisher cte_pub = node.advertise<std_msgs::Float64>(
      "cte",
      1000
    );
  aav_control::QuinticControl control(&cmd_pub, &cte_pub);
  /*
  ros::Subscriber sub = node.subscribe(
      "odometry/filtered",
      1000,
      &aav_control::QuinticControl::updateOdometry,
      &control
    );
  */
  aav_control::GazeboStateForwarder forwarder(control, "car");
  ros::Subscriber sub = node.subscribe(
      "/gazebo/model_states",
      1000,
      &aav_control::GazeboStateForwarder::forwardState,
      &forwarder
    );

  actionlib::SimpleActionServer<aav_msgs::DoQuinticPathAction> server(
      node,
      "control",
      boost::bind(&aav_control::QuinticControl::updateGoal, &control, _1),
      false
    );
  server.start();

  ros::spin();
  return 0;
}
Esempio n. 7
0
void factor_vm::forward_callback_xts()
{
	callback_forwarder forwarder(code,callbacks);
	callbacks->iterate(forwarder);
}
Esempio n. 8
0
void factor_vm::forward_context_xts()
{
	callframe_forwarder forwarder(this);
	iterate_active_frames(forwarder);
}
Esempio n. 9
0
// Compact data and code heaps
void factor_vm::collect_compact_impl() {
  gc_event* event = current_gc->event;

#ifdef FACTOR_DEBUG
  code->verify_all_blocks_set();
#endif

  if (event)
    event->reset_timer();

  tenured_space* tenured = data->tenured;
  mark_bits* data_forwarding_map = &tenured->state;
  mark_bits* code_forwarding_map = &code->allocator->state;

  // Figure out where blocks are going to go
  data_forwarding_map->compute_forwarding();
  code_forwarding_map->compute_forwarding();

  const object* data_finger = (object*)tenured->start;
  const code_block* code_finger = (code_block*)code->allocator->start;

  {
    compaction_fixup fixup(data_forwarding_map, code_forwarding_map, &data_finger,
                           &code_finger);
    slot_visitor<compaction_fixup> forwarder(this, fixup);

    forwarder.visit_uninitialized_code_blocks();

    // Object start offsets get recomputed by the object_compaction_updater
    data->tenured->starts.clear_object_start_offsets();

    // Slide everything in tenured space up, and update data and code heap
    // pointers inside objects.
    auto compact_object_func = [&](object* old_addr, object* new_addr, cell size) {
      forwarder.visit_slots(new_addr);
      forwarder.visit_object_code_block(new_addr);
      tenured->starts.record_object_start_offset(new_addr);
    };
    tenured->compact(compact_object_func, fixup, &data_finger);

    // Slide everything in the code heap up, and update data and code heap
    // pointers inside code blocks.
    auto compact_code_func = [&](code_block* old_addr,
                                 code_block* new_addr,
                                 cell size) {
      forwarder.visit_code_block_objects(new_addr);
      cell old_entry_point = old_addr->entry_point();
      forwarder.visit_instruction_operands(new_addr, old_entry_point);
    };
    code->allocator->compact(compact_code_func, fixup, &code_finger);

    forwarder.visit_all_roots();
    forwarder.visit_context_code_blocks();
  }

  update_code_roots_for_compaction();

  // Each callback has a relocation with a pointer to a code block in
  // the code heap. Since the code heap has now been compacted, those
  // pointers are invalid and we need to update them.
  auto callback_updater = [&](code_block* stub, cell size) {
    callbacks->update(stub);
  };
  callbacks->allocator->iterate(callback_updater);

  code->initialize_all_blocks_set();

  if (event)
    event->ended_compaction();
}
Esempio n. 10
0
int worker(int csock)
{
    char buffer[BUFSIZ+1];
    bzero(&buffer, sizeof buffer);
    int rec,sen;
    /*****Select******/
    printf("Recving select message...\n");
    if((rec = mrecv(csock, buffer, sizeof(SELECT)))<=0){
        close(csock);
        return -1;
    }
    printf("Recved.\n");
    pSELECT select = (pSELECT)&buffer;
    //Do something like checking if the version is 5
    pSELECT_RESPONSE selectRes = (pSELECT_RESPONSE)malloc(sizeof(SELECT_RESPONSE));
    selectRes->ver=0x5; //Socks Version 5
    selectRes->method=0x0;  //NO AUTHENTICATION REQUIRED
    if(select->ver!=0x5){
        selectRes->method=0xFF;
    }
    sen = msend(csock, selectRes, sizeof(SELECT_RESPONSE));
    printf("Select done,rec/send:%d/%d\n",rec,sen);
    free(selectRes);

    /*****Request******/
    printf("Recving request...\n");
    rec = recv(csock, buffer, BUFSIZ,0);
    printf("Recved %d bytes\n",rec);
    pREQUEST request = (pREQUEST)&buffer;

    //Parse the target addr
    struct sockaddr_in taddr;
    taddr.sin_family = AF_INET;
    if(request->atyp==0x3){     //Domain name
        //char domainlen=*(&request->atyp+sizeof(request->atyp));
        char domainlen=*(&request->addr);
        char domain[256]={0};
        strncpy(domain,&request->atyp+2,(unsigned int)domainlen);
        struct hostent *phost = gethostbyname(domain);
        if(phost==NULL){
            printf("Cannot Resolv the Domain name:%s\n",(char *)&domain);
            close(csock);
            return -1;
        }
        memcpy(&taddr.sin_addr,phost->h_addr_list[0],phost->h_length);
        memcpy(&taddr.sin_port,&request->atyp+sizeof(request->atyp)+1+(unsigned int)domainlen,2);
    }
    else if(request->atyp==0x1){    //IPv4 Addr
        memcpy(&taddr.sin_addr.s_addr,&request->atyp+1,4);
        memcpy(&taddr.sin_port,&request->atyp+1+4,2);
    }
    else{
        printf("Not implemented\n");
        close(csock);
        return -1;
    }
    //Connect to the target host
    pREQUEST_RESPONSE requestRes = (pREQUEST_RESPONSE)malloc(sizeof(REQUEST_RESPONSE));
    requestRes->ver=0x5;
    requestRes->rep=0x0;
    requestRes->rsv=0x0;
    requestRes->atyp=0x1;
    memset(requestRes+4, 0, 6);
    /*
    if(request->cmd=0x03){
        uint32_t tmpaddr = htonl("127.0.0.1");
        uint16_t tmpport = htons(8081);
        memcpy(requestRes+4,&tmpaddr,sizeof(uint32_t)); //XXX   wtf?
        memcpy(requestRes+8,&tmpport,sizeof(uint16_t));
    }
    */

    printf("Connecting to  port %d on %s\n",ntohs(taddr.sin_port),inet_ntoa(taddr.sin_addr));
    int tsock;
    //Check its a tcp or udp request
    if(request->cmd==0x04){ //UDP ASSOCIATE X'03' //Never use udp
        printf("Hey, its a udp request!\n");
        tsock = socket(AF_INET, SOCK_DGRAM, 0);
    }   
    else{
        tsock=socket(AF_INET, SOCK_STREAM, 0);
    }

    if(connect(tsock, (struct sockaddr *) &taddr, sizeof(taddr))==-1){
        requestRes->rep=0x5;
        sen = msend(csock, requestRes, sizeof(REQUEST_RESPONSE));
        close(csock);
        return -1;
    }
    printf("Done\n");
    sen = msend(csock, requestRes, sizeof(REQUEST_RESPONSE));
    printf("Request done,rec/send:%d/%d\n",rec,sen);
    free(requestRes);

    if(request->cmd==0x03){ //UDP ASSOCIATE
        printf("Recving... #1\n");

        rec = recv(csock, buffer, BUFSIZ,0);
        /*
            struct sockaddr_in tmpaddr;
            tmpaddr.sin_family = AF_INET;
                memcpy(&tmpaddr.sin_addr.s_addr,buffer+4,4); //XXX
        memcpy(&tmpaddr.sin_port,buffer+4+4,2);
        printf("Recv Ascii:%s:%d\n",inet_ntoa(tmpaddr.sin_addr),ntohs(tmpaddr.sin_port));
        */
        printf("Done:%d\nSending... #1\n",rec);
        sen = send(tsock, buffer, rec,0);
        printf("Done:%d\nRecving... #2\n",sen);
        rec = recv(tsock, buffer, BUFSIZ,0);
        printf("Done:%d\nSending... #2\n",rec);
        sen = send(csock, buffer, rec,0);
        printf("Done:%d",sen);
        return 0;
    }

    /*****Forward******/
    forwarder(csock,tsock);
    printf("worker exit");
    close(csock);
    close(tsock);
    return 0;
}
Esempio n. 11
0
int main(int argc, char* argv[])
{
    int oc;

    /*To parse the options. The options from command line will 
      overwrite those in configuration file(because -c <config_file> 
      is the first option)
    */
//   while( ( oc=getopt(argc, argv, "b:dg:hi:l:L:n:op:s:t:")) != -1 )

    while( ( oc=getopt(argc, argv, "c:dhl:p:")) != -1 )
    {
        switch (oc)
        {
            case 'c': 
                config_file=strdup(optarg);
                config.file_config = config_file;
                break;
            /*
            case 'b':  // blacklist file
                config.file_blacklist=strdup(optarg);   
                break;
            */
            case 'd': //daemonize 
                config.daemonize=TRUE;
                break;
            case 'h':
                usage(argv[0]);
                break; 
            /*
            case 'i':  //IP address file used by censors
                config.file_badip = strdup(optarg);
                break;
            */
            case 'l': //log file
                config.file_log = strdup(optarg);
                break;
            case 'p': //pid file
                config.file_pid = strdup(optarg);
                break;
            default:
                usage(argv[0]);
                break; 
        }// switch(oc)
    }//end of while (parse the options)

    if(config.file_config == NULL)
    {
        config.file_config = DEFAULT_CONFIG;
    }
    if( load_config(config.file_config, &config)<0 ) //The values can be overwrite by the following options
    {
        fprintf(stderr, "ERROR: unable to load configuration file: %s.\n", config.file_config);
        exit(-1);
    }

    if(config.daemonize) 
        daemonize_init();

    /*set default log level to ERROR(2) */
    log_level= (config.log_level == 0? LOG_ERROR: config.log_level);
/*
    if (config.open_resolver == NULL ) config.open_resolver = "8.8.8.8";
    if (config.open_resolver_port == 0 ) config.open_resolver_port = 53;
    if (config.local_resolver == NULL ) config.open_resolver = "127.0.0.1";
    if (config.local_resolver_port == 0 ) config.local_resolver_port = 53;
*/

    if( config.file_log == NULL)
    {
        fd_log = stderr;
    }
    else
    {
        fd_log = fopen(config.file_log, "a");
        if( fd_log ==NULL) 
        {
            fprintf(stderr, "ERROR: unable to open log file: %s to write(append).\n", config.file_log);
            exit(-1);
        }
    }   

    if(config.file_pid != NULL)
    {
        FILE * pid_fd=fopen(config.file_pid,"w"); // open again  
        if (pid_fd == NULL) 
        {
            my_log(LOG_ERROR, "E: Unable to open pid_file:%s to write\n", config.file_pid); 
            exit(-1);
        }
        fprintf(pid_fd, "%d" , getpid());
        fclose(pid_fd);
    }

    blacklist = blacklist_load(config.file_blacklist, 1);
    if( blacklist == NULL) 
    {
        my_log(LOG_ERROR, "E: unable to load Blacklist %s.\n", config.file_blacklist);
        exit(-1); 
    }
    //blacklist_dump(blacklist, config.file_blacklist);
    //printf("OK\n");
    //blacklist_release(blacklist);
    //exit(0);
    

    badip=badip_load(config.file_badip); 
    if(badip== NULL)
    {
        my_log(LOG_ERROR, "E: unable to load bad IP address %s.\n", config.file_badip);
        exit(-1); 
    }

    if( measure_ttl(OPEN_RESOLVER,  config.open_resolver, 
            config.open_resolver_port, "www.mit.edu", &goodTTL[OPEN_RESOLVER]) <0)
    {
        my_log(LOG_ERROR, "E: open_resolver test failed: %s\n", config.open_resolver);
        exit(-1);
    }
    if( measure_ttl(LOCAL_RESOLVER,  config.local_resolver,
            config.local_resolver_port,"www.mit.edu", &goodTTL[LOCAL_RESOLVER]) <0)
    {
        my_log(LOG_ERROR, "E: local_resolver test failed: %s\n", config.local_resolver);
        exit(-1);
    }

    my_log(LOG_MEASURE, "M: M_TTL: %d %d\n", goodTTL[OPEN_RESOLVER], goodTTL[LOCAL_RESOLVER]);

    pthread_t tid_measure_handler;
    int rcode=pthread_create(&tid_measure_handler,NULL, measure_handler, NULL );
    if( rcode !=0)
    {
        my_log(LOG_ERROR, "E: Cannot create thread for tcp_request_handler:rcode=%d in %s(%d).\n",
                rcode, __FILE__, __LINE__);
        exit(-1);
    }

    forwarder(config.service_port, config.open_resolver, config.open_resolver_port,
                    config.local_resolver, config.local_resolver_port, 1);

    //set_resolver_to_me()
    //create_report_service() 
   pthread_join( tid_measure_handler, NULL) ;
    return 0;
}
Esempio n. 12
0
File: main.cpp Progetto: CCJY/coliru
void apply_item(F func, cons<E>, cons<NextSet> ns, cons<Sets>... tail) {
    Forwarder<F, E> forwarder(func);
    
    apply_set(forwarder, ns, tail...);
}