Merge pull request #125 from stubbsw/beaglebone_libpcap_workaround

workaround libpcap 4 extra bytes
This commit is contained in:
Michael Rash
2014-08-20 23:20:40 -04:00
+23
View File
@@ -38,6 +38,7 @@
#include "process_packet.h"
#include "incoming_spa.h"
#include "utils.h"
#include "log_msg.h"
void
process_packet(unsigned char *args, const struct pcap_pkthdr *packet_header,
@@ -134,6 +135,28 @@ process_packet(unsigned char *args, const struct pcap_pkthdr *packet_header,
if (ip_hdr_words < MIN_IPV4_WORDS)
return;
/* Support for the cases where libpcap returns the Ethernet Frame Check
* Sequence (4 bytes at the end of the Ethernet frame) as part of the
* capture. libpcap returning the FCS is fairly rare. Default settings on
* the following system included an Ethernet FCS in the libpcap capture:
* BeagleBone Black rev C running 3.8.13-bone50 #1 SMP Tue May 13
* 13:24:52 UTC 2014 armv7l GNU/Linux
*
* Calculate the new pkt_end from the length in the ip header.
*/
unsigned char *pcap_with_fcs_workaround_pkt_end =
((unsigned char*)iph_p) + ntohs(iph_p->tot_len);
/* Only accept the new end if it is shorter than the original pkt_end
* provided by libpcap.
*/
if(pcap_with_fcs_workaround_pkt_end < pkt_end) {
log_msg(LOG_DEBUG, "Adjusting packet end from %u to %u (likely due to Ethernet FCS being included in the capture)", pkt_end, pcap_with_fcs_workaround_pkt_end);
pkt_end = pcap_with_fcs_workaround_pkt_end;
}
/* Now, find the packet data payload (depending on IPPROTO).
*/
src_ip = iph_p->saddr;