summaryrefslogtreecommitdiff
path: root/pcap2tzsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap2tzsp.c')
-rw-r--r--pcap2tzsp.c25
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;