예제 #1
0
파일: pmda.c 프로젝트: Aconex/pcp
void 
darwin_init(pmdaInterface *dp)
{
    if (_isDSO) {
	int sep = __pmPathSeparator();
	char helppath[MAXPATHLEN];
	sprintf(helppath, "%s%c" "darwin" "%c" "help",
		pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
	pmdaDSO(dp, PMDA_INTERFACE_3, "darwin DSO", helppath);
    } else {
	__pmSetProcessIdentity(username);
    }

    if (dp->status != 0)
	return;

    dp->version.two.instance = darwin_instance;
    dp->version.two.fetch = darwin_fetch;
    pmdaSetFetchCallBack(dp, darwin_fetchCallBack);

    pmdaSetFlags(dp, PMDA_EXT_FLAG_DIRECT);
    pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]),
		metrictab, sizeof(metrictab)/sizeof(metrictab[0]));

    mach_host = mach_host_self();
    host_page_size(mach_host, &mach_page_size);
    mach_page_shift = ffs(mach_page_size) - 1;
    if (refresh_hertz(&mach_hertz) != 0)
	mach_hertz = 100;
    init_network();
}
예제 #2
0
int init_netpaint(char* ip, char* port)
{

	repaint_context_t *repaint_context = init_repaint_context();
	int sfd;
	if((sfd = init_network(ip, atoi(port))) < 0)
	{
		printf("ERROR! Could not initialize network!\n");
		return -1;
	}
	if(ready_read(sfd, repaint_context) < 0)
	{
		printf("ERROR! Could not get the first canvas!\n");
		return -1;
	}
	repaint_context->canvas = repaint_context->canvases[0];
	repaint_context->sfd = sfd;
		
	tool_contexts_t *tool_contexts = init_tool_contexts(repaint_context);

	event_loop(sfd, repaint_context, tool_contexts);

	XCloseDisplay(repaint_context->display);
	(void) ip;
	(void) port;
	return 0;
}
예제 #3
0
static void init(void) 
{
  APP_LOG(APP_LOG_LEVEL_DEBUG, "init started");

  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  weather_data = malloc(sizeof(WeatherData));
  init_network(weather_data);

  // Setup our layers
  time_layer_create(TIME_FRAME, window);
  date_layer_create(DATE_FRAME, window);
  weather_layer_create(WEATHER_FRAME, window);
  debug_layer_create(DEBUG_FRAME, window);
  battery_layer_create(BATTERY_FRAME, window);

  load_persisted_values(weather_data);

  // Kickoff our weather loading 'dot' animation
  weather_animate(weather_data);

  // Setup a timer incase we miss or don't receive js_ready to manually try ourselves
  initial_jsready_timer = app_timer_register(MAX_JS_READY_WAIT, initial_jsready_callback, NULL);

  // Update the screen right away
  time_t now = time(NULL);
  handle_tick(localtime(&now), MINUTE_UNIT | DAY_UNIT );

  // And then every minute
  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
}
예제 #4
0
int 
main(int argc, char **argv)
{    
    int loop_number = 0; 

    startup_win_network();

    parse_parameters(argc, argv);

    init_network();

    signal(SIGINT, sig_handler);

    if (!quiet)
    {
        fprintf(stderr, "listening on port %d for packets .... \n", port_num);
        if (continuous)
            fprintf(stderr, "looping tests.\n");
        fprintf(stderr, "\n");
    }

    fprintf(stdout, "# run no., loss rate in %%, packets_sent, packets_received, payload_size\n");
    do
    {
        loop_number++;
        fprintf(stdout, "%2d.   ", loop_number);
        run_server();
    }
    while (continuous);

    return 1;
}
예제 #5
0
BCubeTopology::BCubeTopology(Logfile* lg, EventList* ev,FirstFit * fit) {
    logfile = lg;
    eventlist = ev;
    ff = fit;

    init_network();
}
예제 #6
0
파일: s5.c 프로젝트: odzhan/shells
int main (int argc, char *argv[])
{
  args_t args;

  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  
  memset (&args, 0, sizeof(args));
  
  // set default parameters
  args.address   = NULL;
  args.ai_family = AF_INET;
  args.port_nbr  = DEFAULT_PORT;
  
  printf ("\n[ server for PIC client v0.1\n");
  
  parse_args(&args, argc, argv);
  
  if (init_network(&args))
  {
    server(&args);
    shutdown (args.s, SHUT_RDWR);
    closesocket(args.s);
  }
  return 0;
}
예제 #7
0
void init (int argc,char *argv[])
{
    struct lac *lac;
    init_args (argc,argv);
    rand_source = 0;
    init_addr ();
    if (init_config ())
    {
        log (LOG_CRIT, "%s: Unable to load config file\n", __FUNCTION__);
        exit (1);
    }
    if (uname (&uts))
    {
        log (LOG_CRIT, "%s : Unable to determine host system\n",
             __FUNCTION__);
        exit (1);
    }
    init_tunnel_list (&tunnels);
    if (init_network ())
        exit (1);
    if (gconfig.daemon)
	daemonize ();
    signal (SIGTERM, &death_handler);
    signal (SIGINT, &death_handler);
    signal (SIGCHLD, &child_handler);
    signal (SIGUSR1, &status_handler);
    signal (SIGHUP, &null_handler);
    init_scheduler ();
    mkfifo (CONTROL_PIPE, 0600);
    control_fd = open (CONTROL_PIPE, O_RDONLY | O_NONBLOCK, 0600);
    if (control_fd < 0)
    {
        log (LOG_CRIT, "%s: Unable to open " CONTROL_PIPE " for reading.",
             __FUNCTION__);
        exit (1);
    }
    log (LOG_LOG, "l2tpd version " SERVER_VERSION " started on %s PID:%d\n",
         hostname, getpid ());
    log (LOG_LOG,
         "Written by Mark Spencer, Copyright (C) 1998, Adtran, Inc.\n");
    log (LOG_LOG, "Forked by Scott Balmos and David Stipp, (C) 2001\n");
    log (LOG_LOG, "Inhereted by Jeff McAdams, (C) 2002\n");
    log (LOG_LOG, "%s version %s on a %s, port %d\n", uts.sysname,
         uts.release, uts.machine, gconfig.port);
    lac = laclist;
    while (lac)
    {
        if (lac->autodial)
        {
#ifdef DEBUG_MAGIC
            log (LOG_DEBUG, "%s: Autodialing '%s'\n", __FUNCTION__,
                 lac->entname[0] ? lac->entname : "(unnamed)");
#endif
            lac->active = -1;
            switch_io = 1;      /* If we're a LAC, autodials will be ICRQ's */
            magic_lac_dial (lac);
        }
        lac = lac->next;
    }
}
예제 #8
0
int start_connect(void)
{
	struct user_data client;
	socklen_t len;
	int result = init_sqlite3_db();				// 初始化数据库
	if (result != LINKC_SUCCESS)
	{
		printf ("DB Init error!\n");
		exit(EXIT_FAILURE);
	}
	int sockfd = init_network(PORT);				// 初始化网络模块
	if (sockfd == -1)
	{
		printf ("network_init error!\n");
		exit(EXIT_FAILURE);
	}
	len = sizeof (client.addr);
	pthread_t pid;
	while (1)
	{
#if DEBUG
		sleep (1);
		printf ("Server is waiting for connect!\n");
#endif
		client.sockfd = accept (sockfd,(struct sockaddr *)&client.addr,(socklen_t *)&len);

		pthread_create (&pid,NULL,(void*)*keep_connect,&(client));
	}
}
예제 #9
0
static void init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  weather_data = malloc(sizeof(WeatherData));
  init_network(weather_data);

  font_date = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_18));
  font_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53));

  time_layer = text_layer_create(TIME_FRAME);
  text_layer_set_text_color(time_layer, GColorWhite);
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_font(time_layer, font_time);
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));

  date_layer = text_layer_create(DATE_FRAME);
  text_layer_set_text_color(date_layer, GColorWhite);
  text_layer_set_background_color(date_layer, GColorClear);
  text_layer_set_font(date_layer, font_date);
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));

  // Add weather layer
  weather_layer = weather_layer_create(GRect(0, 90, 144, 80));
  layer_add_child(window_get_root_layer(window), weather_layer);

  // Update the screen right away
  time_t now = time(NULL);
  handle_tick(localtime(&now), SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT );
  // And then every second
  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);
}
예제 #10
0
파일: netserver.cpp 프로젝트: tmud/libs
 bool init()
 {
     if (initialized)
         return true;
     initialized = init_network();
     return initialized;
 }
예제 #11
0
CollabSocket::CollabSocket(Dispatcher disp) {
   _disp = disp;
   thread = 0;
   init_network();
   conn = (_SOCKET)INVALID_SOCKET;
   connected = false;
   drt = new disp_request_t(_disp);
}
예제 #12
0
StarTopology::StarTopology(Logfile* lg, EventList* ev,FirstFit * fit) {
    logfile = lg;
    eventlist = ev;
    ff = fit;

    N = NSRV;

    init_network();
}
예제 #13
0
/*
 * Initialize variables.
 */
void
tninit(void)
{
    init_terminal();

    init_network();

    init_telnet();

    init_sys();
}
예제 #14
0
void test1() {
  std::cout << "socketHandlerTest test 1" << std::endl;
  int sockfd;

  init_network(sockfd);
  if (fork() == 0) {
    // child process
    sleep(1);
    client();
  } else {
    server(sockfd);
  }
}
예제 #15
0
int
main (int argc, char *argv[])
{
  global_option_type global_option;	//!< Application global options

  global_option.server_port = DEFAULT_SERVER_PORT;
  global_option.number_player = MAX_NUMBER_PLAYER;
  global_option.type_server = LAN_PROTOCOL_TYPE;

#if defined(DEBUG)
  fprintf (stderr, "DEBUG mode is ON\n");
#endif

  if (read_arguments (argc, argv, &global_option) != 0)
    {
      fprintf (stderr, "Error reading arguments\n");
      return 2;
    }

  if (SDL_Init (0) == -1)
    {
      fprintf (stderr, "SDL_Init: %s\n", SDL_GetError ());
      return 1;
    }

  if (init_network () != 0)
    {
      fprintf (stderr, "Error initializing network\n");
      return 1;
    }

#if defined(GTK)

	if (argc == 1)
	{
		// No option given starts the GUI
		build_gtk_interface(argc, argv);
		return;
	}

#endif
  
  serve_dispatch (&global_option);

  shutdown_network ();

  SDL_Quit();

  return 0;
  
}
예제 #16
0
int main()
{
	int ret=init_network();
	if( ret!=0 )
	{
		LLOG(L_ERROR, "init_network error. ");
		return -1;
	}
	
	Spider_Config::instance().load();
	Spider_Seed spider_seed;
	if( 0!=spider_seed.load() )
	{
		return -1;
	}
	
	Spider_Cookie::instance().login();
	Spider_Storage::instance().initialize();
	Spider_Executor::instance().initialize();
	Spider_Url_Rinse::instance().initialize();

	while(true)
	{
		Seed* seed=NULL;
		std::string site_name;
		spider_seed.get_seed(site_name,&seed);
		if ( seed!=NULL )
		{
            LLOG(L_DEBUG, "load seed %s", site_name.c_str());
			Spider_WebSite* website=Spider_WebSite_Factory::create_website(site_name);
			website->initialize(site_name.c_str(), seed);
			website->begin_process();  //处理seed节点
		}
		else
		{
			LLOG(L_DEBUG, "load all seed.");
			break;
		}
		Sleep(1000); //1s
	}
	
	Spider_Executor::instance().execute_loop(); //循环等待完成
	
	Spider_Url_Rinse::instance().uninitialize();
	Spider_Executor::instance().uninitialize();
	Spider_Storage::instance().uninitialize();
	uninit_network();
	return 0;
};
예제 #17
0
/*
 * Initialize variables.
 */
    void
tninit()
{
    init_terminal();

    init_network();

    init_telnet();

    init_sys();

#if defined(TN3270)
    init_3270();
#endif
}
예제 #18
0
파일: main.c 프로젝트: ryo/netbsd-src
/*
 * Initialize variables.
 */
void
tninit(void)
{
    init_terminal();

    init_network();

    init_telnet();

    init_sys();

#ifdef TN3270
    init_3270();
#endif
}
예제 #19
0
파일: ospfd.c 프로젝트: hgn/ospfd
int main(int ac, char **av)
{
	int ret;
	struct ospfd *ospfd;
	int ev_flags = 0;

	ospfd = alloc_ospfd();

	ret = parse_cli_options(ospfd, ac, av);
	if (ret != SUCCESS)
		err_msg_die(EXIT_FAILURE, "Can't parse command line");

	msg(ospfd, GENTLE, PROGRAMNAME " - " VERSIONSTRING);

	/* seed pseudo number randon generator */
	init_pnrg(ospfd);

	/* initialize event subsystem. In this case this belongs
	 * to open a epoll filedescriptor */
	ospfd->ev = ev_new();
	if (!ospfd->ev)
		err_msg_die(EXIT_FAILURE, "Can't initialize event subsystem");


	ret = parse_rc_file(ospfd);
	if (ret != SUCCESS)
		err_msg_die(EXIT_FAILURE, "Can't parse configuration file");


	ret = init_network(ospfd);
	if (ret != SUCCESS)
		err_msg_die(EXIT_FAILURE, "Can't initialize network subsystem");

	/* and branch into the main loop
	 * This loop will never return (with the exception of SIGINT or failure
	 * condition) */
	ret = ev_loop(ospfd->ev, ev_flags);
	if (ret != SUCCESS)
		err_msg_die(EXIT_FAILURE, "Main loop returned unexpected - exiting now");


	fini_network(ospfd);
	free_options(ospfd);
	ev_free(ospfd->ev);
	free_ospfd(ospfd);

	return EXIT_SUCCESS;
}
예제 #20
0
/*
 * Open and configure the specified interface with the provided info.
 */
int
start_conf_network_eifstart(int ifn, const char *eif_addr, const char *eif_mask)
{
	const char *eif_name;
	int nif, err;

	if (eif_addr == 0 || eif_mask == 0)
		return OSKIT_EINVAL;

	nif = init_network();
	if (ifn >= nif)
		return OSKIT_EINVAL;

	eif_name = start_conf_network_eifname(ifn);
	if (eif_name == 0)
		return OSKIT_EINVAL;

#if VERBOSITY > 1
	printf("Configuring ether dev %d as %s\n", ifn, eif_name);
#endif
		
	/*
	 * Open the underlying ether device and configure it.
	 */
#if VERBOSITY > 2
	printf("  open %s\n", eif_name);
#endif
	err = start_conf_network_open_eif(edev[ifn], &eif[ifn]);
	if (err == 0) {
#if VERBOSITY > 2
		printf("  ifconfig %s as %s (mask %s)\n",
		       eif_name, eif_addr, eif_mask);
#endif
		err = start_conf_network_eifconfig(eif[ifn], eif_name,
						   eif_addr, eif_mask);
	}

#if VERBOSITY > 2
	if (err != 0)
		printf("  start_conf_network_single(%d) FAILED (err=%x)\n",
		       ifn, err);
#endif

	return err;
}
예제 #21
0
KPROXY_API f8_bool kproxy_init(int leakDetect)
{
	ITcpAdapter *a;	

	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(leakDetect);
	
	/* initialize and start kernel */
	ex_init();
	
	/* KERN_F_ENABLE_INPUT */

	x_buffer = (char *)__malloc__(LARGE_BUF_SIZE);
	x_buf_len = LARGE_BUF_SIZE;
	b_ShellExit = __false;	

	__new__(ITcpAdapter, a);
	proxy_adapter = __ucast__(ITcpAdapter, IKAdapter, a);

	sections = ke_get_blk(proxy_adapter->kernel, 0);
	assert(sections->uuid == BLK_ID_ROOT);

	create_resource(&sections->uuid);
	create_f8_uuid(&sections->h.uuid);
	create_resource(&sections->h.uuid);

	memset(fileName, 0 , sizeof(fileName));

	g_shell = shell_create(commands);
	
	reset_reg_map();
	init_blklib();
	init_clipboard();

	g_bDirty = __false;


	init_network(RTK_INIT_AS_SERVER, 0);
	vbus = connect_vbus(0xf8, VBUS_CONNECT_AS_SERVER, sr, 0);
	
	return __true;
}
예제 #22
0
/**
 * @brief Initialize everything.
 *
 * @param stop_early 0: do some initialization, 1: no initialization.
 */
static int
init_openvassd (struct arglist *options, int first_pass, int stop_early,
                int dont_fork)
{
  int isck = -1;
  struct arglist *preferences = NULL;
  int scanner_port = GPOINTER_TO_SIZE (arg_get_value (options, "scanner_port"));
  char *config_file = arg_get_value (options, "config_file");
  struct addrinfo *addr = arg_get_value (options, "addr");

  preferences_init (config_file, &preferences);

  log_init (arg_get_value (preferences, "logfile"));
  if (dont_fork == FALSE)
    setup_legacy_log_handler (log_vwrite);

  if (!stop_early)
    {
      if (first_pass != 0)
        init_network (scanner_port, &isck, *addr);
    }

  if (first_pass && !stop_early)
    {
      openvas_signal (SIGSEGV, sighandler);
      openvas_signal (SIGCHLD, sighand_chld);
      openvas_signal (SIGTERM, sighandler);
      openvas_signal (SIGINT, sighandler);
      openvas_signal (SIGHUP, sighup);
      openvas_signal (SIGUSR1, sighandler);     /* openvassd dies, not its sons */
      openvas_signal (SIGPIPE, SIG_IGN);
    }

  arg_replace_value (options, "isck", ARG_INT, sizeof (gpointer),
                     GSIZE_TO_POINTER (isck));
  arg_replace_value (options, "preferences", ARG_ARGLIST, -1, preferences);
  set_globals_from_preferences (preferences);

  return 0;
}
예제 #23
0
파일: lrpc_main.c 프로젝트: longzhiri/lrpc
int main(int argc, char *argv[])
{
    L = luaL_newstate();
    luaL_openlibs(L);

    const char *cfg_file_name = "config.cfg";
    if (argc > 1)
        cfg_file_name = argv[1];
    if (read_config(L, cfg_file_name) != 0) {
        fprintf(stderr, "config read failed %s", lua_tostring(L, -1));
        return -1;
    }

    EV_Base = event_base_new();
    init_network(L, EV_Base);
    preload(L);
    load_service(L);

    event_base_dispatch(EV_Base);
    lua_close(L);
    return 0;
}
예제 #24
0
파일: main.cpp 프로젝트: lufb/code
int
main(void)
{
	int					err;

	init_network();
	if((err = g_log.initLog("./", true, "cp2msg", "log")) != 0){
		printf("启动日志模块失败,程序终止\n");
		return err;
	}
	g_log.writeLog(LOG_TYPE_INFO, "日志模块启动成功");

	if((err = start_srv_mode()) != 0){
		g_log.writeLog(LOG_TYPE_ERROR,
			"启动srv模块失败[%u:%u]",
			GET_SYS_ERR(err), GET_USER_ERR(err));
		return err;
	}
	g_log.writeLog(LOG_TYPE_INFO, "启动srv模块成功");

	if((err = start_deliver_mode()) != 0){
		g_log.writeLog(LOG_TYPE_ERROR,
			"启动DELIVER模块失败[%u:%u]",
			GET_SYS_ERR(err), GET_USER_ERR(err));
		return err;
	}
	g_log.writeLog(LOG_TYPE_INFO, "启动DELIVER模块成功");

	/* 在主线程中敲任意键,发Deliver */
	while((err = getc(stdin)) != EOF){
		if(g_cli_queue.GetRandSock(err) == true)
			if(g_deliver_que.Insert(0, NULL, err) != true)
				assert(0);
	}

	return 0;
}
예제 #25
0
파일: system.c 프로젝트: gravufo/INF3995
void system_init_network(void)
{
	// Structure pour l'adresse MAC du système

	unsigned char mac_address[6] = {0x00, 0x18, 0x3e, 0x00, 0x00, 0x54};
	u8 ip_adr[4] = {132, 207, 89, 54}; // Structure pour l'adresse IP local
	u8 subnet_mask[4] = {255, 255, 255, 0}; // Structure pour le masque de sous-réseau
	u8 gateway[4] = {132, 207, 89, 1}; // Structure pour l'adresse de la passerelle par default


 	/*xil_printf("Démarrage du client avec les adresse :\n");
	xil_printf("Adresse local : %d.%d.%d.%d\n", ip_adr[0], ip_adr[1],
			   ip_adr[2], ip_adr[3]);
	xil_printf("Masque de sous-réseau employé : %d.%d.%d.%d\n", subnet_mask[0],
			   subnet_mask[1], subnet_mask[2], subnet_mask[3]);
	xil_printf("Passerelle employé : %d.%d.%d.%d\n", gateway[0], gateway[1],
			   gateway[2], gateway[3]);*/

 	netif = &allocated_netif;
 	init_network(netif, mac_address, ip_adr, subnet_mask, gateway);
 	enable_network(netif);

 	connection_init();
}
예제 #26
0
void init (int argc,char *argv[])
{
    struct lac *lac;
    struct in_addr listenaddr;
    int myRet=0;

    init_args (argc,argv);
    srand( time(NULL) );
    rand_source = 0;
    init_addr ();
    if (init_config ())
    {
        log (LOG_CRIT, "%s: Unable to load config file\n", __FUNCTION__);
        exit (1);
    }
    init_tunnel_list (&tunnels);
    if (init_network ())
        exit (1);
    //if (gconfig.daemon)
	//daemonize ();
    signal (SIGTERM, &death_handler);
    signal (SIGINT, &death_handler);
    signal (SIGCHLD, &child_handler);
    signal (SIGUSR1, &status_handler);
    signal (SIGHUP, &null_handler);
    init_scheduler ();

    unlink (gconfig.controlfile);
    myRet=mkfifo (gconfig.controlfile, 0600);
//    log (LOG_LOG,"gconfig.controlfile=%s, myRet=%d,errno=%d",gconfig.controlfile,myRet,errno);//Added for test
    if(myRet<0)
    {
    	 log (LOG_CRIT, "%s: Unable to mkfifo %s.",__FUNCTION__, gconfig.controlfile);
        exit (1);
    }
    control_fd = open (gconfig.controlfile, O_RDONLY | O_NONBLOCK, 0600);
    if (control_fd < 0)
    {
        log (LOG_CRIT, "%s: Unable to open %s for reading.",
             __FUNCTION__, gconfig.controlfile);
        exit (1);
    }
    log (LOG_LOG, "l2tpd version " SERVER_VERSION " started on %s PID:%d\n",
         hostname, getpid ());
    log (LOG_LOG,
         "Written by Mark Spencer, Copyright (C) 1998, Adtran, Inc.\n");
    log (LOG_LOG, "Forked by Scott Balmos and David Stipp, (C) 2001\n");
    log (LOG_LOG, "Inherited by Jeff McAdams, (C) 2002\n");
    listenaddr.s_addr = gconfig.listenaddr;
    log (LOG_LOG, "Listening on IP address %s, port %d\n",
	 inet_ntoa(listenaddr), gconfig.port);
    lac = laclist;
    while (lac)
    {
        if (lac->autodial)
        {
#ifdef DEBUG_MAGIC
            log (LOG_DEBUG, "%s: Autodialing '%s'\n", __FUNCTION__,
                 lac->entname[0] ? lac->entname : "(unnamed)");
#endif
            lac->active = -1;
            switch_io = 1;      /* If we're a LAC, autodials will be ICRQ's */
            magic_lac_dial (lac);
        }
        lac = lac->next;
    }
}
예제 #27
0
PROXY_API __bool PMC_API init_proxy(HWND hWnd, __uint flags)
{
	char * szWarning = "没有找到软件狗,进入演示状态,数据库最大规模32点";

	if(!_g_InitLock){
		_g_InitLock = new CLock;
	}
	
	g_InitLock.Lock();
	if(g_iInitCount){
		g_iInitCount++;
		g_InitLock.UnLock();
		return __true;
	}

	g_iInitCount++;

	g_iInitFlag = flags;
	
	_load_settings(__false);
	
	g_DBDispatchTable.OnAddNode = _on_add_node;
	g_DBDispatchTable.OnDropNode = _on_del_node;
	hook_rtdb_events(&g_DBDispatchTable);
	
	if(!(g_iInitFlag & PROXY_INIT_AS_SERVER)){
		unsigned char run, dev;
		int runLevel, devLevel;
		init_key();
		get_key(&run, &runLevel, &dev, &devLevel);
		if(!dev){
			/* no dog is attached*/
			/* create_group(0x12345678,xxx) is a loophole */
			create_group((RTK_CURSOR)0x12345678, (PRTK_GROUP)32);
			if(!(flags & PROXY_SILENT)){
				MessageBox(
					hWnd,
					szWarning,
					"PMC Error",
					MB_OK
					);
			}
		}else{
			/* yes, dog is attached, set database limit */
			create_group((RTK_CURSOR)0x12345678, (PRTK_GROUP)devLevel);
		}
	}
	init_powermgr();
	init_network(0);
	init_rtdb();
	connect_vbus(BUSID_RTDB, 0, _on_rtdb, default_client_filter);
	connect_vbus(BUSID_CONFIG, 0, _on_config, default_client_filter);
	connect_vbus(BUSID_ALARM, 0, _on_alarm, default_client_filter);
	connect_vbus(BUSID_SYSTEM, 0, _on_system, default_client_filter);
	connect_vbus(BUSID_OPERATION, 0, 0, default_client_filter);
	if(flags & PROXY_ENABLE_DISPATCHER){
		start_dispatcher();
	}	

	g_Worker = new CProxyWorker(flags);
	if(!g_Worker){
		g_InitLock.UnLock();
		return __false;		
	}
	g_Worker->start();

#if defined(_WIN32) && 1
	SetThreadPriority(g_Worker->handle(), THREAD_PRIORITY_BELOW_NORMAL);
#endif
		
	g_InitLock.UnLock();
	return __true;
}
예제 #28
0
void start(){
  initscr();
  srand(time(0));
  init_background(0,0);
  refresh();
  keypad(stdscr,TRUE);
  pthread_t keyboard;                                      //键盘监听线程
  int err = init_network();                                //初始化网络模块
  if(err!=0){
    mvprintw(5,60,"Network model init failed!");
  }
 start:
  initpanel();                                                   //把两个panel清空
  initblock(b1);initblock(b2);
  printpanel(PANELSTARTX,PANELSTARTY);
  err = pthread_create(&keyboard,NULL,keylistener,NULL);
  if(err !=0){
     printf("can't create thread keyboard listener!");
     exit(1);
    }

  //main thread make the block moving down until the gameover
  while(!over){
    movemid();
    if(caninput(b1)){			//可以放下当前块说明游戏未结束
      while( canmovedown() ){		//直到不能下落位置
	//继续下落
	goahead();	
	//显示一次			
	printpanel(PANELSTARTX,PANELSTARTY);

	usleep(sleeptime);
      }

      //save temp panel to preview panel and create new block
      savetoprev();
      printpanel(PANELSTARTX,PANELSTARTY);

	//停止下落后要消除
      eliminate();
	
	//把下一个块替换上来
      nextblock();
    }
    else
      over=true;
  }
  attrset(COLOR_PAIR(7));
  mvprintw(21,37,"YOU DEAD!Try again?(y/n):");
  int input;
  int quit = 1;
  while(quit){
    input=getch();                              //判断用户还要不要玩下去
    switch(input){
    case 'y':  
      over = 0;
      attrset(COLOR_PAIR(0));
      mvprintw(21,37,"                         ");
      goto start;                                 //重新开始
      break;
    case 'n':  endwin();quit = 0;break;
    default: 
      mvprintw(21,37,"YOU DEAD!Try again?(y/n):");
  }
  }
}
예제 #29
0
파일: runsc.c 프로젝트: Logan-lu/shellcode
int main (int argc, char *argv[])
{
  args_t args;
  struct stat st;
  
  #ifdef WIN
  // 
  PVOID   OldValue=NULL;
  WSADATA wsa;
  
  Wow64DisableWow64FsRedirection (&OldValue);
  WSAStartup(MAKEWORD(2,0), &wsa);
  #endif
  
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  
  memset (&args, 0, sizeof(args));
  
  // set default parameters
  args.address   = NULL;
  args.file      = NULL;
  args.ai_family = AF_INET;
  args.port      = DEFAULT_PORT;
  args.port_nbr  = atoi(args.port);
  args.mode      = -1;
  args.tx_mode   = -1;
  args.sim       = 0;
  args.dbg       = 0;
  
  printf ("\n[ run shellcode v0.1\n");
  
  parse_args(&args, argc, argv);
  
  // check if we have file parameter and it accessible
  if (args.file!=NULL) {
    if (stat (args.file, &st)) {
      printf ("[ unable to access %s\n", args.file);
      return 0;
    } else {
      if (st.st_size > MAX_BUFSIZ) {
        printf ("[ %s exceeds MAX_BUFSIZ of %i bytes\n", args.file, MAX_BUFSIZ);
        return 0;
      }
    }
  }
  
  // if mode is executing
  if (args.mode==RSC_EXEC) {
    if (args.file!=NULL) {
      xfile(&args);
      return 0;
    } else {
      printf ("\n[ you've used -x without supplying file with -f");
      return 0;
    }
  }
  if (init_network(&args))
  {
    // if no file specified, we receive and execute data
    args.tx_mode = (args.file==NULL) ? RSC_RECV : RSC_SEND;
    
    // if mode is -1, we listen for incoming connections
    if (args.mode == -1) {
      args.mode=RSC_SERVER;
    }
    
    // if no file specified, set to receive one
    if (args.tx_mode == -1) {
      args.tx_mode=RSC_RECV;
    }
    
    if (args.mode==RSC_SERVER) {
      ssr (&args);
    } else {
      csr (&args);
    }
  }
  return 0;
}
예제 #30
0
int main(int argc, char* argv[]) {
    char q[512];
    MYSQL_ROW row;
    MYSQL_RES* res;

    int err = init_network();
    if (err) {
        return err;
    }

    for (int year = 1990; year <= 2011; year++) {
        std::cout << "Querying " << year << "\n";

        snprintf(q, 512, "select count(value) from entries where year=%d and inserted>(select updated from visualizations where name='GAP2' and year=%d)", year, year);
        if (mysql_query(mysql, q)) {
            std::cerr << mysql_error(mysql) << "\n";
            return -2;
        }
        res = mysql_use_result(mysql);
        if ((row = mysql_fetch_row(res)) == 0 || atoi(row[0]) == 0) {
            mysql_free_result(res);
            continue;
        }
        mysql_free_result(res);

        err = read_network(year);
        if (err) {
            return err;
        }

        std::cout << "Calculating " << year << "\n";

        Basetype* in_flow = create_array(0);
        Basetype* out_flow = create_array(0);
        int regions_size = regions.size();
        Basetype* total_output = new Basetype[regions_size];
        for (int r = 0; r < regions_size; r++) {
            total_output[r] = 0;
        }
        for (int v = 0; v < network_size; v++) {
            for (int w = 0; w < network_size; w++) {
                in_flow[v] += flows[w][v];
                out_flow[v] += flows[v][w];
            }
            total_output[get_region(v)] += out_flow[v];
        }
        int sectors_size = sectors.size();
        Basetype** in_flow_by_sector = new Basetype*[sectors_size];
        for (int i = 0; i < sectors_size; i++) {
            in_flow_by_sector[i] = create_array(0);
        }
        for (int v = 0; v < network_size; v++) {
            for (int w = 0; w < network_size; w++) {
                in_flow_by_sector[get_sector(v)][w] += flows[v][w];
            }
        }

        snprintf(q, 512, "delete from visualization_data where visualization in (select id from visualizations where (name='GAP1' or name='GAP2') and year=%d)", year);
        if (mysql_query(mysql, q)) {
            std::cerr << mysql_error(mysql) << "\n";
            return -2;
        }

        snprintf(q, 512, "select id from visualizations where name='GAP1' and year=%d", year);
        if (mysql_query(mysql, q)) {
            std::cerr << mysql_error(mysql) << "\n";
            return -2;
        }
        res = mysql_use_result(mysql);
        row = mysql_fetch_row(res);
        int id1 = atoi(row[0]);
        mysql_free_result(res);

        snprintf(q, 512, "select id from visualizations where name='GAP2' and year=%d", year);
        if (mysql_query(mysql, q)) {
            std::cerr << mysql_error(mysql) << "\n";
            return -2;
        }
        res = mysql_use_result(mysql);
        row = mysql_fetch_row(res);
        int id2 = atoi(row[0]);
        mysql_free_result(res);

        for (int r = 0; r < regions_size; r++) {
            Basetype* damage1 = create_array(0);
            Basetype* damage2 = create_array(0);
            int js;

            #pragma omp parallel default(shared) private(js)
            {
                #pragma omp for schedule(guided) nowait
                for (js = 0; js < network_size; js++) {
                    if (get_region(js) == r) {
                        damage1[js] = 1;
                    } else {
                        for (int i = 0; i < sectors_size; i++) {
                            Basetype damage = flows[get_index(i, r)][js] / in_flow_by_sector[i][js];
                            if (damage1[js] < damage) {
                                damage1[js] = damage;
                            }
                        }
                    }
                }
            }
            #pragma omp parallel default(shared) private(js)
            {
                #pragma omp for schedule(guided) nowait
                for (js = 0; js < network_size; js++) {
                    if (get_region(js) == r) {
                        damage2[js] = 1;
                    } else {
                        for (int i = 0; i < sectors_size; i++) {
                            Basetype damage = 0;
                            for (int r = 0; r < regions_size; r++) {
                                int ir = get_index(i, r);
                                damage += damage1[ir] * flows[ir][js] / in_flow_by_sector[i][js];
                            }
                            if (damage2[js] < damage) {
                                damage2[js] = damage;
                            }
                        }
                    }
                }
            }

            Basetype* region_damage1 = new Basetype[regions_size];
            Basetype* region_damage2 = new Basetype[regions_size];
            for (int r = 0; r < regions_size; r++) {
                region_damage1[r] = 0;
                region_damage2[r] = 0;
            }
            for (int js = 0; js < network_size; js++) {
                int s = get_region(js);
                if (total_output[s] > 0) {
                    region_damage1[s] += damage1[js] * out_flow[js] / total_output[s];
                    region_damage2[s] += damage2[js] * out_flow[js] / total_output[s];
                }
            }
            delete[] damage1;
            delete[] damage2;

            std::stringstream query1("insert into visualization_data (visualization, region_from, region_to, value) values ", std::ios_base::app | std::ios_base::out);
            bool first1 = true;
            std::stringstream query2("insert into visualization_data (visualization, region_from, region_to, value) values ", std::ios_base::app | std::ios_base::out);
            bool first2 = true;
            for (int s = 0; s < regions_size; s++) {
                region_damage1[s] = round(region_damage1[s] * 1000) / 1000;
                if (region_damage1[s] > 0) {
                    if (first1) {
                        first1 = false;
                    } else {
                        query1 << ",";
                    }
                    query1 << "(" << id1 << ",'" << regions[r] << "','" << regions[s] << "'," << region_damage1[s] << ")";
                }
                region_damage2[s] = round(region_damage2[s] * 1000) / 1000;
                if (region_damage2[s] > 0) {
                    if (first2) {
                        first2 = false;
                    } else {
                        query2 << ",";
                    }
                    query2 << "(" << id2 << ",'" << regions[r] << "','" << regions[s] << "'," << region_damage2[s] << ")";
                }
            }
            if (!first1) {
                if (mysql_query(mysql, query1.str().c_str())) {
                    std::cerr << mysql_error(mysql) << "\n";
                    return -2;
                }
            }
            if (!first2) {
                if (mysql_query(mysql, query2.str().c_str())) {
                    std::cerr << mysql_error(mysql) << "\n";
                    return -2;
                }
            }

            delete[] region_damage1;
            delete[] region_damage2;
        }

        delete[] in_flow;
        delete[] out_flow;
        free_double_array(flows);
        for (int i = 0; i < sectors_size; i++) {
            delete[] in_flow_by_sector[i];
        }
        delete[] in_flow_by_sector;
        delete[] total_output;

        snprintf(q, 512, "update visualizations set updated=now() where (name='GAP1' or name='GAP2') and year=%d", year);
        if (mysql_query(mysql, q)) {
            std::cerr << mysql_error(mysql) << "\n";
            return -2;
        }
    }

    return disconnect();
}