// start int main(int argc, char *argv[]) { mhdd_debug_init(); struct fuse_args *args = parse_options(argc, argv); flist_init(); return fuse_main(args->argc, args->argv, &mhdd_oper, 0); }
int datastream_init (datastream_t *datastream, void *context, uint32_t size, datastream_feed_func feed_func) { int error; if (unlikely(datastream == NULL)) LOG_ERROR_AND_RETURN(-1, "null datasttream_t"); if (unlikely(NULL == (datastream->data = malloc(size)))) LOG_ERROR_AND_RETURN(-101, "failed to malloc(%u), %s", size, strerror(errno)); if (unlikely(0 != (error = flist_init(&datastream->queue, 100, NULL)))) LOG_ERROR_AND_RETURN(-102, "failed to flist_init, %d", error); if (unlikely(0 != (error = thread_init(&datastream->thread, "datastream-thread", (thread_start_func)__datastream_thread, datastream, NULL)))) LOG_ERROR_AND_RETURN(-103, "failed to thread_init, %d", error); datastream->size = size; datastream->stop = 0; datastream->context = context; datastream->feed = feed_func; memset(datastream->data, 0, size); if (unlikely(0 != (error = thread_start(&datastream->thread)))) LOG_ERROR_AND_RETURN(-103, "failed to thread_start, %d", error); return 0; }
int main (void) { struct flist new_flist; flist_init(&new_flist); return 0; }
// start int main(int argc, char *argv[]) { mhdd_debug_init(); struct fuse_args *args = parse_options(argc, argv); flist_init(); limits_init(); signal(SIGSEGV, save_backtrace); return fuse_main(args->argc, args->argv, &mhdd_oper, 0); }
void initSet(struct anonflow *flow) { int i; struct sourceinfo *info; memset(flow, 0, sizeof(struct anonflow)); flow->output_type = NONE; flow->output_filename = NULL; flow->cont_set = 0; flow->nf9_templates = malloc(sizeof(flist_t)); flow->nf9_option_templates = malloc(sizeof(flist_t)); flist_init(flow->nf9_templates); flist_init(flow->nf9_option_templates); flow->ipfix_templates = malloc(sizeof(flist_t)); flow->ipfix_options = malloc(sizeof(flist_t)); flist_init(flow->ipfix_templates); flist_init(flow->ipfix_options); for (i = 0; i < MAX_CONT; i++) flow->give_output[i] = -1; info = search_for_registered_source(source_type); if (!info) { printf("Unknown source type in initSet\n"); return; } if (info->init_input) { info->init_input(flow); } binaryGenericWgetInit(); binaryGenericXORInit(); binaryStuttgartInit(); binaryWuerzburgInit(); }
int delete_files(char *name) { char tmp_name[CCHMAXPATHCOMP]; struct flist_root root; FILE_COUNT curfile; flist_init(&root, FCLIM_DELETION, FL_STANDARD); if(flist_add_files(&root, NULL, name, 1, 0, FETCH_FILES, NULL)) return(1); for(curfile=0; curfile<root.files; curfile++) { flist_retrieve(tmp_name, NULL, &root, curfile); msg_cprintf(0, M_DELETING, tmp_name); if(is_directory(tmp_name)?file_rmdir(tmp_name):file_unlink(tmp_name)) msg_cprintf(H_ERR, M_CANT_DELETE, tmp_name); } flist_cleanup(&root); return(0); }
static void init() //common initialization function for mapi and dimapi { // set up globals if (drvglobals == NULL) { drvglobals = malloc(sizeof(struct flowdrv_globals)); drvglobals->minit = &minit; drvglobals->mapi_lock = &mapi_lock; drvglobals->local_err = &local_err; drvglobals->agent = &agent; drvglobals->flowlist = &flowlist; drvglobals->fd_counter = &fd_counter; drvglobals->localdrv = &localdrv; drvglobals->remotedrv = &remotedrv; drvglobals->get_numflows = get_numflows; drvglobals->incr_numflows = incr_numflows; drvglobals->decr_numflows = decr_numflows; drvglobals->get_totalflows = get_totalflows; drvglobals->incr_totalflows = incr_totalflows; } // TODO/XXX: read flowdrivers from conf file? can default to libmapi_local/remote.so if no conf is found. // Load local driver localdrv = (void *) dlopen("libmapi_local.so", RTLD_NOW); if (localdrv == NULL) { local_err = 0; // FIXME: Add MAPI_INIT_LOADING_DRIVER printf("ERROR: Could not load local driver (libmapi_local.so).\n"); printf("Aborting...\n"); exit(1); } flowdrv_setglobals = drv_get_funct(localdrv, "flowdrv_setglobals"); if (flowdrv_setglobals == NULL) { local_err = 0; // FIXME: add error constant printf("ERROR: Could not initialize driver.\n"); printf("Aborting...\n"); exit(1); } (*flowdrv_setglobals)(drvglobals); #ifdef DIMAPI // Load remote driver remotedrv = (void *) dlopen("libmapi_remote.so", RTLD_NOW); if (remotedrv == NULL) { local_err = 0; // FIXME: see previous printf("ERROR: Could not load remote (DiMAPI) driver (libmapi_remote.so).\n"); printf("Aborting...\n"); // XXX: Should we just continue? it does have local loaded. exit(1); } flowdrv_setglobals = drv_get_funct(remotedrv, "flowdrv_setglobals"); if (flowdrv_setglobals == NULL) { local_err = 0; // FIXME: add error constant printf("ERROR: Could not initialize driver.\n"); printf("Aborting...\n"); exit(1); } (*flowdrv_setglobals)(drvglobals); #endif flowdrv_setglobals = NULL; // Don't free drvglobals here, that will break offline processing. printf("INIT2\n"); minit = 1; flowlist = malloc(sizeof(flist_t)); flist_init(flowlist); }
void process_packet(unsigned char *packet, anon_pkthdr_t * header, int cont) { struct anonflow *flow; struct function *flist; int i = 0, j = 0, jcnt = 0, uncook_done; anon_pkthdr_t *hd_temp_1 = malloc(sizeof(anon_pkthdr_t)); anon_pkthdr_t *hd_temp_2 = NULL; unsigned char *temp_packet_buf = malloc(NIC_PKTCAP_LEN * sizeof(unsigned char)); unsigned char *temp_packet_buf2 = NULL; while (flowArray[i] != NULL && i < MAX_NUM_OF_SETS) { flow = flowArray[i]; if ((cont != i) && (cont != -1)) { i++; continue; } if (flow->cont_set && (cont == -1)) { i++; continue; } flist = flow->function_list; flow->decoded_packet = NULL; flow->client_headers = NULL; flow->server_headers = NULL; memcpy(temp_packet_buf, packet, header->caplen); memcpy(hd_temp_1, header, sizeof(anon_pkthdr_t)); if (flow->modifies && flow->mod_pkt != (unsigned char *)(&modified_packet_buf[0])) { free(flow->mod_pkt); flow->mod_pkt = &modified_packet_buf[0]; } if (flow->modifies) { //if we have cooking we have to copy the packet to flow->mod_pkt memcpy(modified_packet_buf, packet, header->caplen); memcpy(&flow->mod_pkt_head, header, sizeof(anon_pkthdr_t)); flow->mod_pkt = &modified_packet_buf[0]; if (flow->server_mod_pkt) { free(flow->server_mod_pkt); flow->server_mod_pkt = NULL; } } uncook_done = 0; while (flist) { if (flow->modifies) { if (flist->function_info-> process(flow, flist->internal_data, flow->mod_pkt, &flow->mod_pkt_head) == 0) { break; } } else { if (flist->function_info-> process(flow, flist->internal_data, temp_packet_buf, hd_temp_1) == 0) { break; } } if (flow->uncook_ready == 1) { uncook_done = 1; do_uncook_loop(flow, flist); break; } else { flist = flist->next; } } if (flow->client_headers) { free_header_list(flow->client_headers, FLIST_FREE_DATA); flist_init(flow->client_headers); } if (flow->server_headers) { if (uncook_done) free_header_list(flow->server_headers, FLIST_LEAVE_DATA); else free_header_list(flow->server_headers, FLIST_FREE_DATA); flist_init(flow->server_headers); } for (j = 0; j < MAX_CONT; j++) { if (flow->give_output[j] != -1) { temp_packet_buf2 = malloc(NIC_PKTCAP_LEN * sizeof(unsigned char)); hd_temp_2 = malloc(sizeof(anon_pkthdr_t)); jcnt++; memcpy(temp_packet_buf2, temp_packet_buf, header->caplen); memcpy(hd_temp_2, hd_temp_1, sizeof(anon_pkthdr_t)); process_packet(temp_packet_buf2, hd_temp_2, flow->give_output[j]); } } if (jcnt == 0) { if (flist == NULL && flow->output_type != NONE) { //Flow reached its end if (flow->modifies) { dump_packet(flow, flow->mod_pkt, &flow->mod_pkt_head); } else { dump_packet(flow, temp_packet_buf, hd_temp_1); } } } i++; } if (temp_packet_buf) { free(temp_packet_buf); temp_packet_buf = NULL; } if (temp_packet_buf2) { free(temp_packet_buf2); temp_packet_buf2 = NULL; } if (hd_temp_1) { free(hd_temp_1); hd_temp_1 = NULL; } if (hd_temp_2) { free(hd_temp_2); hd_temp_2 = NULL; } }
int flowdrv_create_flow(const char *dev) //Create new flow //dev = device that should be used { struct mapiipcbuf qbuf; flowdescr_t *flow, *tmpflow; pthread_once(&mapi_is_initialized, (void*)mapi_init); while(__sync_lock_test_and_set(mapi_lock,1)); if (((*get_numflows)() == 0) && ((*get_totalflows)() > 0) && *minit){ // socket has been closed, re-create it if(mapiipc_client_init() == -1) { *local_err = MCOM_INIT_SOCKET_ERROR; *mapi_lock = 0; return -1; } (*incr_numflows)(); } else (*incr_numflows)(); *mapi_lock = 0; strncpy((char *)qbuf.data,dev,DATA_SIZE); qbuf.mtype = 1; qbuf.cmd = CREATE_FLOW; qbuf.fd = getpid(); qbuf.pid = getpid(); while(__sync_lock_test_and_set(mapi_lock,1)); if (mapiipc_write((struct mapiipcbuf*)&qbuf) < 0) { *local_err = MCOM_SOCKET_ERROR; *mapi_lock = 0; (*decr_numflows)(); return -1; } if (mapiipc_read((struct mapiipcbuf*)&qbuf) < 0) { *local_err = MCOM_SOCKET_ERROR; *mapi_lock = 0; (*decr_numflows)(); return -1; } *mapi_lock = 0; switch(qbuf.cmd) { case CREATE_FLOW_ACK: tmpflow = flist_get(*flowlist, qbuf.fd); if (tmpflow != NULL) { printf("ERROR: Mapid gave us a fd (%d) which already exist in our lists, exiting [%s:%d]\n", qbuf.fd, __FILE__, __LINE__); (*decr_numflows)(); return -1; } flow = malloc(sizeof(flowdescr_t)); if (flow == NULL) { printf("ERROR: Out of memory [%s:%d]\n", __FILE__, __LINE__); (*decr_numflows)(); return -1; } flow->fd = qbuf.fd; flow->devtype = (char *) malloc(strlen((char *)qbuf.data) + 1); flow->flist = malloc(sizeof(flist_t)); flow->shm_base = NULL; flow->shm_spinlock = NULL; flow->file = -1; // in case of online flow, assigned to -1 flow->is_connected = 0; flow->numfd = 0; // initialize number of open file descriptors to zero flist_init(flow->flist); strcpy(flow->devtype, (char *)qbuf.data); flowlist_t *flow_item = malloc(sizeof(flowlist_t)); if (flow_item == NULL) { printf("ERROR: Out of memory [%s:%d]\n", __FILE__, __LINE__); (*decr_numflows)(); return -1; } while(__sync_lock_test_and_set(mapi_lock,1)); flow_item->fd = ++(*fd_counter); flow_item->flowtype = FLOWTYPE_LOCAL; flow_item->driver = *localdrv; // get_driver ? flow_item->flowdescr = flow; flist_append(*flowlist, *fd_counter, flow_item); (*incr_totalflows)(); *mapi_lock = 0; return *fd_counter; /* should probably have a separate error message for ERROR_ACK? */ case ERROR_ACK: (*decr_numflows)(); *local_err = qbuf.remote_errorcode; return -1; default: (*decr_numflows)(); *local_err = MCOM_UNKNOWN_ERROR; return -1; } }
static void cmd_create_offline_device(char *dev, int format, int pid, int sock) //Create a new flow //dev = device //if = IPC id used to send ack message back to client { struct mapiipcbuf buf; mapidrv *drv, *drv2, *lok; int err; int file; struct client *cl; char *format_; long file_size; //Get file descriptor buf.mtype = pid; buf.cmd = SEND_FD; mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock); file = mapiipc_read_fd(sock); //Decide which driver to use for (drv = drvlist; drv != NULL; drv = drv->next) { if (drv->format == format) { DEBUG_CMD(Debug_Message("Using driver %s for %s", drv->name, dev)); break; } } if (drv == NULL) { DEBUG_CMD(Debug_Message("ERROR: No driver found for %s", dev)); report_error(MAPID_NO_DRIVER, pid, sock); return; } //Calls driver //First create new "device" for the file drv2 = malloc(sizeof(mapidrv)); drv2->device = malloc(strlen(dev)+7); sprintf(drv2->device, "%s@%d", dev, deviceid); lok=drvlist; while (lok->next!=NULL) lok = lok->next; lok->next = drv2; drv2->next=NULL; drv2->handle = drv->handle; drv2->name = strdup(drv->name); drv2->format = drv->format; drv2->devid = -deviceid++; drv2->offline = 1; drv2->active = 1; drv2->description = strdup(drv->description); drv2->offline_status = DEVICE_SETUP; mapidrv_add_device = get_drv_funct(drv->handle, "mapidrv_add_device"); err = mapidrv_add_device(dev, file, drv2->devid, gflist, &drv2->offline_status); if (err != 0) { report_error(err, pid, sock); return; } // save a reference to the newly created flow to client's flow list cl = flist_get(clientlist, pid); if (cl == NULL) { cl = (struct client *) malloc(sizeof(struct client)); cl->pid = pid; cl->sock = sock; // init the list that holds references to the flows of this client if ((cl->flowlist = malloc(sizeof(flist_t))) == NULL) { DEBUG_CMD(Debug_Message( "ERROR: cmd_create_flow - malloc new client struct: %s", strerror(errno))); exit(EXIT_FAILURE); } if ((cl->devicelist = malloc(sizeof(flist_t))) == NULL) { DEBUG_CMD(Debug_Message( "ERROR: cmd_create_flow - malloc new client struct: %s", strerror(errno))); exit(EXIT_FAILURE); } flist_init(cl->flowlist); flist_init(cl->devicelist); cl->numflows = 0; flist_append(clientlist, pid, cl); } flist_append(cl->devicelist, drv2->devid, drv->handle); cl->numdevs++; //Send ack back to user buf.mtype = pid; buf.cmd = CREATE_OFFLINE_DEVICE_ACK; strcpy((char *)buf.data, drv2->device); buf.fd = -1; if (format == 0) format_ = strdup("MFF_PCAP"); else if (format == 1) format_ = strdup("MFF_RAW"); else if (format == 2) format_ = strdup("MFF_DAG_ERF"); else if (format == 4) format_ = strdup("MFF_NAPATECH"); if (log_to_file) { file_size = acquire_write_lock(log_fd_info); write_to_file( log_fd_info, "MAPID: new offline device was created ( tracefile: %s, format: %s, device name returned: %s ) at ", dev, format_, buf.data); write_date(log_fd_info); write_newline(log_fd_info, "\n"); release_write_lock(log_fd_info, file_size); } if (log_to_syslog) log_message( "new offline device was created ( tracefile: %s, format: %s, device name returned: %s )", dev, format_, buf.data); free(format_); mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock); }
static void cmd_create_flow(char *device, int pid, uid_t uid, int sock) /*removed id, id==pid here */ //Create a new flow //dev = device //if = IPC id used to send ack message back to client { struct flow *fl = (struct flow *) malloc(sizeof(struct flow)); struct client *cl; struct mapiipcbuf buf; char *devtype; mapidrv *drv; int err = 0; char* dev=device; long file_size; fl->id = pid; fl->fd = ++fdseed; fl->drv = NULL; fl->uid = uid; fl->offline = 0; if (running_shutdown) err = MAPI_SHUTTING_DOWN; //Decide which driver to use for (drv = drvlist; drv != NULL; drv = drv->next) { if (drv->device != NULL) if (strcmp(dev, drv->device) == 0) { fl->drv = drv; DEBUG_CMD(Debug_Message("Using driver %s for %s", drv->name, dev)); break; } } if (fl->drv == NULL) { DEBUG_CMD(Debug_Message("No driver found for %s", dev)); report_error(MAPID_NO_DRIVER, pid, sock); free(fl); return; } ++flows; //total number of currently registered flows //Calls driver if (err == 0) { mapidrv_create_flow = get_drv_funct(fl->drv->handle, "mapidrv_create_flow"); err = mapidrv_create_flow(drv->devid, fl->fd, &devtype); } if (err != 0) { /* flow wasn't created */ /* we can't leave the flow in place, but we need it for errno... */ /* cleanup? */ flows--; report_error(err, pid, sock); free(fl); return; } else { flist_append(flowlist, fl->fd, fl); //check if this is the first time we hear from this client cl = flist_get(clientlist, pid); if (cl == NULL) { cl = (struct client *) malloc(sizeof(struct client)); cl->pid = pid; cl->sock = sock; // init the list that holds references to the flows of this client if ((cl->flowlist = malloc(sizeof(flist_t))) == NULL) { DEBUG_CMD(Debug_Message( "ERROR: cmd_create_flow - malloc new client struct: %s", strerror(errno))); exit(EXIT_FAILURE); } flist_init(cl->flowlist); if ((cl->devicelist = malloc(sizeof(flist_t))) == NULL) { DEBUG_CMD(Debug_Message( "ERROR: cmd_create_flow - malloc new client struct: %s", strerror(errno))); exit(EXIT_FAILURE); } flist_init(cl->devicelist); cl->numflows = 0; cl->numdevs = 0; flist_append(clientlist, pid, cl); } // save a reference to the newly created flow to client's flow list cl->numflows++; flist_append(cl->flowlist, fl->fd, fl); //Send ack back to user buf.mtype = pid; strcpy((char *)buf.data, devtype); buf.cmd = CREATE_FLOW_ACK; buf.fd = fl->fd; if (log_to_file) { file_size = acquire_write_lock(log_fd_info); write_to_file(log_fd_info, "MAPID: new flow was created ( device: %s, fd: %d ) at ", device, fl->fd); write_date(log_fd_info); write_newline(log_fd_info, "\n"); release_write_lock(log_fd_info, file_size); } if (log_to_syslog) log_message("new flow was created ( device: %s, fd: %d )", device, fl->fd); } mapiipc_daemon_write(&buf, sock); }
int main(int argc, char *argv[]) { const char *homedir; parse_arguments(argc, argv); flowlist=malloc(sizeof(flist_t)); flist_init(flowlist); clientlist = malloc(sizeof(flist_t)); flist_init(clientlist); gflist = malloc(sizeof(global_function_list_t)); gflist->fflist=malloc(sizeof(flist_t)); flist_init(gflist->fflist); gflist->lock = 0; homedir = getenv("HOME"); if (homedir == NULL) { fputs("Environment variable HOME not set. Giving up.\n", stderr); exit( 1); } mapid_conf = printf_string( CONFDIR"/"CONF_FILE ); printf("using %s\n", mapid_conf); log_level = get_log_level(mapid_conf); // get log level from mapi.conf if (log_to_syslog) // logging to syslog is enabled open_syslog(log_level, "MAPID"); log_to_file = set_logging_to_file(mapid_conf, &log_fd_info, &log_fd_debug); // support for logging to file if (log_to_syslog == 0 && log_to_file == 0) log_level = LOGGING_DISABLED; if (log_to_syslog == 0) printf("logging to syslog: disabled\n"); else printf("logging to syslog: enabled - LogLevel: %d\n", log_level); if (log_to_file) { daemon_started(log_fd_info, "MAPID", daemonize, 0); daemon_started(log_fd_debug, "MAPID", daemonize, 0); } if (log_to_syslog) log_message( "MAPID was started %s%s", daemonize ? " ( is running as daemon )" : ""); drvlist = load_drivers(); if (drvlist == NULL) { DEBUG_CMD(Debug_Message("ERROR: No MAPI drivers found")); exit(EXIT_FAILURE); } // Grab some signals so we can mapid_shutdown gracefully signal(SIGTERM, mapid_shutdown); signal(SIGQUIT, mapid_shutdown); signal(SIGINT, mapid_shutdown); if (daemonize) continue_as_daemon(); mapidcom(); mapid_shutdown(0); // wait for shutdown to finish // espenb TODO: use pthread_cond_wait (or similar) instead while (running_shutdown != 2) usleep(10000); return 0; }
int main(int argc, char **argv) { lnf_rec_t *recp; pthread_t th[MAX_THREADS]; int i = 0; int numthreads = 1; int sortfield = 0; int sortbits4 = 0; int sortbits6 = 0; char c; // lnf_filter_t *filterp; flist_init(&flist); numthreads = get_cpu_cores() * NUM_THREADS_FACTOR; /* initalise one instance of memory heap (share by all threads) */ memp = NULL; filterp = NULL; progressp = NULL; recp = NULL; filter[0] = '\0'; /* fields in all outpusts */ fields_add(LNF_FLD_FIRST); fields_add(LNF_FLD_CALC_DURATION); while ((c = getopt_long(argc, argv, "A:O:r:R:T:W;", longopts, NULL)) != -1) { switch (c) { case 1: case 'T': /* T option will be removed in future */ numthreads = atoi(optarg); if (numthreads > MAX_THREADS) { fprintf(stderr, "Maximim allowed threads is %d\n", MAX_THREADS); exit(1); // numthreads = MAX_THREADS - 1; } break; case 2: if (strcmp(optarg, "nfdump") == 0) { filter_type = NFDUMPP_FILTER_NFDUMP; } else if (strcmp(optarg, "libnf") == 0) { filter_type = NFDUMPP_FILTER_LIBNF; } else { fprintf(stderr, "Invalid filter type \"%s\". Allowed options nfdump or libnf. \n", optarg); exit(1); } break; case 'r': case 'R': flist_lookup_dir(&flist, optarg); break; case 'A': if (memp == NULL) { lnf_mem_init(&memp); } parse_aggreg(memp, optarg); break; case 'O': sortfield = lnf_fld_parse(optarg, &sortbits4, &sortbits6); if (sortfield == 0) { fprintf(stderr, "Unknow or unsupported sort field: %s\n", optarg); exit(1); } break; case '?': printf("Usage: %s [ -A ] [ -R -r ] [ <filter> ] \n", argv[0]); printf(" -r : \n"); printf(" -R : Input file or directory (multiple -r -R options is allowed)\n"); printf(" -A : aggregation\n"); printf(" -O : sort order\n"); printf(" --num-threads = <num> : num threads (default: %.0f%% number of CPU cores, %d on this system)\n", NUM_THREADS_FACTOR * 100, numthreads); printf(" --filter-type = nfdump|libnf : use original nfdump filter or new libnf implementation \n"); printf("\n"); exit(1); } } /* set filter */ if (optind < argc ) { for ( ; optind < argc; optind++) { if (strlen(filter) + strlen(argv[optind]) > MAX_FILTER_LEN) { fprintf(stderr, "Not enough space for filter in buffer\n"); exit(1); } strcat(filter, argv[optind]); strcat(filter, " "); printf("filter: %s \n", filter); } filterp = NULL; switch (filter_type) { case NFDUMPP_FILTER_DEFAULT: lnf_filter_init(&filterp, filter); break; case NFDUMPP_FILTER_NFDUMP: lnf_filter_init_v1(&filterp, filter); break; case NFDUMPP_FILTER_LIBNF: lnf_filter_init_v2(&filterp, filter); break; default: fprintf(stderr, "This should never hapen line: %d\n", __LINE__); exit(1); break; } if (filterp == NULL) { fprintf(stderr, "Can not compile filter: %s\n", filter); exit(1); } // lnf_filter_free(filterp); } /* init progress bar */ if (progress_init(&progressp, 0, NULL) != NULL) { progress_steps(progressp, flist_count(&flist)); } /* aggregated or not aggregated records */ if (memp == NULL) { /* not aggregated, but sorted */ if (sortfield > 0) { lnf_mem_init(&memp); /* switch memp into list mode */ lnf_mem_setopt(memp, LNF_OPT_LISTMODE, NULL, 0); lnf_mem_fastaggr(memp, LNF_FAST_AGGR_BASIC); lnf_mem_fadd(memp, LNF_FLD_PROT, LNF_AGGR_KEY, 0, 0); lnf_mem_fadd(memp, LNF_FLD_SRCADDR, LNF_AGGR_KEY, 24, 128); lnf_mem_fadd(memp, LNF_FLD_SRCPORT, LNF_AGGR_KEY, 0, 0); lnf_mem_fadd(memp, LNF_FLD_DSTADDR, LNF_AGGR_KEY, 24, 128); lnf_mem_fadd(memp, LNF_FLD_DSTPORT, LNF_AGGR_KEY, 0, 0); } fields_add(LNF_FLD_PROT); fields_add(LNF_FLD_SRCADDR); fields_add(LNF_FLD_SRCPORT); fields_add(LNF_FLD_DSTADDR); fields_add(LNF_FLD_DSTPORT); } /* default fields on the ond of the list */ fields_add(LNF_FLD_DPKTS); fields_add(LNF_FLD_DOCTETS); fields_add(LNF_FLD_CALC_BPS); fields_add(LNF_FLD_CALC_BPP); fields_add(LNF_FLD_AGGR_FLOWS); /* set sort firld */ if (sortfield > 0) { int defaultaggr = 0; int defaultsort = 0; lnf_fld_info(sortfield, LNF_FLD_INFO_AGGR, &defaultaggr, sizeof(int)); lnf_fld_info(sortfield, LNF_FLD_INFO_SORT, &defaultsort, sizeof(int)); lnf_mem_fadd(memp, sortfield, defaultaggr|defaultsort, sortbits4, sortbits6); } print_header(); /* prepare and run threads */ pthread_mutex_init(&mutex, NULL); for ( i = 0 ; i < numthreads ; i++ ) { if ( pthread_create(&th[i], NULL, process_thread, NULL) < 0) { fprintf(stderr, "Can not create thread for %d\n", i); break; } } /* wait for threads */ for ( i = 0; i < numthreads; i++ ) { if( pthread_join(th[i], NULL) ) { fprintf(stderr, "Error joining thread\n"); break; } } /* print the records out */ if (memp != NULL) { i = 0; lnf_rec_init(&recp); while (lnf_mem_read(memp, recp) != LNF_EOF) { i++; print_row(recp); outputflows++; } } /* header */ printf("Total input flows %d, output flows: %lu\n", totalrows, outputflows); lnf_mem_free(memp); lnf_rec_free(recp); if (filterp != NULL) { lnf_filter_free(filterp); } }
int main(int argc, char *argv[]) { int cur_arg; #if SFX_LEVEL>=ARJSFXV int cmd; int is_add_cmd; unsigned long start_time, proc_time; FILE_COUNT i; FILE *stream; char *tmp_ptr, *tptr; int got_str; char *name; int flist_type; FILE_COUNT numfiles; int expand_wildcards; int entry; int sort_f; FILE_COUNT count; FILE_COUNT cur_file; int tmp_reg; #else char *tmp_ptr; #endif #ifdef COLOR_OUTPUT no_colors=redirected=!is_tty(stdout); #endif #if SFX_LEVEL>=ARJSFXV errorlevel=0; ignore_errors=0; new_stdout=stdout; lfn_supported=LFN_NOT_SUPPORTED; ticks=get_ticks(); detect_lfns(); detect_eas(); #ifndef NO_FATAL_ERROR_HDL install_smart_handler(); #endif build_crc32_table(); #else build_crc32_table(); detect_lfns(); file_packing=1; #endif #ifdef TZ_VAR tzset(); #endif #ifdef STDOUT_SETBUF_FIX /* ASR fix for IBM C Set / GLIBC */ setbuf(stdout, NULL); setbuf(stderr, NULL); #endif #if SFX_LEVEL>=ARJSFXV start_time=get_ticks(); flist_init(&flist_main, FCLIM_ARCHIVE, FL_STANDARD); ctrlc_processing=0; header=(char *)malloc_msg(HEADERSIZE_MAX); archive_name=(char *)malloc_msg(FILENAME_MAX); /* Original ARJSFX reserves 200 bytes for misc_buf but, taking into account that LFNs can be large enough, more space is to be reserved. */ misc_buf=(char *)malloc_msg(FILENAME_MAX+INPUT_LENGTH); tmp_tmp_filename=(char *)malloc_msg(FILENAME_MAX); limit=20; init(); if(signal(SIGINT, ctrlc_handler)==SIG_ERR) error(M_SIGNAL_FAILED); #ifndef NO_TERM_HDL if(signal(SIGTERM, term_handler)==SIG_ERR) error(M_SIGNAL_FAILED); #endif atexit(final_cleanup); #else tmp_tmp_filename[0]='\0'; target_dir=nullstr; garble_password=nullstr; extr_cmd_text=nullstr; #endif #ifndef SKIP_GET_EXE_NAME get_exe_name(archive_name); #else strcpy(archive_name, argv[0]); #endif exe_name=archive_name; #if SFX_LEVEL<=ARJSFX for(tmp_ptr=exe_name; *tmp_ptr!='\0'; tmp_ptr++) if(*tmp_ptr==PATHSEP_DEFAULT) exe_name=tmp_ptr+1; atexit(final_cleanup); signal(SIGINT, ctrlc_handler); #ifndef NO_TERM_HDL signal(SIGTERM, term_handler); #endif #endif check_fmsg(CHKMSG_SKIP); #if SFX_LEVEL>=ARJSFXV skip_switch_processing=0; #else switch_char=0; #endif for(cur_arg=1; cur_arg<argc; cur_arg++) parse_cmdline(argv[cur_arg]); #if SFX_LEVEL>=ARJSFXV if(install_errhdl) ignore_errors=1; if(quiet_mode) freopen(dev_null, m_w, stdout); #endif if(argc>1) skip_preset_options=1; arj_exec_validation(); if(help_issued) { #if SFX_LEVEL>=ARJSFXV show_sfx_logo(); #else msg_cprintf(0, M_ARJSFX_BANNER, exe_name); #endif check_fmsg(CHKMSG_SFX_HELP); #if SFX_LEVEL>=ARJSFXV exit(ARJ_ERL_SUCCESS); #else exit(ARJSFX_ERL_SUCCESS); #endif } #if SFX_LEVEL>=ARJSFXV if(limit!=0) wait_error(M_CRC_ERROR); limit=20; arj_exec_validation(); proc_time=get_ticks(); check_fmsg(CHKMSG_SKIP); perform_cmd(); #else process_archive(); #endif /* Cleanup for ARJSFXV */ #if SFX_LEVEL>=ARJSFXV file_arg_cleanup(); #endif if(errors>0) error(M_FOUND_N_ERRORS, errors); #if SFX_LEVEL>=ARJSFXV if(errorlevel!=ARJ_ERL_SUCCESS) exit(errorlevel); #endif #if SFX_LEVEL>=ARJSFXV if(extr_cmd_text[0]!='\0') #else if(execute_extr_cmd&&extr_cmd_text[0]!='\0') #endif { if(licensed_sfx) { msg_cprintf(0, M_EXECUTING_CMD, extr_cmd_text); arj_delay(2); exec_command(extr_cmd_text); } else { #if SFX_LEVEL>=ARJSFXV msg_sprintf(misc_buf, M_EXTR_CMD_QUERY, extr_cmd_text); if(query_action(REPLY_YES, QUERY_CRITICAL, (FMSG *)misc_buf)) exec_command(extr_cmd_text); #else msg_cprintf(0, M_EXTR_CMD_QUERY, extr_cmd_text); if(query_action()) exec_command(extr_cmd_text); #endif } } #if SFX_LEVEL>=ARJSFXV return(ARJ_ERL_SUCCESS); #else return(ARJSFX_ERL_SUCCESS); #endif }