int do_image_size(const std::vector<char *> &arg) { const IceTSizeType begin_size = 2048; const IceTSizeType end_size = 2048; int result = 0; for (IceTSizeType dim = begin_size; dim <= end_size; dim *= 2) { SCREEN_WIDTH = SCREEN_HEIGHT = dim; result += do_collect(arg); } return result; }
int main (int argc, char *argv[]) { char arg; /* short options: character */ int loptidx=0; /* long options: arg==0 and index */ char opt[] = "64stuhl:p:vo:f:"; #ifdef HAVE_GETOPT_LONG struct option lopt[] = { { "dbhost", 1, 0, 0}, { "dbname", 1, 0, 0}, { "dbuser", 1, 0, 0}, { "dbpw", 1, 0, 0}, { "db", 0, 0, 0}, { "ssl", 0, 0, 0}, { "key", 1, 0, 0}, { "cert", 1, 0, 0}, { "cafile", 1, 0, 0}, { "cadir", 1, 0, 0}, { "help", 0, 0, 0}, { 0, 0, 0, 0 } }; #endif /** set default options */ par.tcp = 0; par.udp = 0; par.sctp = 0; par.ssl = 0; par.cafile = CAFILE; par.cadir = CADIR; par.keyfile = KEYFILE; par.certfile= CERTFILE; par.port = 0; par.family = AF_UNSPEC; par.logfile = NULL; par.maxcon = 10; par.datadir = NULL; par.datafile = NULL; par.dbexport = 0; par.dbhost = DFLT_MYSQL_HOST; par.dbname = DFLT_MYSQL_DBNAME; par.dbuser = DFLT_MYSQL_USER; par.dbpw = DFLT_MYSQL_PASSWORD; snprintf( par.progname, sizeof(par.progname), "%s", basename( argv[0]) ); /* --- command line parsing --- */ #ifdef HAVE_GETOPT_LONG while ((arg=getopt_long( argc, argv, opt, lopt, &loptidx)) >=0 ) #else while( (arg=getopt( argc, argv, opt )) != EOF ) #endif { switch (arg) { case 0: switch (loptidx) { case 0: /* dbhost */ par.dbhost = optarg; break; case 1: /* dbname */ par.dbname = optarg; break; case 2: /* dbuser */ par.dbuser = optarg; break; case 3: /* dbpw */ par.dbpw = optarg; break; case 4: /* db */ par.dbexport = 1; break; case 5: /* ssl */ par.ssl = 1; break; case 6: /* key */ par.keyfile = optarg; break; case 7: /* cert */ par.certfile = optarg; break; case 8: /* cafile */ par.cafile = optarg; break; case 9: /* cadir */ par.cadir = optarg; break; case 10: usage(par.progname); exit(1); } break; case '4': #ifdef INET6 par.family = (par.family==AF_INET6)? AF_UNSPEC : AF_INET; break; case '6': par.family = (par.family==AF_INET)? AF_UNSPEC : AF_INET6; #endif break; case 'd': par.dbexport = 1; break; case 'l': par.logfile = optarg; break; case 's': par.sctp ++; break; case 't': par.tcp ++; break; case 'u': par.udp ++; break; case 'o': par.datadir = optarg; if ( access( optarg, W_OK|X_OK ) <0 ) { fprintf( stderr, "cannot access dir '%s': %s!\n", optarg, strerror(errno) ); exit(1); } break; case 'f': par.datafile = optarg; break; case 'p': if ((par.port=atoi(optarg)) <0) { fprintf( stderr, "Invalid -p argument!\n" ); exit(1); } break; case 'v': verbose_level ++; break; case 'h': default: usage(par.progname); exit(1); } } if ( !par.udp && !par.tcp && !par.sctp ) par.tcp++; if ( !par.dbexport && !par.datadir ) { fprintf( stderr, "info: message dump, no data storage.\n" ); fflush( stderr ); } if ( par.port==0 ) { par.port = par.ssl?IPFIX_TLS_PORTNO:IPFIX_PORTNO; } /** init loggin */ mlog_set_vlevel( verbose_level ); if ( par.logfile ) (void) mlog_open( par.logfile, NULL ); if ( (!par.dbexport && !par.datadir) || (verbose_level >2) ) (void) ipfix_col_start_msglog( stderr ); mlogf( 1, "[%s] listen on port %d, write to %s ...\n", par.progname, par.port, par.dbexport?"database":par.datadir?"files":"stdout" ); /** init ipfix lib */ if ( ipfix_init() <0 ) { fprintf( stderr, "ipfix_init() failed: %s\n", strerror(errno) ); exit(1); } if ( ipfix_add_vendor_information_elements( ipfix_ft_fokus ) <0 ) { fprintf( stderr, "ipfix_add_ie() failed: %s\n", strerror(errno) ); exit(1); } /** signal handler signal( SIGSEGV, sig_func ); */ signal( SIGKILL, sig_func ); signal( SIGTERM, sig_func ); signal( SIGINT, sig_func ); /** do the work */ if ( do_collect() <0 ) exit_func(1); exit_func(0); return 0; }