static void setupDetection(void) { NDPI_PROTOCOL_BITMASK all; // init global detection structure ndpi_struct = ndpi_init_detection_module(detection_tick_resolution, malloc_wrapper, free_wrapper, debug_printf); if(ndpi_struct == NULL) { printf("ERROR: global structure initialization failed\n"); exit(-1); } // enable all protocols NDPI_BITMASK_SET_ALL(all); ndpi_set_protocol_detection_bitmask2(ndpi_struct, &all); // allocate memory for id and flow tracking size_id_struct = ndpi_detection_get_sizeof_ndpi_id_struct(); size_flow_struct = ndpi_detection_get_sizeof_ndpi_flow_struct(); // clear memory for results memset(protocol_counter, 0, sizeof(protocol_counter)); memset(protocol_counter_bytes, 0, sizeof(protocol_counter_bytes)); memset(protocol_flows, 0, sizeof(protocol_flows)); if(_protoFilePath != NULL) ndpi_load_protocols_file(ndpi_struct, _protoFilePath); raw_packet_count = ip_packet_count = total_bytes = 0; ndpi_flow_count = 0; }
NetworkInterface::NetworkInterface(const char *name) { char pcap_error_buffer[PCAP_ERRBUF_SIZE]; NDPI_PROTOCOL_BITMASK all; u_int32_t num_hashes; char _ifname[64]; #ifdef WIN32 if(name == NULL) name = "1"; /* First available interface */ #endif purge_idle_flows_hosts = true; if(name == NULL) { if(!help_printed) ntop->getTrace()->traceEvent(TRACE_WARNING, "No capture interface specified"); printAvailableInterfaces(false, 0, NULL, 0); name = pcap_lookupdev(pcap_error_buffer); if(name == NULL) { ntop->getTrace()->traceEvent(TRACE_ERROR, "Unable to locate default interface (%s)\n", pcap_error_buffer); exit(0); } } else { if(isNumber(name)) { /* We need to convert this numeric index into an interface name */ int id = atoi(name); _ifname[0] = '\0'; printAvailableInterfaces(false, id, _ifname, sizeof(_ifname)); if(_ifname[0] == '\0') { ntop->getTrace()->traceEvent(TRACE_WARNING, "Unable to locate interface Id %d", id); printAvailableInterfaces(false, 0, NULL, 0); exit(0); } name = _ifname; } } ifname = strdup(name); num_hashes = max_val(4096, ntop->getPrefs()->get_max_num_flows()/4); flows_hash = new FlowHash(this, num_hashes, ntop->getPrefs()->get_max_num_flows()); num_hashes = max_val(4096, ntop->getPrefs()->get_max_num_hosts()/4); hosts_hash = new HostHash(this, num_hashes, ntop->getPrefs()->get_max_num_hosts()); strings_hash = new StringHash(this, num_hashes, ntop->getPrefs()->get_max_num_hosts()); // init global detection structure ndpi_struct = ndpi_init_detection_module(ntop->getGlobals()->get_detection_tick_resolution(), malloc_wrapper, free_wrapper, debug_printf); if(ndpi_struct == NULL) { ntop->getTrace()->traceEvent(TRACE_ERROR, "Global structure initialization failed"); exit(-1); } if(ntop->getCustomnDPIProtos() != NULL) ndpi_load_protocols_file(ndpi_struct, ntop->getCustomnDPIProtos()); ndpi_port_range d_port[MAX_DEFAULT_PORTS]; memset(d_port, 0, sizeof(d_port)); ndpi_set_proto_defaults(ndpi_struct, NTOPNG_NDPI_OS_PROTO_ID, (char*)"Operating System", d_port, d_port); // enable all protocols NDPI_BITMASK_SET_ALL(all); ndpi_set_protocol_detection_bitmask2(ndpi_struct, &all); last_pkt_rcvd = 0; next_idle_flow_purge = next_idle_host_purge = next_idle_aggregated_host_purge = 0; cpu_affinity = -1; running = false; #ifdef HAVE_SQLITE db = new DB(this); #endif }