예제 #1
0
파일: console.c 프로젝트: pegue/naev
/**
 * @brief Opens the console.
 */
void cli_open (void)
{
   unsigned int wid;

   /* Lazy loading. */
   if (cli_state == NULL)
      if (cli_init())
         return;

   /* Must not be already open. */
   if (window_exists( "Lua Console" ))
      return;

   /* Create the window. */
   wid = window_create( "Lua Console", -1, -1, cli_width, cli_height );

   /* Window settings. */
   window_setAccept( wid, cli_input );
   window_setCancel( wid, window_close );
   window_handleKeys( wid, cli_keyhandler );

   /* Input box. */
   window_addInput( wid, 20, 20,
         cli_width-60-BUTTON_WIDTH, BUTTON_HEIGHT,
         "inpInput", LINE_LENGTH, 1 );

   /* Buttons. */
   window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnClose", "Close", window_close );

   /* Custom console widget. */
   window_addCust( wid, 20, -40,
         cli_width-40, cli_height-80-BUTTON_HEIGHT,
         "cstConsole", 0, cli_render, NULL );
}
예제 #2
0
/* *****************************************************************************
The main function
***************************************************************************** */
int main(int argc, char const *argv[]) {
  /* initialize the CLI helper and options */
  cli_init(argc, argv);

  /* sertup routes */
  route_add("/json", on_request_json);
  route_add("/plaintext", on_request_plain_text);

  /* Server name and header */
  HTTP_HEADER_SERVER = fiobj_str_new("server", 6);
  HTTP_VALUE_SERVER = fiobj_str_new("facil.io " FIO_VERSION_STRING,
                                    strlen("facil.io " FIO_VERSION_STRING));
  /* JSON values to be serialized */
  JSON_KEY = fiobj_str_new("message", 7);
  JSON_VALUE = fiobj_str_new("Hello, World!", 13);

  /* Test for static file service */
  const char *public_folder = fio_cli_get("-www");
  if (public_folder) {
    fprintf(stderr, "* serving static files from:%s\n", public_folder);
  }

  /* listen to HTTP connections */
  http_listen(fio_cli_get("-port"), fio_cli_get("-address"),
              .on_request = route_perform, .public_folder = public_folder,
              .log = fio_cli_get_bool("-log"));

  /* Start the facil.io reactor */
  fio_start(.threads = fio_cli_get_i("-t"), .workers = fio_cli_get_i("-w"));

  /* perform cleanup */
  cleanup();
  return 0;
}
예제 #3
0
/*---------------------------------------------------------------------------*/
usys     mod_init (void)
{
    usys stat = GOOD ;

#ifdef   INCLUDE_STDIO
    if (stdio_init () != GOOD)
    {
       printf ("ERR: initStdio() Failed !!!\n") ;
       stat = BAD ; 
    }
#endif
#ifdef   INCLUDE_CLI
    if (cli_init () != GOOD)
    {
       printf ("ERR: cli_init() Failed !!!\n") ; 
       stat = BAD ; 
    }
#endif
#ifdef   INCLUDE_TESTS
    if (test_init () != GOOD)
    {
       printf ("ERR: test_init() Failed !!!\n") ; 
       stat = BAD ; 
    }
#endif
#ifdef   INCLUDE_NETWORK
    if (net_init () != GOOD)
    {
       printf ("ERR: net_init() Failed !!!\n") ; 
       stat = BAD ; 
    }
#endif

    return stat ;
} /* End of function mod_init () */
예제 #4
0
파일: cli.c 프로젝트: TakumiKomada/trema
int main(int argc, char **argv)
{
    char instance[PATH_MAX];
    int ret;

    memset(instance, '\0', sizeof(instance));

    log_init(LOG_WARN, LOG_OUT_STDOUT);

    cli_set_program_name(basename(argv[0]));

    if((argc > 2) && (strcmp(argv[1], "-i") == 0)){
        strncpy(instance, argv[2], PATH_MAX - 1);
        argc -= 2;
        argv += 2;
    }
    else{
        strncpy(instance, CLI_DEFAULT_INSTANCE, PATH_MAX - 1);
    }

    cli_init(instance);

    ret = cli_parse_args(argc, argv);
    if(ret < 0){
        log_err("cannot execute.");
    }

    cli_close();
    log_close();

    return 0;
}
예제 #5
0
int main(void)
{
	// SystemINIT
	SystemInit();

	// Init Debug Serial
	serial_init();

	// Init COOS
	CoInitOS ();

	// Setup tasks

	cli_init();		  // Init Serial Client
	ip_init();        // Init IP Stack
	http_init();	  // Init HTTP Server

	// Start Tasks!
	CoStartOS ();

	// Never to get here!!!
	while(1)
    {
    }
}
예제 #6
0
/*
 * Main Loop
 */
int main()
{
    LOG("--------------------------------\r\n");

    /* Unmask interrupt for output compare match A on TC0 */
    timers_setup_timer(TIMER_COUNTER0, TIMER_MODE_CTC, 1000UL);
    TIMSK0 |= (1 << OCIE0A);

    lcd_load_custom_character(degree_symbol, CUSTOM_SYMBOL_DEGREE);

    cli_init();
    motor_init(&g_timers_state);
    log_init();
	scheduler_init(&g_timers_state, g_tasks, COUNT_OF(g_tasks));
	interpolator_init(&g_timers_state);
    sei();

    log_start();

	/* Main Loop: Run Tasks scheduled by scheduler */
	while (1) {
	    int i;
	    for (i = 0; i < 50; i++) {
	        serial_check(); /* needs to be called frequently */
	    }
	    scheduler_service();
	}
}
예제 #7
0
파일: main.c 프로젝트: ckruczek/texpack
int main(int argc, char* argv[])
{
    jc_print();
    cli_init();
    cli_parse(argc,argv);
    //tpFreeCmdConfig();

    return 0;
}
예제 #8
0
/**
 * Main function.
 *
 * @return error code (0 - no error)
 */
int
main (int argc, /**< number of arguments */
      char **argv) /**< argument list */
{
  cli_state_t cli_state = cli_init (main_opts, argc - 1, argv + 1);

  for (int id = cli_consume_option (&cli_state); id != CLI_OPT_END; id = cli_consume_option (&cli_state))
  {
    switch (id)
    {
      case OPT_MERGE_HELP:
      {
        /* Help is always printed if no command is provided. */
        break;
      }
      case CLI_OPT_DEFAULT:
      {
        const char *command_p = cli_consume_string (&cli_state);

        if (cli_state.error != NULL)
        {
          break;
        }

        if (!strcmp ("merge", command_p))
        {
          return process_merge (&cli_state, argc, argv[0]);
        }
        else if (!strcmp ("generate", command_p))
        {
          return process_generate (&cli_state, argc, argv[0]);
        }

        jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: unknown command: %s\n\n", command_p);
        print_commands (argv[0]);

        return JERRY_STANDALONE_EXIT_CODE_FAIL;
      }
      default:
      {
        cli_state.error = "Internal error";
        break;
      }
    }
  }

  if (check_cli_error (&cli_state))
  {
    return JERRY_STANDALONE_EXIT_CODE_FAIL;
  }

  print_commands (argv[0]);
  return JERRY_STANDALONE_EXIT_CODE_OK;
} /* main */
예제 #9
0
int main_loop_interactive(struct mode *mode, char *confname)
{
	struct cli_def *cli;

	cli = cli_init();
	cli_set_banner(cli, "libcli test environment");
	cli_set_hostname(cli, "router");
//	cli_telnet_protocol(cli, 1);

	cli_done(cli);
	return 0;
}
예제 #10
0
/**
 * @brief Opens the console.
 */
void cli_open (void)
{
   unsigned int wid;

   /* Lazy loading. */
   if (cli_state == NULL)
      if (cli_init())
         return;

   /* Make sure main menu isn't open. */
   if (menu_isOpen(MENU_MAIN))
      return;

   /* Must not be already open. */
   if (window_exists( "Lua Console" ))
      return;

   /* Put a friendly message at first. */
   if (cli_firstOpen) {
      char buf[256];
      cli_addMessage( "" );
      cli_addMessage( "\egWelcome to the Lua console!" );
      nsnprintf( buf, sizeof(buf), "\eg "APPNAME" v%s", naev_version(0) );
      cli_addMessage( buf );
      cli_addMessage( "" );
      cli_firstOpen = 0;
   }

   /* Create the window. */
   wid = window_create( "Lua Console", -1, -1, CLI_WIDTH, CLI_HEIGHT );

   /* Window settings. */
   window_setAccept( wid, cli_input );
   window_setCancel( wid, window_close );
   window_handleKeys( wid, cli_keyhandler );

   /* Input box. */
   window_addInput( wid, 20, 20,
         CLI_WIDTH-60-BUTTON_WIDTH, BUTTON_HEIGHT,
         "inpInput", LINE_LENGTH, 1, cli_font );

   /* Buttons. */
   window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnClose", "Close", window_close );

   /* Custom console widget. */
   window_addCust( wid, 20, -40,
         CLI_WIDTH-40, CLI_HEIGHT-80-BUTTON_HEIGHT,
         "cstConsole", 0, cli_render, NULL, NULL );

   /* Cache current height in case the window is resized. */
   cli_height = CLI_HEIGHT;
}
예제 #11
0
파일: console.cpp 프로젝트: btb/dxx-rebirth
void con_init(void)
{
	con_buffer = {};
	if (CGameArg.DbgSafelog)
		gamelog_fp.reset(PHYSFS_openWrite("gamelog.txt"));
	else
		gamelog_fp = PHYSFSX_openWriteBuffered("gamelog.txt");

	cli_init();
	cmd_init();
	cvar_init();

}
//runs with lowest priority
void cli_task(){
	cli_init();

    while (1) {
	#ifndef MAVLINK_ON_UART0_ENABLED
		serial_printf((SerialDevice *)&cli_uart, "octanis Rover Console:\r\n");
		shell(commands, (SerialDevice *)&cli_uart);
	#else
		mavlink_rx((SerialDevice *)&cli_uart);
    #endif
    }


}
예제 #13
0
int wm_core_init(void)
{
	int ret = 0;
	static char init_done;

	if (init_done)
		return WM_SUCCESS;

	wmstdio_init(UART0_ID, 0);

	ret = cli_init();
	if (ret != WM_SUCCESS) {
		init_e("Cli init failed.");
		goto out;
	}

	ret = wmtime_init();
	if (ret != WM_SUCCESS) {
		init_e("Wmtime init failed.");
		goto out;
	}

	ret = pm_init();
	if (ret != WM_SUCCESS) {
		init_e("Power manager init failed.");
		goto out;
	}

	ret = healthmon_init();
	if (ret != WM_SUCCESS) {
		init_e("Healthmon init failed.");
		goto out;
	}

	boot_report_flags();

	wmlog("boot", "Reset Cause Register: 0x%x",
	      boot_reset_cause());
	if (boot_reset_cause() & (1<<5))
		wmlog("boot", " - Watchdog reset bit is set");

	/* Read partition table layout from flash */
	part_init();
out:
	if (ret == WM_SUCCESS)
		init_done = 1;
	return ret;
}
예제 #14
0
파일: netcom.c 프로젝트: mkocs/netcom
int main(int argc, char **argv)
{
  int run_srv, run_cli;

  if (argc < 2) {
    printf("Not enough arguments provided.\n%s", netcom_usage_string);
    return -1;
  }

  char *host_addr;

  for (int i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-h") == 0) {
      printf("NETCOM HELP\n%s%s", netcom_usage_string, netcom_cmd_string);
      return 0;
    } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
      printf("%s", netcom_ver_string);
      return 0;
    } else if (strcmp(argv[i], "-c") == 0) {
      if (i < argc-1) {
        host_addr = argv[i+1];
        run_cli = 1;
      } else {
        printf("Not enough arguments to call -c. You need to enter a destination address.\n");
        return -1;
      }
    } else if (strcmp(argv[i], "-s") == 0) {
      run_srv = 1;
    }
  }
  if (run_srv && !run_cli) {
    srv_init();
  } else if (run_srv && run_cli) {
    pthread_t srv_thread;
    if (pthread_create(&srv_thread, NULL, &srv_thread_init, &srv_thread) != 0) {
      printf("Server thread could not be created.\n");
      return -1;
    }
  }
  if (run_cli) {
    if (cli_init(host_addr) != 0) {
      srv_close();
      return -1;
    }
  }
  return 0;
}
예제 #15
0
파일: clitest.c 프로젝트: chrisa/monoimage
int main(int argc, char *argv[])
{
    struct cli_command *c;
    struct cli_def *cli;

    cli = cli_init();
    cli_set_banner(cli, "libcli test environment");
    cli_set_hostname(cli, "router");
    cli_set_newline(cli, "\n");
    cli_register_command(cli, NULL, "test", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
    cli_register_command(cli, NULL, "sex",  NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
    cli_register_command(cli, NULL, "simple",  NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
    cli_register_command(cli, NULL, "simon",  NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
    cli_register_command(cli, NULL, "set", cmd_set,  PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL);
    c = cli_register_command(cli, NULL, "show", NULL,  PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
    cli_register_command(cli, c, "counters", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the counters that the system uses");
    cli_register_command(cli, c, "junk", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);


    cli_register_command(cli, NULL, "interface", cmd_config_int, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Configure an interface");
    cli_register_command(cli, NULL, "exit", cmd_config_int_exit, PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, "Exit from interface configuration");
    cli_register_command(cli, NULL, "address", cmd_test, PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, "Set IP address");

    //cli_set_auth_callback(cli, check_auth);
    //cli_set_enable_callback(cli, check_enable);
    // Test reading from a file
    {
	    FILE *fh;

	    if ((fh = fopen("clitest.txt", "r")))
	    {
		    // This sets a callback which just displays the cli_print() text to stdout
		    cli_print_callback(cli, pc);
		    cli_file(cli, fh, PRIVILEGE_UNPRIVILEGED, MODE_EXEC);
		    cli_print_callback(cli, NULL);
		    fclose(fh);
	    }
    }

    set_canonical(0);
    cli_loop(cli, fileno(stdin), fileno(stdout));
    set_canonical(1);
        
    cli_done(cli);
    return 0;
}
예제 #16
0
int jemCLIinit(void)
{
    int on = 1;

    cli = cli_init();
    cli_set_banner(cli, "Jem/JVM Command Line Interface");
    cli_set_hostname(cli, "Jem/JVM");
    cli_register_command(cli, NULL, "uptime", cmdUptime, PRIVILEGE_UNPRIVILEGED,
        MODE_EXEC, "Display uptime.");

    if ((socketFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        printf("Socket creation error for CLI, result=%d.\n", errno);
        return errno;
    }
    setsockopt(socketFD, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

    memset(&serverAddr, 0, sizeof(serverAddr));
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    int cliPort = getIntVal((char *) "CLIPORT");
    if (cliPort == 0) cliPort = 8181;
    serverAddr.sin_port = htons(cliPort);
    if (bind(socketFD, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) {
        printf("Socket bind error for CLI, result=%d.\n", errno);
        return errno;
    }

    if (listen(socketFD, 50) < 0) {
        printf("Socket listen error for CLI, result=%d.\n", errno);
        return errno;
    }

    int result = rt_task_create(&cliTask,"cliTask",0,1,T_FPU|T_JOINABLE);
    if (result) {
        printf("Failed to create cli task, code=%d \n", result);
        return -1;
    }

    result = rt_task_start(&cliTask,&commandTask,NULL);
    if (result) {
        printf("Failed to start cli task, code=%d \n", result);
        return -1;
    }

    return 0;
}
예제 #17
0
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void tuh_msc_mounted_cb(uint8_t dev_addr)
{
  puts("\na MassStorage device is mounted");

  //------------- Disk Information -------------//
  // SCSI VendorID[8] & ProductID[16] from Inquiry Command
  uint8_t const* p_vendor  = tuh_msc_get_vendor_name(dev_addr);
  uint8_t const* p_product = tuh_msc_get_product_name(dev_addr);

  for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);

  putchar(' ');
  for(uint8_t i=0; i<16; i++) putchar(p_product[i]);
  putchar('\n');

  uint32_t last_lba, block_size;
  tuh_msc_get_capacity(dev_addr, &last_lba, &block_size);
  printf("Disk Size: %d MB\n", (last_lba+1)/ ((1024*1024)/block_size) );
  printf("LBA 0-0x%X  Block Size: %d\n", last_lba, block_size);

  //------------- file system (only 1 LUN support) -------------//
  uint8_t phy_disk = dev_addr-1;
  disk_initialize(phy_disk);

  if ( disk_is_ready(phy_disk) )
  {
    if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK )
    {
      puts("mount failed");
      return;
    }

    puts("---------------------------------------------------------------------");
    puts("- MASSSTORAGE CLASS CLI IS A IMMATURE CODE. DISK-WRITING COMMANDS");
    puts("- SUCH AS cp(COPY), mkdir(MAKE DIRECTORY) ARE POTENTIAL TO DAMAGE");
    puts("- YOUR USB THUMBDRIVE. USING THOSE COMMANDS ARE AT YOUR OWN RISK.");
    puts("- THE AUTHOR HAS NO RESPONSIBILITY WITH YOUR DEVICE NOR ITS DATA");
    puts("---------------------------------------------------------------------");

    f_chdrive(phy_disk); // change to newly mounted drive
    f_chdir("/"); // root as current dir

    cli_init();
  }
}
예제 #18
0
void tuh_msc_unmounted_cb(uint8_t dev_addr)
{
  puts("\na MassStorage device is unmounted");

  uint8_t phy_disk = dev_addr-1;

  f_mount(phy_disk, NULL); // unmount disk
  disk_deinitialize(phy_disk);

  if ( phy_disk == f_get_current_drive() )
  { // active drive is unplugged --> change to other drive
    for(uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX; i++)
    {
      if ( disk_is_ready(i) )
      {
        f_chdrive(i);
        cli_init(); // refractor, rename
      }
    }
  }
}
int main()
{	
    cli_init();

    mastercontroller_init();

    uint8_t i = 0;
    while(1) {
        for(i = 0; i < 5; i++) { 
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            usleep(200);
        }
        mastercontroller_tick();
        cli_process();
    }
    cli_exit();
	return 0;
}
int cli_server_init(cli_handler_t handler)
{

  int one = 1;
  cli_init();

  cli_server_handler = handler;

  if ((cli_cfg->sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return -1;
  }

  if (setsockopt(cli_cfg->sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
                 sizeof(one)) < 0) {
    perror("setsockopt");
    return -1;
  }

  LOG_I(CLI,"socket created %d\n", cli_cfg->sfd);
  memset(&saddr, 0, sizeof(saddr));
  saddr.sin_family = AF_INET;
  saddr.sin_addr.s_addr = htonl(INADDR_ANY);
  saddr.sin_port = htons(server_port);

  if (bind(cli_cfg->sfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
    perror("bind");
    return -1;
  }

  /* create telnet listener thread */
  if (pthread_create(&cli_server_listener, NULL, cli_server_listen, NULL)) {
    perror("thread");
    return -1;
  }

  return 0;
}
예제 #21
0
파일: main.c 프로젝트: bonnefoa/junkie
static void all_init(void)
{
    log_init();
    files_init();
    ext_init();
    cli_init();
    mallocer_init();    // as all users do not init it...
    ref_init(); // as all users do not init it...
    hash_init();    // as all users do not init it...
    redim_array_init(); // if there are no users then some ext functions used by the www interface won't be defined
    os_detect_init();   // dummy function just to include os_detect in junkie (that does not use it, but plugins may want to)

    // Openssl don't like to be inited several times so let's do it once and for all
    SSL_load_error_strings();
    SSL_library_init();
    OpenSSL_add_all_algorithms();

    for (unsigned i = 0; i < NB_ELEMS(initers); i++) {
        initers[i].init();
    }

    ext_rebind();
}
예제 #22
0
void user_init(void)
{
    sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
    printf("\n\n\n");
    printf("SDK version:%s\n", sdk_system_get_sdk_version());
    cli_init();

#ifndef CONFIG_NO_WIFI
    struct sdk_station_config config = {
        .ssid = WIFI_SSID,
        .password = WIFI_PASS,
    };

    /* required to call wifi_set_opmode before station_set_config */
    sdk_wifi_set_opmode(STATION_MODE);
    sdk_wifi_station_set_config(&config);
#endif // CONFIG_NO_WIFI

    xTaskCreate(&server_task, (signed char *) "server_task", 256, NULL, 2, NULL);
#ifndef CONFIG_NO_PIR
    xTaskCreate(&pir_task, (signed char *) "pir_task", 256, NULL, 2, NULL);
#endif // CONFIG_NO_PIR
}
int main()
{

  printf("start \n");
  cli_init();

  //Main process of telnet  server
  if (cli_server_init(cli_server_recv) < 0) {
    printf("server init failed \n");
    exit(-1);
  }

  while (cli_cfg->exit ==0) {
  }

  printf("server init done 1 \n");
  cli_server_cleanup();
  //pthread_join(telnet_server_listener, NULL);
  printf("server init done \n");


  return 0;
}
예제 #24
0
static void modules_init()
{
    int ret;

    ret = wmstdio_init(UART0_ID, 0);
    if (ret != WM_SUCCESS) {
        wmprintf("Error: wmstdio_init failed\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = cli_init();
    if (ret != WM_SUCCESS) {
        wmprintf("Error: cli_init failed\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
    ret = wlan_cli_init();
    if (ret != WM_SUCCESS) {
        wmprintf("Error: wlan_cli_init failed\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = pm_cli_init();
    if (ret != WM_SUCCESS) {
        wmprintf("Error: pm_cli_init failed\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
    /* Initialize time subsystem.
     *
     * Initializes time to 1/1/1970 epoch 0.
     */
    ret = wmtime_init();
    if (ret != WM_SUCCESS) {
        wmprintf("Error: wmtime_init failed\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
    return;
}
예제 #25
0
int sandbox_main_loop_init(void)
{
	struct sandbox_state *state = state_get_current();

	/* Execute command if required */
	if (state->cmd || state->run_distro_boot) {
		int retval = 0;

		cli_init();

#ifdef CONFIG_CMDLINE
		if (state->cmd)
			retval = run_command_list(state->cmd, -1, 0);

		if (state->run_distro_boot)
			retval = cli_simple_run_command("run distro_bootcmd",
							0);
#endif
		if (!state->interactive)
			os_exit(retval);
	}

	return 0;
}
예제 #26
0
/*******************************************************************************
 * Do it.
 *
 ******************************************************************************/
int main()
{
    clock_init();
    uart_init();
    uart_puts("\r\nInitializing...\r\n");
    timer_init();
    io_init();
    uart_puts("Starting drive...\r\n");

    c1541_init();

    cli_init();

    for (;;)
    {
#ifdef CONFIG_GDBSIM
        uart_putdec(demon_clock());
        uart_putcrlf();
#endif
        cli_check();
    }

    return 0;
}
예제 #27
0
int cli_main( uint16_t port ) {
    struct sockaddr_in addr;
    struct sockaddr client_addr;
    int bindfd;
    int clientfd;
    cli_client_t* client;
#ifdef _STANDALONE_CLI_
    unsigned sock_len;
#else
    int sock_len;
#endif

    sock_len = sizeof(struct sockaddr);
    pthread_mutex_init( &parser_lock, NULL );

    cli_init();
    cli_parser_init();
    cli_scanner_init();

    /* create a socket to listen for connections on */
    bindfd = socket( AF_INET, SOCK_STREAM, 0 );
    if( bindfd == -1 ) {
        fprintf( stderr, "Error: unable to create a IPv4 TCP socket" );
        return CLI_ERROR;
    }

    /* bind to the requested port */
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = 0;
    memset(&(addr.sin_zero), 0, sizeof(addr.sin_zero));
    if( bind(bindfd, (struct sockaddr*)&addr, sizeof(struct sockaddr)) ) {
        fprintf( stderr, "Error: CLI unable to bind to port %u", port );
        return CLI_ERROR;
    }

    /* listen for clients */
    listen( bindfd, 10 );

#ifndef _STANDALONE_CLI_
    /* listen locally too */
    cli_local_init( port );
#endif

    while( !cli_is_time_to_shutdown() ) {
        /* wait for a new client */
        clientfd = accept(bindfd, &client_addr, &sock_len);
        if( clientfd == - 1 ) {
            if( errno == EINTR ) {
                /* Interrupt received, going back to accept() */
                continue;
            }

            /* some error */
            perror( "accept() failed" );
            continue;
        }
        /* accepted a new connection client */

        /* create a client record */
        client = malloc_or_die( sizeof(cli_client_t) );
        client->fd = clientfd;
        search_state_init( &client->state, CLI_INIT_BUF, CLI_MAX_BUF );

        /* spawn a new thread to handle the client */
        make_thread( cli_client_handler_main, client );
    }

    return CLI_SHUTDOWN;
}
예제 #28
0
파일: cli.c 프로젝트: 0x0mar/netsniff-ng
int cli(void)
{
   struct sockaddr_in servaddr;
   struct cli_command  
     *address,
     *clear,
     *debug, 
     *eth_frame,
     *frame,
     *ip_packet,
     *ip_int,
     *launch,
     *mac_packet,
     *macaddr,
     *mac_int,
     *pld,
     *port,
     *reset,
     *run,
     *show,
     *tag,
     *tcp_packet,
     *udp_packet;
   
   struct cli_def *cli;
   int on = 1, x, s, cnt=0;
   int i;
   char TimeStamp[128];

   (void) signal(SIGINT, clean_up);  // to close and free everything upon SIGINT
   
   // Must be called first to setup data structures
   cli = cli_init();
   gcli = cli; 
   
   // Set the hostname (shown in the the prompt)
   cli_set_hostname(cli, "mz");
   
   // Set the greeting
   cli_set_banner(cli, "mausezahn " VERSION_LONG);
   
   // Enable usernames and passwords
   cli_allow_user(cli, mz_username, mz_password);
   cli_allow_enable(cli, mz_enable);
   
   // Initialize MOPS
   mp_head = mops_init();  // now mp_head points to the head of the doubly linked list 

   // Initialize packet sequences list 
   packet_sequences = mz_ll_create_new_element(NULL); 
	
	
   mops_rx_arp();
   lookupdev();
   for (i=0; i<device_list_entries; i++) {
        get_dev_params(device_list[i].dev);
   }

   // Initialize sequence list
   
	
   // **************** THE MAIN CLI COMMANDS ****************
   
   // ---- DEBUG MODE: ----
   debug = cli_register_command(cli, NULL, "debug", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Enter debug mode");
   cli_register_command(cli, debug, "packet", debug_packet, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Debug packet processing");
   cli_register_command(cli, debug, "all", debug_all, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Debug all (beware!)");

   // ---- INTERFACE MODE COMMANDS: ---- (these are defaults for the 'device defaults' command)
   cli_register_command(cli, NULL, "interface", enter_interface, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Enter interface configuration mode");
   ip_int = cli_register_command(cli, NULL, "ip", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure interface IP address");
   cli_register_command(cli, ip_int, "address", conf_ip_address, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure interface IP address");
   mac_int= cli_register_command(cli, NULL, "mac", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure interface MAC address");
   cli_register_command(cli, mac_int, "address", conf_mac_address, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure interface MAC address");
   tag = cli_register_command(cli, NULL, "tag", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure tags");
   cli_register_command(cli, tag, "dot1q", conf_tag_dot1q, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure 802.1Q and 802.1P parameters");
   cli_register_command(cli, tag, "mpls", conf_tag_mpls, PRIVILEGE_PRIVILEGED, MZ_MODE_INTERFACE, "Configure mpls label stack");

   // ---- VARIOUS CONFIG MODE COMMANDS : ----
   frame = cli_register_command(cli, NULL, "frame", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Configure global frame settings");
   cli_register_command(cli, frame, "limit", conf_frame_limit, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Configure frame size limits");
   cli_register_command(cli, NULL, "sequence", conf_sequence, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Configure a sequence of packets");

   // ---- PACKET CONFIG MODE COMMANDS: ----
   cli_register_command(cli, NULL, "packet", enter_packet, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Enter packet configuration mode");
   cli_register_command(cli, NULL, "clone", cmd_packet_clone, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Clone from another packet");
   cli_register_command(cli, NULL, "name", cmd_packet_name, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Assign a unique name");
   cli_register_command(cli, NULL, "description", cmd_packet_description, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Assign a packet description text");
   cli_register_command(cli, NULL, "bind", cmd_packet_bind, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Select the network interface");
   cli_register_command(cli, NULL, "count", cmd_packet_count, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the packet count value");
   cli_register_command(cli, NULL, "delay", cmd_packet_delay, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the inter-packet delay");
   cli_register_command(cli, NULL, "interval", cmd_packet_interval, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a greater interval");
   cli_register_command(cli, NULL, "type", cmd_packet_type, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Specify packet type");
   mac_packet = cli_register_command(cli, NULL, "mac", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's MAC addresses");
   address = cli_register_command(cli, mac_packet, "address", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's source IP address");
   cli_register_command(cli, address, "source", cmd_packet_mac_address_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's source MAC addresses");
   cli_register_command(cli, address, "destination", cmd_packet_mac_address_destination, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's destination MAC addresses");
   tag = cli_register_command(cli, NULL, "tag", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure tags");
   cli_register_command(cli, tag, "dot1q", cmd_packet_dot1q, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure 802.1Q (and 802.1P) parameters");
   cli_register_command(cli, tag, "mpls", cmd_packet_mpls, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure MPLS label stack");
   pld = cli_register_command(cli, NULL, "payload", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a payload");
   cli_register_command(cli, pld, "hex", cmd_packet_payload_hex, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a payload in hexadecimal format");
   cli_register_command(cli, pld, "ascii", cmd_packet_payload_ascii, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a payload in ascii format");
   cli_register_command(cli, pld, "raw", cmd_packet_payload_raw, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a raw payload (whole file as it is)");
   port = cli_register_command(cli, NULL, "port", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's port numbers");
   cli_register_command(cli, port, "source", cmd_port_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's source port number");
   cli_register_command(cli, port, "destination", cmd_port_destination, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's destination port number");
   cli_register_command(cli, NULL, "end", cmd_packet_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "End packet configuration mode");

   // ---------- Ethernet related (for all packets that have Ethernet or LLC/SNAP as link layer)
   eth_frame = cli_register_command(cli, NULL, "ethernet", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure frame's Ethernet, 802.2, 802.3, or SNAP settings");
   macaddr = cli_register_command(cli, eth_frame, "address", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure frame's source or destination MAC address");
   cli_register_command(cli, macaddr, "source", cmd_packet_mac_address_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure frame's source MAC addresses");
   cli_register_command(cli, macaddr, "destination", cmd_packet_mac_address_destination, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure frame's destination MAC addresses");
   cli_register_command(cli, eth_frame, "type", cmd_eth_type, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure Ethernet's type field");
   cli_register_command(cli, eth_frame, "length", cmd_eth_length, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure IEEE 802.3 length field");
   cli_register_command(cli, eth_frame, "llc", cmd_eth_llc, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the IEEE 802.2 field");
   cli_register_command(cli, eth_frame, "snap", cmd_eth_snap, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the IEEE 802.2 field");

   // ---------- IP related (for all packets that have IPv4 as network layer)
   ip_packet = cli_register_command(cli, NULL, "ip", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's IP settings");
   address = cli_register_command(cli, ip_packet, "address", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's source or destination IP address");
   cli_register_command(cli, address, "source", cmd_ip_address_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's source IP address");
   cli_register_command(cli, address, "destination", cmd_ip_address_destination, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's destination IP address");
   cli_register_command(cli, ip_packet, "version", cmd_ip_version, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure version field in IPv4 header");
   cli_register_command(cli, ip_packet, "ttl", cmd_ip_ttl, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure TTL field in IPv4 header");
   cli_register_command(cli, ip_packet, "protocol", cmd_ip_protocol, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure protocol field in IPv4 header");
   cli_register_command(cli, ip_packet, "hlen", cmd_ip_hlen, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure header-length (aka IHL) field in IPv4 header");
   cli_register_command(cli, ip_packet, "length", cmd_ip_len, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure length field in IPv4 header");
   cli_register_command(cli, ip_packet, "identification", cmd_ip_id, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure identification field in IPv4 header");
   cli_register_command(cli, ip_packet, "offset", cmd_ip_offset, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure fragment offset field in IPv4 header");
   cli_register_command(cli, ip_packet, "checksum", cmd_ip_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure checksum field in IPv4 header");
   cli_register_command(cli, ip_packet, "tos", cmd_ip_tos, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure type-of-service (ToS) field in IPv4 header");
   cli_register_command(cli, ip_packet, "dscp", cmd_ip_dscp, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the ToS as DSCP field in IPv4 header");
   cli_register_command(cli, ip_packet, "reserved", cmd_ip_rsv, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the reserved flag in IPv4 header");
   cli_register_command(cli, ip_packet, "dont-fragment", cmd_ip_df, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the don't fragment flag in IPv4 header");
   cli_register_command(cli, ip_packet, "more-fragments", cmd_ip_mf, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the more fragments flag in IPv4 header");
   cli_register_command(cli, ip_packet, "fragment-size", cmd_ip_fragsize, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the fragment size to enable fragmentation");
   cli_register_command(cli, ip_packet, "fragment-overlap", cmd_ip_fragoverlap, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a fragmentation overlap");
   cli_register_command(cli, ip_packet, "option", cmd_ip_option, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure IPv4 options");
   cli_register_command(cli, ip_packet, "auto-delivery", cmd_ip_delivery, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Enable or disable IP auto-delivery");
   // --------- IP commands:
   cli_register_command(cli, NULL, "version", cmd_ip_version, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP version (default: 4)");
   cli_register_command(cli, NULL, "ttl", cmd_ip_ttl, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the TTL (default: 255)");
   cli_register_command(cli, NULL, "source-address", cmd_ip_address_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the source IP address");
   cli_register_command(cli, NULL, "destination-address", cmd_ip_address_destination, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the destination IP address");
   cli_register_command(cli, NULL, "protocol", cmd_ip_protocol, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP protocol");
   cli_register_command(cli, NULL, "hlen", cmd_ip_hlen, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP header length");
   cli_register_command(cli, NULL, "len", cmd_ip_len, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP packet length");
   cli_register_command(cli, NULL, "identification", cmd_ip_id, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP identification");
   cli_register_command(cli, NULL, "offset", cmd_ip_offset, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the fragment offset");
   cli_register_command(cli, NULL, "sum", cmd_ip_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the IP header checksum");
   cli_register_command(cli, NULL, "tos", cmd_ip_tos, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the Type of Service");
   cli_register_command(cli, NULL, "dscp", cmd_ip_dscp, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Specify the DSCP");
   cli_register_command(cli, NULL, "reserved", cmd_ip_rsv, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Set or unset the reserved bit");
   cli_register_command(cli, NULL, "df", cmd_ip_df, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Set or unset the Don't Fragment (DF) bit");
   cli_register_command(cli, NULL, "mf", cmd_ip_mf, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Set or unset the More Fragments (MF) bit");
   cli_register_command(cli, NULL, "fragment-size", cmd_ip_fragsize, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Configure the fragment size to enable fragmentation");
   cli_register_command(cli, NULL, "fragment-overlap", cmd_ip_fragoverlap, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Configure a fragmentation overlap");
   cli_register_command(cli, NULL, "option", cmd_ip_option, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Configure an IP option");
   cli_register_command(cli, NULL, "auto-delivery", cmd_ip_delivery, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "Enable or disable IP auto-delivery");
   cli_register_command(cli, NULL, "end", cmd_ip_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IP, "End IP configuration mode");

   // ---------- UDP related (for all packets that have UDP as transport layer)
   udp_packet = cli_register_command(cli, NULL, "udp", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's UDP header parameters");
   cli_register_command(cli, udp_packet, "checksum", cmd_udp_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the UDP checksum");
   cli_register_command(cli, udp_packet, "length", cmd_udp_len, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the UDP length field");
   // ---------- UDP commands:
   cli_register_command(cli, NULL, "checksum", cmd_udp_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_UDP, "Configure the UDP checksum");
   cli_register_command(cli, NULL, "length", cmd_udp_len, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_UDP, "Configure the UDP length field");
   cli_register_command(cli, NULL, "end", cmd_udp_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_UDP, "End UDP configuration mode");
   
   // ---------- TCP related (for all packets that have TCP as transport layer)
   tcp_packet = cli_register_command(cli, NULL, "tcp", NULL, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure packet's TCP header parameters");
   cli_register_command(cli, tcp_packet, "seqnr", cmd_tcp_seqnr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP sequence number");
   cli_register_command(cli, tcp_packet, "acknr", cmd_tcp_acknr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP acknowledgement number");
   cli_register_command(cli, tcp_packet, "hlen", cmd_tcp_offset, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP header length");
   cli_register_command(cli, tcp_packet, "reserved", cmd_tcp_res, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP reserved field");
   cli_register_command(cli, tcp_packet, "flags", cmd_tcp_flags, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure a combination of TCP flags at once");
   cli_register_command(cli, tcp_packet, "cwr", cmd_tcp_cwr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Set or unset the TCP CWR flag");
   cli_register_command(cli, tcp_packet, "ece", cmd_tcp_ece, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Set or unset the TCP ECE flag");
   cli_register_command(cli, tcp_packet, "urg", cmd_tcp_urg, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Set or unset the TCP URG flag");
   cli_register_command(cli, tcp_packet, "ack", cmd_tcp_ack, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "set or unset the TCP ACK flag");
   cli_register_command(cli, tcp_packet, "psh", cmd_tcp_psh, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "set or unset the TCP PSH flag");
   cli_register_command(cli, tcp_packet, "rst", cmd_tcp_rst, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "set or unset the TCP RST flag");
   cli_register_command(cli, tcp_packet, "syn", cmd_tcp_syn, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "set or unset the TCP SYN flag");
   cli_register_command(cli, tcp_packet, "fin", cmd_tcp_fin, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "set or unset the TCP FIN flag");
   cli_register_command(cli, tcp_packet, "window", cmd_tcp_window, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP window size");
   cli_register_command(cli, tcp_packet, "checksum", cmd_tcp_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP checksum");
   cli_register_command(cli, tcp_packet, "urgent-pointer", cmd_tcp_urgptr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure the TCP urgend pointer");
   cli_register_command(cli, tcp_packet, "options", cmd_tcp_options, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET, "Configure TCP options");
   // ---------- TCP commands:
   cli_register_command(cli, NULL, "seqnr", cmd_tcp_seqnr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP sequence number");
   cli_register_command(cli, NULL, "acknr", cmd_tcp_acknr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP acknowledgement number");
   cli_register_command(cli, NULL, "hlen", cmd_tcp_offset, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP header length");
   cli_register_command(cli, NULL, "reserved", cmd_tcp_res, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP reserved field");
   cli_register_command(cli, NULL, "flags", cmd_tcp_flags, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure a combination of TCP flags at once");
   cli_register_command(cli, NULL, "cwr", cmd_tcp_cwr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Set or unset the TCP CWR flag");
   cli_register_command(cli, NULL, "ece", cmd_tcp_ece, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Set or unset the TCP ECE flag");
   cli_register_command(cli, NULL, "urg", cmd_tcp_urg, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Set or unset the TCP URG flag");
   cli_register_command(cli, NULL, "ack", cmd_tcp_ack, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "set or unset the TCP ACK flag");
   cli_register_command(cli, NULL, "psh", cmd_tcp_psh, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "set or unset the TCP PSH flag");
   cli_register_command(cli, NULL, "rst", cmd_tcp_rst, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "set or unset the TCP RST flag");
   cli_register_command(cli, NULL, "syn", cmd_tcp_syn, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "set or unset the TCP SYN flag");
   cli_register_command(cli, NULL, "fin", cmd_tcp_fin, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "set or unset the TCP FIN flag");
   cli_register_command(cli, NULL, "window", cmd_tcp_window, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP window size");
   cli_register_command(cli, NULL, "checksum", cmd_tcp_sum, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP checksum");
   cli_register_command(cli, NULL, "urgent-pointer", cmd_tcp_urgptr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure the TCP urgend pointer");
   cli_register_command(cli, NULL, "options", cmd_tcp_options, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "Configure TCP options");
   cli_register_command(cli, NULL, "end", cmd_tcp_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_TCP, "End TCP configuration mode");   
   
   // --------- ARP commands:
   cli_register_command(cli, NULL, "hardware-type", cmd_arp_hwtype, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the hardware type");
   cli_register_command(cli, NULL, "protocol-type", cmd_arp_prtype, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the protocol type");
   cli_register_command(cli, NULL, "hw-addr-size", cmd_arp_hwaddrsize, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the hardware address size");
   cli_register_command(cli, NULL, "pr-addr-size", cmd_arp_praddrsize, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the protocol address size");
   cli_register_command(cli, NULL, "opcode", cmd_arp_opcode, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the ARP opcode");
   cli_register_command(cli, NULL, "sender-mac", cmd_arp_smac, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the sender MAC address");
   cli_register_command(cli, NULL, "sender-ip", cmd_arp_sip, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the sender IP address");
   cli_register_command(cli, NULL, "target-mac", cmd_arp_tmac, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the target MAC address");
   cli_register_command(cli, NULL, "target-ip", cmd_arp_tip, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the target IP address");
   cli_register_command(cli, NULL, "trailer", cmd_arp_trailer, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "Specify the trailer length");
   cli_register_command(cli, NULL, "end", cmd_arp_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_ARP, "End ARP configuration mode");

   // --------- BPDU commands:
   cli_register_command(cli, NULL, "id", cmd_bpdu_id, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU identifier");
   cli_register_command(cli, NULL, "version", cmd_bpdu_version, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU version");
   cli_register_command(cli, NULL, "bpdutype", cmd_bpdu_type, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU type");
   cli_register_command(cli, NULL, "flags", cmd_bpdu_flags, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU flags");
   cli_register_command(cli, NULL, "root-id", cmd_bpdu_rid, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU root identifier");
   cli_register_command(cli, NULL, "path-cost", cmd_bpdu_pc, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU root path cost");
   cli_register_command(cli, NULL, "bridge-id", cmd_bpdu_bid, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU bridge identifier");
   cli_register_command(cli, NULL, "port-id", cmd_bpdu_pid, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU port identifier");
   cli_register_command(cli, NULL, "age", cmd_bpdu_age, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU age");
   cli_register_command(cli, NULL, "maxage", cmd_bpdu_maxage, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU maxage");
   cli_register_command(cli, NULL, "hello-interval", cmd_bpdu_hello, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU hello interval");
   cli_register_command(cli, NULL, "forward-delay", cmd_bpdu_fwd, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU forward delay");
   cli_register_command(cli, NULL, "mode", cmd_bpdu_mode, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the BPDU mode");
   cli_register_command(cli, NULL, "vlan", cmd_bpdu_vlan, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "Specify the vlan for PVST+");
   cli_register_command(cli, NULL, "end", cmd_bpdu_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_BPDU, "End BPDU configuration mode");

   // --------- IGMP commands:
   cli_register_command(cli, NULL, "v2-general-query", 	cmd_igmpv2_genquery, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv2 general query");
   cli_register_command(cli, NULL, "v2-group-specific-query", cmd_igmpv2_specquery, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv2 group-specific query");
   cli_register_command(cli, NULL, "v2-report", cmd_igmpv2_report, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv2 membership report");
   cli_register_command(cli, NULL, "v2-leave", cmd_igmpv2_leave, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv2 leave group message");
   cli_register_command(cli, NULL, "v1-query", 	cmd_igmpv1_query, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv1 query");
   cli_register_command(cli, NULL, "v1-report", cmd_igmpv1_report, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "Create an IGMPv1 membership report");
   cli_register_command(cli, NULL, "end", cmd_ip_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_IGMP, "End IGMP configuration mode"); // we reuse cmd_ip_end here!

   cli_register_command(cli, NULL, "conformance", cmd_lldp_conformance, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Enable or disable LLDP standard conformance");
   cli_register_command(cli, NULL, "chassis-id", cmd_lldp_chassis_id, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure the LLDP Chassis-ID");
   cli_register_command(cli, NULL, "port-id", cmd_lldp_port_id, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure the LLDP Port-ID");
   cli_register_command(cli, NULL, "ttl", cmd_lldp_ttl, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure the LLDP Time-to-Live");	
   cli_register_command(cli, NULL, "vlan", cmd_lldp_vlan, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure the LLDP Port VLAN-ID");
   cli_register_command(cli, NULL, "generic-tlv", cmd_lldp_opt_tlv, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure a generic LLDP TLV");
   cli_register_command(cli, NULL, "bad-tlv", cmd_lldp_opt_tlv_bad, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure a bad TLV for testing purposes");
   cli_register_command(cli, NULL, "organisational-tlv", cmd_lldp_opt_org, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Configure an organisational LLDP TLV");
   cli_register_command(cli, NULL, "early-end", cmd_lldp_endtlv, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Insert an 'early' End-of-LLDPU TLV");
   cli_register_command(cli, NULL, "reset", cmd_lldp_reset, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "Reset the LLDPU to defaults and clear all optional TLVs");
   cli_register_command(cli, NULL, "end", cmd_ip_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_LLDP, "End IGMP configuration mode"); // we reuse cmd_ip_end here!

   // --------- RTP commands:
   cli_register_command(cli, NULL, "version", cmd_rtp_version, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Specify the RTP version (default: 2)");
   cli_register_command(cli, NULL, "padding", cmd_rtp_padding, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Set or unset the padding flag (default: 0)");
   cli_register_command(cli, NULL, "xten", cmd_rtp_xten, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Set or unset the eXtension flag (default: 0)");
   cli_register_command(cli, NULL, "marker", cmd_rtp_marker, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Set or unset the marker flag (default: 0)");
   cli_register_command(cli, NULL, "csrc-count", cmd_rtp_cc, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the CSRC count (default: 0)");
   cli_register_command(cli, NULL, "csrc-list", cmd_rtp_cclist, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the CSRC list (default: none)");
   cli_register_command(cli, NULL, "payload-type", cmd_rtp_pt, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the payload type (default: G.711, A-law, 20 msec)");
   cli_register_command(cli, NULL, "sequence-number", cmd_rtp_sqnr, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the sequence number");
   cli_register_command(cli, NULL, "timestamp", cmd_rtp_time, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the timestamp");
   cli_register_command(cli, NULL, "ssrc", cmd_rtp_ssrc, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure the SSRC (source identifier)");
   cli_register_command(cli, NULL, "extension", cmd_rtp_extension, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Configure an extension header");
   cli_register_command(cli, NULL, "source", cmd_rtp_source, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "Specify a media source");
   cli_register_command(cli, NULL, "end", cmd_ip_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_RTP, "End RTP configuration mode"); // we reuse cmd_ip_end here!
	
   // --------- DNS commands:
   cli_register_command(cli, NULL, "ttl", cmd_dns_ttl, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_DNS, "Specify the TTL (default: 0)");
   cli_register_command(cli, NULL, "query", cmd_dns_query, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_DNS, "Specify the query");
   cli_register_command(cli, NULL, "answer", cmd_dns_answer, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_DNS, "Specify the answer");
   cli_register_command(cli, NULL, "end", cmd_dns_end, PRIVILEGE_PRIVILEGED, MZ_MODE_PACKET_DNS, "End DNS configuration mode");

	
   // --------- SEQUENCE COMMANDS
   cli_register_command(cli, NULL, "add", sequence_add, PRIVILEGE_PRIVILEGED, MZ_MODE_SEQUENCE, "Add another packet to the current sequence");
   cli_register_command(cli, NULL, "delay", sequence_delay, PRIVILEGE_PRIVILEGED, MZ_MODE_SEQUENCE, "Add a delay to the current sequence");
   cli_register_command(cli, NULL, "show", sequence_show, PRIVILEGE_PRIVILEGED, MZ_MODE_SEQUENCE, "Show current sequence list");
   cli_register_command(cli, NULL, "remove", sequence_remove, PRIVILEGE_PRIVILEGED, MZ_MODE_SEQUENCE, "Remove a packet or delay from the current sequence");
   cli_register_command(cli, NULL, "end", cmd_end_to_config, PRIVILEGE_PRIVILEGED, MZ_MODE_SEQUENCE, "End sequence configuration mode"); 
   // ---- BENCHMARK CONFIG MODE COMMANDS: ---
   // ---- SCAN CONFIG MODE COMMANDS: ---

   // ---- CONTROL COMMANDS: ----
   cli_register_command(cli, NULL, "terminate", stop_mausezahn, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Terminate the Mausezahn server");
   run = cli_register_command(cli, NULL, "run", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Run previously configured mops instances or sequences");
   cli_register_command(cli, run, "id", cmd_run_id, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Run mops packet(s) by specifying packet identifiers");
   cli_register_command(cli, run, "name", cmd_run_name, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Run mops packet(s) by specifying packet names");
   cli_register_command(cli, run, "sequence", cmd_run_sequence, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Run a packet sequence");
   cli_register_command(cli, run, "all", cmd_run_all, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Run all currently configured mops packet(s)");
   cli_register_command(cli, NULL, "tx", transmit, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Send inline configured packet (legacy mode; not recommended)");
   cli_register_command(cli, NULL, "stop", cmd_stop, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Stop transmission");
   cli_register_command(cli, NULL, "load", cmd_load, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Load commands from a file");

   // ---- SET COMMANDS: -----
   cli_register_command(cli, NULL, "set", cmd_set, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set global Mausezahn parameters");

   // ---- CLEAR COMMANDS: -----
   clear = cli_register_command(cli, NULL, "clear", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Clear something (use '?')");
   cli_register_command(cli, clear, "all", clear_all, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Re-initialize Mausezahn");
   cli_register_command(cli, clear, "packet", clear_packet, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Delete a packet (i. e. MOPS entry)");
   
   // ---- SHOW COMMANDS: -----
   show = cli_register_command(cli, NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show something (use '?')");
   cli_register_command(cli, show, "packet", show_packets, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show defined packets");
// cli_register_command(cli, show, "system", show_system, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show basic system settings");
   cli_register_command(cli, show, "interfaces", show_interfaces, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show detailed interface information");
   cli_register_command(cli, show, "mops", show_mops, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show MOPS details");
// cli_register_command(cli, show, "processes", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all Mausezahn processes");
   cli_register_command(cli, show, "set", show_set, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List general packet parameters");
   cli_register_command(cli, show, "arp", show_arp, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show the advanced Mausezahn ARP table");

// cli_register_command(cli, show, "report", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Print reports");

   // ---- PRIVILEGE (OTHER) ----
   reset = cli_register_command(cli, NULL, "reset", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Reset something...");
    cli_register_command(cli, reset, "interface", cmd_reset_interface, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Reset interfaces");
    cli_register_command(cli, reset, "packet", cmd_reset_packet, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Reset interfaces");
   // ------- LAUNCH ------
   launch = cli_register_command(cli, NULL, "launch", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch a predefined MOPS process");
    cli_register_command(cli, launch, "bpdu", launch_bpdu, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch a(nother) BPDU process");
    cli_register_command(cli, launch, "synflood", launch_synflood, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch a(nother) SYN-Flood process");
//    cli_register_command(cli, launch, "alot", launch_alot, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch lots of traffic");
//    cli_register_command(cli, launch, "rtp", launch_rtp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch rtp stream(s)");
//    cli_register_command(cli, launch, "arp", launch_arp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch a(nother) ARP process");
//    cli_register_command(cli, launch, "lldp", launch_lldp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Launch a(nother) LLDP process");
	
	
   // *******************************************************
   
   // Create a socket
   s = socket(AF_INET, SOCK_STREAM, 0);
   setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

   // Should we bind the CLI session to a specific interface?
   // TODO: This does nothing !?
   for (i=0; i<device_list_entries; i++) {
	   if (device_list[i].cli) {
		   setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, device_list[i].dev, strnlen(device_list[i].dev, 16));
		   break; // can only be one interface
	   }
   }
   
   // Listen on port mz_port (default: 25542, towel day)
   memset(&servaddr, 0, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   inet_aton(mz_listen_addr, &servaddr.sin_addr);
   servaddr.sin_port = htons(mz_port); 
   bind(s, (struct sockaddr *)&servaddr, sizeof(servaddr));

   if (!quiet) {
                       fprintf(stderr, "Mausezahn accepts incoming Telnet connections on %s:%i.\n",  mz_listen_addr, mz_port);
               }

   // Wait for a connection
   listen(s, 50);

   while ((x = accept(s, NULL, 0)))
     {
	if (!quiet)
	  {
	     cnt++;
	     timestamp_human(TimeStamp, NULL);
	     fprintf(stderr, "Got incoming connection [%i] at %s.\n", cnt, TimeStamp);
	     fflush(stderr);
	  }
	
	// Pass the connection off to libcli
	cli_loop(cli, x);
	
	if (!quiet)
	  {
	     timestamp_human(TimeStamp, NULL);
	     fprintf(stderr, "Connection [%i] left at %s.\n", cnt, TimeStamp);
	  }
	
	close(x);
     }
   
   // Free data structures
   cli_done(cli);

   return 0;
}
예제 #29
0
int main(int argc, char *argv[])
{
	int result;
	int opt;
	int arg = 1;
	static char *exit_cmd[] = { "exit", NULL };
	char *hist_size;

	strcpy(server, "localhost");

	cli_init("ippool");
	result = cli_add_commands(&cmds[0]);
	if (result < 0) {
		fprintf(stderr, "Application initialization error.\n");
		return result;
	}

	cl = clnt_create(server, IPPOOL_PROG, IPPOOL_VERSION, "udp");
	if (cl == NULL) {
		clnt_pcreateerror(server);
		exit(1);
	}
	atexit(cleanup);

	opterr = 0;		/* no error messages please */

	opt = getopt(argc, argv, "qR:");
	switch (opt) {
	case 'q':
		opt_quiet = 1;
		arg++;
		break;
	case 'R':
		strncpy(server, optarg, sizeof(server));
		arg += 2;
		ippool_set_prompt(server);
		break;
	default:
		break;
	}

	/* If user supplied arguments, send them to the CLI now and immediately exit.
	 */
	if (argc > arg) {
		(void) cli_execute(argc - arg, &argv[arg]);
		(void) cli_execute(1, exit_cmd);
	} else {
		/* interactive mode */
		interactive = 1;
		ippool_histfile = getenv("IPPOOL_HISTFILE");
		if (ippool_histfile == NULL) {
			ippool_histfile = "~/.ippool_history";
		}
		hist_size = getenv("IPPOOL_HISTFILESIZE");
		if (hist_size != NULL) {
			ippool_histfile_maxsize = strtoul(hist_size, NULL, 0);
		}

		cli_read_history_file(ippool_histfile);
		cli_run();
	}

	return 0;
}
예제 #30
0
int main(int argc, char *argv[])
{
    cli_init();
    log_init();
    thread_init();
    cmd_init();
    dev_addr_mgr_init();
    addr_sock_init();
    socket_init();
    dev_router_init();
    cli_commands_init();

    broadcast_msg_t msg;
    dev_addr_mgr_add_support_dev_type(1);
    dev_addr_mgr_set_network_type(NETWORK_TYPE_CENTER);
    dev_addr_mgr_set_addr_mac(0x89ABCDE0);

    dev_router_set_mac_local(0x89ABCDE0);

#ifdef TEST_CLIENT
    ex_memzero_one(&msg);
    strcpy(msg.dev_name, "1004");
    msg.router_list_lens[0] = 3;
    msg.router_list_lens[1] = 3;
    msg.router_list_lens[2] = 0;
    msg.router_list_lens[3] = 0;
    msg.router_cnt = 7;
    msg.router_list_cnt = 2;
    msg.network_nodes[0].dev_type = 1;
    msg.network_nodes[0].addr_mac = 0x89ABCDE0;
    msg.network_nodes[0].subnet_cnt = 4;
    msg.network_nodes[0].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[0].dev_name, "1004");

    msg.network_nodes[1].dev_type = 1;
    msg.network_nodes[1].addr_mac = 0x89ABCDE1;
    msg.network_nodes[1].subnet_cnt = 4;
    msg.network_nodes[1].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[1].dev_name, "1003");

    msg.network_nodes[2].dev_type = 1;
    msg.network_nodes[2].addr_mac = 0x89ABCDE2;
    msg.network_nodes[2].subnet_cnt = 4;
    msg.network_nodes[2].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[2].dev_name, "1002");

    msg.network_nodes[3].dev_type = 1;
    msg.network_nodes[3].addr_mac = 0x89ABCDE3;
    msg.network_nodes[3].subnet_cnt = 4;
    msg.network_nodes[3].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[3].dev_name, "1001");

    msg.network_nodes[4].dev_type = 1;
    msg.network_nodes[4].addr_mac = 0x89ABCDE4;
    msg.network_nodes[4].subnet_cnt = 4;
    msg.network_nodes[4].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[4].dev_name, "1005");

    msg.network_nodes[5].dev_type = 1;
    msg.network_nodes[5].addr_mac = 0x89ABCDE5;
    msg.network_nodes[5].subnet_cnt = 4;
    msg.network_nodes[5].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[5].dev_name, "1006");

    msg.network_nodes[6].dev_type = 1;
    msg.network_nodes[6].addr_mac = 0x89ABCDE6;
    msg.network_nodes[6].subnet_cnt = 4;
    msg.network_nodes[6].network_type = NETWORK_TYPE_ROUTER;
    strcpy(msg.network_nodes[6].dev_name, "1007");
#endif

    socket_listen_async(50002);
    socket_listen_cli(49999);
    socket_recv_start();
#ifdef TEST_SERVER
    socket_bc_tx_start("test", 50000, 50001, 50002);
#endif
#ifdef TEST_CLIENT
    socket_bc_rx_start("test", 50000, 50001, &msg);
#endif

#if 0
    cstr *json = cstr_new();
    int fd = 0;
    fd = socket_cli_send_request("127.0.0.1", 49999, "test");
    socket_cli_recv_response(fd, json);
    cstr_clear(json);
    fd = socket_cli_send_request("127.0.0.1", 49999, "test f**k");
    socket_cli_recv_response(fd, json);
    cstr_clear(json);
    fd = socket_cli_send_request("127.0.0.1", 49999, "f**k f**k f**k you test f**k");
    socket_cli_recv_response(fd, json);
    cstr_free(json);
#endif

    cli_loop();

    dev_addr_mgr_release();
    socket_release();
    cmd_release();
    thread_release();
    log_release();
    cli_release();
#if 0
  cli_cmd_t cmd;
  int i = 0;

  command_init(&cmd, argv[0], "0.0.1");
  command_option(&cmd, "-v", "--verbose", "enable verbose stuff", verbose);
  command_option(&cmd, "-r", "--required <arg>", "required arg", required);
  command_option(&cmd, "-o", "--optional [arg]", "optional arg", optional);
  command_parse(&cmd, argc, argv);
  printf("additional args:\n");
  for (i = 0; i < cmd.argc; ++i) {
    printf("  - '%s'\n", cmd.argv[i]);
  }
  command_free(&cmd);
#endif
    return 0;
}