1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-06-03 11:46:31 +02:00

Fix issue with packets which bigger than 1500 bytes. Related #343

This commit is contained in:
Pavel Odintsov 2015-07-29 15:29:46 +03:00
parent aea8ba0447
commit 4ecf4965ef

View File

@ -12,11 +12,12 @@ class packet_storage_t {
memory_pos = NULL;
buffer_size = 0;
packet_size = 1500;
// TODO: fix hardcoded mtu size this!!!
max_packet_size = 1500;
}
bool allocate_buffer(unsigned int buffer_size_in_packets) {
unsigned int memory_size_in_bytes = buffer_size_in_packets * (packet_size + sizeof(fastnetmon_pcap_pkthdr))
unsigned int memory_size_in_bytes = buffer_size_in_packets * (max_packet_size + sizeof(fastnetmon_pcap_pkthdr))
+ sizeof(fastnetmon_pcap_file_header);
// std::cout << "We will allocate " << memory_size_in_bytes << std::endl;
@ -62,14 +63,21 @@ class packet_storage_t {
pcap_packet_header.ts_sec = current_time.tv_sec;
pcap_packet_header.ts_usec = current_time.tv_usec;
pcap_packet_header.incl_len = length;
// Store full length of packet
pcap_packet_header.orig_len = length;
if (length > max_packet_size) {
// We whould crop packet because it's too big
pcap_packet_header.incl_len = max_packet_size;
} else {
pcap_packet_header.incl_len = length;
}
if (!this->write_binary_data(&pcap_packet_header, sizeof(pcap_packet_header))) {
return false;
}
return (this->write_binary_data(payload_pointer, length));
return (this->write_binary_data(payload_pointer, pcap_packet_header.incl_len));
}
bool we_have_free_space_for_x_bytes(unsigned int length) {
@ -84,8 +92,7 @@ class packet_storage_t {
bool write_header() {
struct fastnetmon_pcap_file_header pcap_header;
// TODO: fix hardcoded mtu size this!!!
fill_pcap_header(&pcap_header, 1500);
fill_pcap_header(&pcap_header, max_packet_size);
return this->write_binary_data(&pcap_header, sizeof(pcap_header));
}
@ -114,7 +121,7 @@ class packet_storage_t {
unsigned char* memory_pointer;
unsigned char* memory_pos;
unsigned int buffer_size;
unsigned int packet_size;
unsigned int max_packet_size;
};
#endif