int main(int argc, char **argv) { WSADATA wsa; subnet sub; int ret, x; WSAStartup(0x22, &wsa); fprintf(stderr, "CIDR Reverse DNS - William Welna ([email protected])\n\n"); if(argc != 3) { fprintf(stderr, "No Range Specified and/or no output file or too many arguments\n"); fprintf(stderr, "Usage: %s 127.0.0.0/24 localrdns.txt\n", argv[0]); exit(0); } if(ret=ares_library_init(ARES_LIB_INIT_ALL)!=ARES_SUCCESS) { fprintf(stderr, "ares_library_init() failed %i\n", ret); exit(0); } if(ret=ares_init(&ares_chan)!=ARES_SUCCESS) { fprintf(stderr, "ares_init() failed %i\n", ret); exit(0); } calculate_subnet(argv[1], &sub); build_ips(sub.addr_s, sub.addr_e); global_total = sub.total_ips; for(x=0; x < 60 && IPS_P != NULL; ++x, IPS_P=IPS_P->n) ares_gethostbyaddr(ares_chan, &IPS_P->ip, 4, AF_INET, rdns_callback, IPS_P); fprintf(stderr, "Resolving %s to %s (%i)\n", sub.ip_s, sub.ip_e, sub.total_ips); tehloop(); dump_results(argv[2]); return 0; }
/*! this is a straight forward main function, that does the following - load lua config file - get configuration table from config - contruct a preferences class from them - start simulation according to the preferences - dump the result as precified in preferences */ int main(int argc, char * argv[argc]) { fftw_init_threads(); fftw_plan_with_nthreads(4); if (argc != 3) { fprintf(stderr, "usage: %s config.lua result.dat\n", argv[0]); return -1; } lua_State * L = luaL_newstate(); luaL_openlibs(L); preferences_t * prefs = preferences_new(); if (luaL_dofile(L, argv[1])) { fprintf(stderr, "could not load '%s' : %s\n", argv[1], lua_tostring(L, 1)); } else { // get config table lua_getfield(L, LUA_GLOBALSINDEX, "config"); if (lua_isnil(L, -1)) { fprintf(stderr, "table config undefined\n"); } else { // ref config table, so we can access it in preferences_read() prefs->config = luaL_ref(L, LUA_REGISTRYINDEX); if (!preferences_read(L, prefs)) { if (!start_simulation(prefs)) { FILE * fp = fopen(argv[2], "wb"); assert(fp); dump_results(prefs, fp); fclose(fp); } } } } preferences_free(prefs); lua_close(L); fftw_cleanup(); fftw_cleanup_threads(); pthread_exit(NULL); }
void count_main(int argc, char **argv) { Timer *total_timer = new Timer("count_main"); parse_count_options(argc, argv); std::istream* probes_stream; probes_stream = (opt::probes_file == "-") ? &std::cin : createReader(opt::probes_file); /* Load probes */ ss_probes probes; int probe_length; std::cerr << ">> Loading probes " << std::endl; probes.set_empty_key("-"); load_probes(probes, probes_stream); std::cerr << ">> # of probes (RC included): " << probes.size() << std::endl; probe_length = probes.begin()->first.length(); /* Process reads */ std::string **buffer; /* request mem for buffer of reads */ buffer = (std::string **) calloc(sizeof(std::string *), BUFFER_SIZE); int n_rr = 0; // number of reads read int total = 0; // total number of reads processed SeqReader reader(opt::reads_file, SRF_NO_VALIDATION); while((n_rr = load_to_buffer(&reader, buffer)) != 0) { Timer *pr_timer = new Timer("Processing reads"); std::cerr << ">> Computing screen on " << n_rr << " reads" << std::endl; total += n_rr; pthread_t *tid; pthread_attr_t attr; thread_data *data; unsigned int j; // to iterate over num of threads pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); data = (thread_data*) calloc(opt::n_threads, sizeof(thread_data)); tid = (pthread_t*) calloc(opt::n_threads, sizeof(pthread_t)); /* create/init mutex */ pthread_mutex_t mutex; pthread_mutex_init(&mutex, NULL); for (j=0; j<opt::n_threads; ++j) { data[j].n_reads = n_rr; data[j].tid = j; data[j].buffer = buffer; data[j].probes = &probes; data[j].p_len = probe_length; data[j].mutex = &mutex; data[j].n_threads = opt::n_threads; pthread_create(&tid[j], &attr, worker, data+j); } /* join-start threads */ for (j=0; j<opt::n_threads; ++j) pthread_join(tid[j], 0); std::cerr << ">> Done computing " << n_rr << " reads" << std::endl; std::cerr << ">> Total # of reads processed so far: " << total << std::endl; free(data); free(tid); delete pr_timer; // force dump cpu time. } dump_results(probes); free_up_probes(probes); delete probes_stream; for (int j=0; j<BUFFER_SIZE; j++) delete buffer[j]; free(buffer); delete total_timer; }
int main(int argc, char *argv[]) { int i, ch, count; struct timeval before, after; unsigned long elapsed; int use_lwps = 0; memset(elapsed_times, 0, ITERATIONS); while ((ch = getopt(argc, argv, "hl")) != -1) { switch (ch) { case 'l': #if defined(LWP) use_lwps = 1; #else errx(1, "not supported"); #endif break; case 'h': usage(); } } argc -= optind; argv += optind; sleep(1); if (pipe(fd0) != 0) errx(1, "Unable to create pipe"); if (pipe(fd1) != 0) errx(1, "Unable to create pipe"); /* * Determine overhead */ for (count=0; count<2; count++) { gettimeofday(&before, NULL); for (i=0; i<2*(PASSES/2); i++) { ch = 0; write(fd0[1], &ch, 1); read(fd0[0], &ch, 1); } gettimeofday(&after, NULL); overhead = 1000000 * (after.tv_sec - before.tv_sec); overhead += after.tv_usec - before.tv_usec; } if (use_lwps) { #if defined(LWP) ucontext_t u; ucontext_t *contextp; int stacksize = 65536; void *stackbase; lwpid_t l; int error; getcontext(&u); contextp = (ucontext_t *)malloc(sizeof(ucontext_t)); stackbase = malloc(stacksize); sigprocmask(SIG_SETMASK, NULL, &contextp->uc_sigmask); _lwp_makecontext(contextp, child, NULL, NULL, stackbase, stacksize); error = _lwp_create(contextp, 0, &l); if (error) errx(1, "error _lwp_create"); #endif } else { switch (childpid = fork()) { case 0: /* child */ child(); case -1: /* error */ errx(1, "error forking"); break; } } ch = 0; if (read(fd1[0], &ch, 1) != 1) errx(1, "parent read failed"); for (count=0; count<ITERATIONS; count++) { gettimeofday(&before, NULL); for (i=0; i<PASSES/2; i++) { ch = 0; if (write(fd0[1], &ch, 1) != 1) errx(1, "parent write failed"); if (read(fd1[0], &ch, 1) != 1) errx(1, "parent read failed"); } gettimeofday(&after, NULL); elapsed = 1000000 * (after.tv_sec - before.tv_sec); elapsed += after.tv_usec - before.tv_usec; elapsed_times[count] = elapsed; } if (!use_lwps) kill(childpid, SIGTERM); dump_results(); return (0); }