diff options
-rw-r--r-- | pcap2tzsp.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pcap2tzsp.c b/pcap2tzsp.c index ec9264a..701944c 100644 --- a/pcap2tzsp.c +++ b/pcap2tzsp.c @@ -44,9 +44,8 @@ TODO List * Implémenter une bwlimit en sortie (ptks/s et/ou bytes/s) * Pkt timestamps sur 64bits (quel field prendre ?) * Comparer les headers envoyés par un mikrotik avec /tool sniffer - * free() de tous les malloc(), calloc() et strdup() * TZSP over IPv6 - * Graceful stop avec signal() + * Graceful stop avec signal() (penser a faire un retour chariot de + car le prompt du shell est au bout de la ligne sinon) * getopts -v et --help * Licence GPL * 64bits problem : pcap2tzsp.c:264:3: attention : format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’ [-Wformat] @@ -174,6 +173,13 @@ int main(int argc, char *argv[]) { /* Run the capture loop */ capture_loop(pcap_filter); + free(pcap_filter); + + free(opt_host); + free(opt_port); + free(opt_snaplen); + if (opt_iface!=NULL) free(opt_iface); + return 0; } @@ -225,6 +231,8 @@ void capture_loop(char pcap_filter[]) { exit(21); } + free(pcap_device); + if (opt_verbose) printf("Compiling the following capture filter : '%s'\n", pcap_filter); if ( pcap_compile(pcap_handle,&pcap_filter_prog,pcap_filter,1,PCAP_NETMASK_UNKNOWN) == -1 ) { fprintf(stderr,"ERROR : %s\n", pcap_geterr(pcap_handle) ); @@ -236,6 +244,8 @@ void capture_loop(char pcap_filter[]) { exit(23); } + pcap_freecode(&pcap_filter_prog); + /* Initialisation socket UDP */ process_packet_args.udp_socket=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (process_packet_args.udp_socket==-1) { @@ -244,11 +254,13 @@ void capture_loop(char pcap_filter[]) { } /* Loop forever & call process_packet() for every received packet*/ - if ( pcap_loop(pcap_handle, -1, process_packet, (u_char *)&process_packet_args) == -1){ + /* For valgrind tests : if ( pcap_loop(pcap_handle, 1000000, process_packet, (u_char *)&process_packet_args) == -1){ */ + if ( pcap_loop(pcap_handle, -1, process_packet, (u_char *)&process_packet_args) == -1) { fprintf(stderr, "ERROR: %s\n", pcap_geterr(pcap_handle) ); exit(25); } + pcap_close(pcap_handle); close(process_packet_args.udp_socket); } |