diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-10-21 13:32:29 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-10-21 13:32:29 +0000 |
commit | 87a0dd9a5fa0f673d95bd20ee3750af21243f10c (patch) | |
tree | 8db0fe1f764672f4b75821fdb330f9a66c04794e /pcap2tzsp.c | |
parent | ac85647309e45ad3705a72a7828954a07c24f5a7 (diff) | |
download | 2012-tzsp-87a0dd9a5fa0f673d95bd20ee3750af21243f10c.tar.gz 2012-tzsp-87a0dd9a5fa0f673d95bd20ee3750af21243f10c.tar.bz2 2012-tzsp-87a0dd9a5fa0f673d95bd20ee3750af21243f10c.zip |
Resolution problèmes printf 64 bits (harmonisation des types avec la libpcap)
Resolution bug du free en trop sur pas d'option "-i"
git-svn-id: file:///var/svn/2012-tzsp/trunk@9 147d2d3d-d0bd-48ea-923a-d90ac20f5906
Diffstat (limited to 'pcap2tzsp.c')
-rw-r--r-- | pcap2tzsp.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/pcap2tzsp.c b/pcap2tzsp.c index 05c1a4e..8ec9e9f 100644 --- a/pcap2tzsp.c +++ b/pcap2tzsp.c @@ -46,18 +46,11 @@ /* TODO List - * Crash at exit if no -i supplied - * TZSP TAGPACKET_COUNT field * Resolution DNS host -> IP (c'est l'ip qu'il faut dans le filtre et pas le host !!) - * Stats nombre de packets loupés ? * 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 * TZSP over IPv6 - * 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] */ /* Functions declaration */ @@ -66,8 +59,9 @@ void process_packet(u_char *void_args, const struct pcap_pkthdr* pkthdr, const u /* Custom types definition */ typedef struct _process_packet_args { - uint64_t captured_pkt_count; - uint64_t sent_pkt_count; + /* Types like in libpcap because I don't want to mess around hours */ + u_int captured_pkt_count; + u_int sent_pkt_count; int udp_socket; struct sockaddr_in udp_sockaddr; } process_packet_args_t; @@ -234,7 +228,7 @@ void capture_loop(char pcap_filter[]) { } } else { /* Use user-suplied interface */ - pcap_device=strdup(opt_iface); + pcap_device=opt_iface; } snaplen=atoi(opt_snaplen); @@ -261,8 +255,6 @@ 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) ); @@ -284,13 +276,12 @@ void capture_loop(char pcap_filter[]) { } /* Loop forever & call process_packet() for every received packet */ - /* 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); } - fprintf(stderr, "\n%llu packets captured\n%llu TZSP packets sent\n", + fprintf(stderr, "\n%u packets captured\n%u TZSP packets sent\n", process_packet_args.captured_pkt_count, process_packet_args.sent_pkt_count); if (pcap_stats(pcap_handle, &stat) == -1) { @@ -311,7 +302,7 @@ void capture_loop(char pcap_filter[]) { void process_packet(u_char *void_args, const struct pcap_pkthdr* pkthdr, const u_char * packet) { static time_t old_tv_sec=0; - static uint64_t old_captured_pkt_count=0; + static u_int old_captured_pkt_count=0; int res; double throughput; @@ -328,11 +319,11 @@ void process_packet(u_char *void_args, const struct pcap_pkthdr* pkthdr, const u args->captured_pkt_count++; if (old_tv_sec != pkthdr->ts.tv_sec) { - /*printf("DEBUG : throughput=((double) %llu - %llu ) / ( %u - %u )\n", + /*printf("DEBUG : throughput=((double) %u - %u ) / ( %u - %u )\n", args->captured_pkt_count, old_captured_pkt_count, pkthdr->ts.tv_sec, old_tv_sec); */ throughput=((double) args->captured_pkt_count - old_captured_pkt_count ) / (pkthdr->ts.tv_sec - old_tv_sec); - printf("\rPacket Count: %20llu (%8.1f pkt/s)", args->captured_pkt_count, throughput); + printf("\rPacket Count: %u (%8.1f pkt/s)", args->captured_pkt_count, throughput); fflush(stdout); old_tv_sec=pkthdr->ts.tv_sec; old_captured_pkt_count= args->captured_pkt_count; |