diff options
-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); } |