int scamper_task_init(void) { if((tx_ip = splaytree_alloc(tx_ip_cmp)) == NULL) return -1; if((tx_nd = splaytree_alloc(tx_nd_cmp)) == NULL) return -1; if((sniff = dlist_alloc()) == NULL) return -1; return 0; }
int scamper_addr2mac_init() { if((tree = splaytree_alloc((splaytree_cmp_t)addr2mac_cmp)) == NULL) { return -1; } if(scamper_option_noinitndc() != 0) return 0; #ifdef HAVE_BSD_ARPCACHE if(addr2mac_init_bsd() != 0) { return -1; } #endif #ifdef __linux__ if(addr2mac_init_linux() != 0) { return -1; } #endif #ifdef _WIN32 if(addr2mac_init_win32() != 0) { return -1; } #endif return 0; }
int scamper_outfiles_init(char *def_filename, char *def_type) { if((outfiles = splaytree_alloc(outfile_cmp)) == NULL) { return -1; } if(outfile_opendef(def_filename, def_type) != 0) { return -1; } return 0; }
/* * scamper_fds_init * * setup the global data structures necessary for scamper to manage a set of * file descriptors */ int scamper_fds_init() { #ifdef HAVE_GETDTABLESIZE scamper_debug(__func__, "fd table size: %d", getdtablesize()); #endif #ifdef HAVE_POLL pollfunc = fds_poll; #endif #ifdef HAVE_KQUEUE if(scamper_option_kqueue()) { pollfunc = fds_kqueue; if(fds_kqueue_init() != 0) return -1; } #endif #ifdef HAVE_EPOLL if(scamper_option_epoll()) { pollfunc = fds_epoll; if(fds_epoll_init() != 0) return -1; } #endif if(scamper_option_select() || pollfunc == NULL) pollfunc = fds_select; if((fd_list = alloc_list("fd_list")) == NULL || (read_fds = alloc_list("read_fds")) == NULL || (read_queue = alloc_list("read_queue")) == NULL || (write_fds = alloc_list("write_fds")) == NULL || (write_queue = alloc_list("write_queue")) == NULL || (refcnt_0 = alloc_list("refcnt_0")) == NULL) { return -1; } if((fd_tree = splaytree_alloc(fd_cmp)) == NULL) { printerror(errno, strerror, __func__, "alloc fd tree failed"); return -1; } planetlab = scamper_option_planetlab(); return 0; }
int scamper_firewall_init(char *opt) { if((entries = splaytree_alloc(firewall_entry_cmp)) == NULL) { printerror(errno, strerror, __func__, "could not create entries tree"); return -1; } #if defined(HAVE_IPFW) return ipfw_init(); #else return 0; #endif }
int main(int argc, char *argv[]) { scamper_file_t *file[2]; scamper_file_filter_t *filter; scamper_trace_t *trace; tracepair_t *pair, fm; uint16_t type = SCAMPER_FILE_OBJ_TRACE; char buf[256]; int i, filec_open; #ifdef _WIN32 WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); #endif if(check_options(argc, argv) != 0) goto err; if((filter = scamper_file_filter_alloc(&type, 1)) == NULL) { fprintf(stderr, "could not allocate filter\n"); goto err; } memset(file, 0, sizeof(file)); for(i=0; i<filec; i++) { if((file[i] = scamper_file_open(files[i], 'r', NULL)) == NULL) { fprintf(stderr, "could not open %s\n", files[i]); goto err; } } filec_open = filec; if((pairs = splaytree_alloc(tracepair_cmp)) == NULL) { fprintf(stderr, "could not alloc tracepair tree\n"); goto err; } splaytree_onremove(pairs, (splaytree_onremove_t)tracepair_onremove); while(filec_open != 0) { for(i=0; i<filec; i++) { if(file[i] == NULL) continue; if(scamper_file_read(file[i], filter, &type, (void *)&trace) != 0) { fprintf(stderr, "could not read from %s\n", files[i]); goto err; } if(trace == NULL) { filec_open--; scamper_file_close(file[i]); continue; } assert(type == SCAMPER_FILE_OBJ_TRACE); fm.tracec = 1; fm.traces[0] = trace; if((pair = splaytree_find(pairs, &fm)) == NULL) { if((pair = malloc_zero(sizeof(tracepair_t))) == NULL) goto err; pair->traces[i] = trace; pair->tracec = 1; if((pair->node = splaytree_insert(pairs, pair)) == NULL) goto err; } else { if(pair->traces[i] != NULL) { fprintf(stderr, "repeated trace for %s\n", scamper_addr_tostr(trace->dst, buf, sizeof(buf))); goto err; } pair->traces[i] = trace; pair->tracec++; } if(pair->tracec != filec) continue; splaytree_remove_node(pairs, pair->node); tracepair_process(pair); tracepair_free(pair); } } return 0; err: return -1; }