static void printResults(u_int64_t tot_usec) { u_int32_t i; printf("\x1b[2K\n"); printf("pcap file contains\n"); printf("\tIP packets: \x1b[33m%-13llu\x1b[0m of %llu packets total\n", (long long unsigned int)ip_packet_count, (long long unsigned int)raw_packet_count); printf("\tIP bytes: \x1b[34m%-13llu\x1b[0m\n", (long long unsigned int)total_bytes); printf("\tUnique flows: \x1b[36m%-13u\x1b[0m\n", ndpi_flow_count); if(tot_usec > 0) { char buf[32], buf1[32]; float t = (float)(ip_packet_count*1000000)/(float)tot_usec; float b = (float)(total_bytes * 8 *1000000)/(float)tot_usec; printf("\tnDPI throughout: \x1b[36m%s pps / %s/sec\x1b[0m\n", formatPackets(t, buf), formatTraffic(b, 1, buf1)); } for(i=0; i<NUM_ROOTS; i++) ndpi_twalk(ndpi_flows_root[i], node_proto_guess_walker, NULL); if(enable_protocol_guess) printf("\tGuessed flow protocols: \x1b[35m%-13u\x1b[0m\n", guessed_flow_protocols); printf("\n\nDetected protocols:\n"); for (i = 0; i <= ndpi_get_num_supported_protocols(ndpi_struct); i++) { if(protocol_counter[i] > 0) { printf("\t\x1b[31m%-20s\x1b[0m packets: \x1b[33m%-13llu\x1b[0m bytes: \x1b[34m%-13llu\x1b[0m " "flows: \x1b[36m%-13u\x1b[0m\n", ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i], (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]); } } if(verbose && (protocol_counter[0] > 0)) { printf("\n"); for(i=0; i<NUM_ROOTS; i++) ndpi_twalk(ndpi_flows_root[i], node_print_known_proto_walker, NULL); printf("\n\nUndetected flows:\n"); for(i=0; i<NUM_ROOTS; i++) ndpi_twalk(ndpi_flows_root[i], node_print_unknown_proto_walker, NULL); } printf("\n\n"); }
static void printResults(void) { u_int32_t i, j; printf("\x1b[2K\n"); printf("pcap file contains\n"); printf("\tip packets: \x1b[33m%-13llu\x1b[0m of %llu packets total\n", (long long unsigned int)ip_packet_count, (long long unsigned int)raw_packet_count); printf("\tip bytes: \x1b[34m%-13llu\x1b[0m\n", (long long unsigned int)total_bytes); printf("\tunique flows: \x1b[36m%-13u\x1b[0m\n", ndpi_flow_count); ndpi_twalk(ndpi_flows_root, node_proto_guess_walker, NULL); if(enable_protocol_guess) printf("\tguessed flow protocols: \x1b[35m%-13u\x1b[0m\n", guessed_flow_protocols); printf("\n\ndetected protocols:\n"); for (i = 0; i <= ndpi_get_num_supported_protocols(ndpi_struct); i++) { if (protocol_counter[i] > 0) { printf("\t\x1b[31m%-20s\x1b[0m packets: \x1b[33m%-13llu\x1b[0m bytes: \x1b[34m%-13llu\x1b[0m " "flows: \x1b[36m%-13u\x1b[0m\n", ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i], (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]); } } if(verbose && (protocol_counter[0] > 0)) { printf("\n\nundetected flows:\n"); ndpi_twalk(ndpi_flows_root, node_print_unknown_proto_walker, NULL); } if (1) { flow_info_file = fopen(flow_info_file_name, "wb"); fputs("source_ip source_port dest_ip dest_port first_packet_time l4_proto detect_proto packets bytes\n", flow_info_file); ndpi_twalk(ndpi_flows_root, node_output_flow_info_walker, NULL); fclose(flow_info_file); } printf("\n\n"); }
// 在 winrow 上用黑体重写 static void prepareResults(/*u_int64_t tot_usec*/) { u_int32_t i; int row=0; int m = 0; /* Default output mode: color (0) */ memset(results,0,sizeof(results)); if (m) { printf("\n"); } else { printf("\x1b[2K\n"); } if (m) { sprintf(results[row++],"\tIP packets: %-13llu of %llu packets total\n", (long long unsigned int)ip_packet_count, (long long unsigned int)raw_packet_count); if(total_bytes > 0) sprintf(results[row++],"\tIP bytes: %-13llu (avg pkt size %u bytes)\n", (long long unsigned int)total_bytes,raw_packet_count>0?0: (unsigned int)(total_bytes/raw_packet_count)); sprintf(results[row++],"\tUnique flows: %-13u\n", ndpi_flow_count); } else { sprintf(results[row++],"\tIP packets: %-13llu of %llu packets total\n", (long long unsigned int)ip_packet_count, (long long unsigned int)raw_packet_count); sprintf(results[row++],"\tIP bytes: %-13llu (avg pkt size %u bytes)\n", (long long unsigned int)total_bytes,/*raw_packet_count>0?0:(unsigned int)(total_bytes/ip_packet_count)*/0); sprintf(results[row++],"\tUnique flows: %-13u\n", ndpi_flow_count); } /* if(tot_usec > 0) { char buf[32], buf1[32]; float t = (float)(ip_packet_count*1000000)/(float)tot_usec; float b = (float)(total_bytes * 8 *1000000)/(float)tot_usec; if (m) { printf("\tnDPI throughout: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1)); } else { //printf("\tGuessed flow protocols: \x1b[35m%-13u\x1b[0m\n", guessed_flow_protocols); } } */ sprintf(results[row++],"\n"); sprintf(results[row++],"\n"); sprintf(results[row++],"\tDetected protocols:"); sprintf(results[row++],"\n"); sprintf(results[row++],"\n"); for (i = 0; i <= ndpi_get_num_supported_protocols(ndpi_struct) /*&& row < NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 10*/; i++,row++) { if(protocol_counter[i] > 0) { if (m) { sprintf(results[row],"\t\%-20s packets: %-13llu bytes: %-13llu " "flows: %-13u\n", ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i], (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]); } else { printf("%d\n",row); sprintf(results[row],"\t%-20s packets: %-13llu bytes: %-13llu " "flows: %-13u\n", ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i], (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]); } } }