diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-10-20 17:46:19 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-10-20 17:46:19 +0000 |
commit | d74b50abd7829b49dbfb32ed8fb11f3bebd1d650 (patch) | |
tree | 9b9598d15f752052193e82a7cd7f803bd0afe6be /pcap2tzsp.c | |
parent | 3eb4a091791b57becee5054b66fc68ce94642cae (diff) | |
download | 2012-tzsp-d74b50abd7829b49dbfb32ed8fb11f3bebd1d650.tar.gz 2012-tzsp-d74b50abd7829b49dbfb32ed8fb11f3bebd1d650.tar.bz2 2012-tzsp-d74b50abd7829b49dbfb32ed8fb11f3bebd1d650.zip |
Utilisation reele du opt_snaplen
git-svn-id: file:///var/svn/2012-tzsp/trunk@4 147d2d3d-d0bd-48ea-923a-d90ac20f5906
Diffstat (limited to 'pcap2tzsp.c')
-rw-r--r-- | pcap2tzsp.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/pcap2tzsp.c b/pcap2tzsp.c index 4bafc47..50b31c4 100644 --- a/pcap2tzsp.c +++ b/pcap2tzsp.c @@ -22,16 +22,17 @@ #define DEFAULT_FILTER "not ( icmp[icmptype]=icmp-unreach or (udp and dst %s and port %s) )" #define DEFAULT_HOST "127.0.0.1" #define DEFAULT_PORT "37008" -#define DEFAULT_SNAPLEN "64" +#define DEFAULT_SNAPLEN "70" +/* 70 bytes captured packets will to sent in ~128 bytes frames when encapsulated */ #define UDP_SEND_BUFLEN 1500 #define MAX_TZSP_PAYLOAD (1500-40-16) +#define MIN_BYTES_TO_CAPTURE 16 #define MAX_BYTES_TO_CAPTURE (1500-40-16) /* TODO List - * Utiliser le opt_snaplen réellement * 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) @@ -42,6 +43,7 @@ TODO List * Graceful stop avec signal() * 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 */ @@ -177,6 +179,7 @@ void capture_loop(char pcap_filter[]) { char pcap_errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program pcap_filter_prog; process_packet_args_t process_packet_args; + int snaplen; memset(pcap_errbuf,0,PCAP_ERRBUF_SIZE); memset(&process_packet_args,0,sizeof(process_packet_args_t)); @@ -192,6 +195,12 @@ void capture_loop(char pcap_filter[]) { pcap_device=strdup(opt_iface); } + snaplen=atoi(opt_snaplen); + if ( snaplen < MIN_BYTES_TO_CAPTURE || snaplen > MAX_BYTES_TO_CAPTURE ) { + fprintf(stderr, "snaplen of %i is not in the allowedrange of [%i..%i]", snaplen, MIN_BYTES_TO_CAPTURE, MAX_BYTES_TO_CAPTURE); + exit(12); + } + //Already done : memset((char *) &(process_packet_args.udp_sockaddr), 0, sockaddr_len); process_packet_args.udp_sockaddr.sin_family = AF_INET; process_packet_args.udp_sockaddr.sin_port = htons(atoi(opt_port)); @@ -205,7 +214,7 @@ void capture_loop(char pcap_filter[]) { if (opt_verbose) printf("Opening device %s for capturing\n", pcap_device); /* Open device in promiscuous mode */ - if ( (pcap_handle = pcap_open_live(pcap_device, MAX_BYTES_TO_CAPTURE, 1, 512, pcap_errbuf)) == NULL){ + if ( (pcap_handle = pcap_open_live(pcap_device, snaplen, 1, 512, pcap_errbuf)) == NULL){ fprintf(stderr, "ERROR: %s\n", pcap_errbuf); exit(21); } |