37
37
#include " headers.hpp"
38
38
#include < ipfixprobe/packet.hpp>
39
39
40
+ #include < iterator>
41
+ #include < string>
42
+ #include < sstream>
43
+ #include < numeric>
40
44
namespace ipxp {
41
45
42
46
// #define DEBUG_PARSER
@@ -454,7 +458,7 @@ inline uint16_t parse_ipv6_hdr(const u_char *data_ptr, uint16_t data_len, Packet
454
458
* \param [out] pkt Pointer to Packet structure where parsed fields will be stored.
455
459
* \return Size of header in bytes.
456
460
*/
457
- inline uint16_t parse_tcp_hdr (const u_char *data_ptr, uint16_t data_len, Packet *pkt)
461
+ inline uint16_t parse_tcp_hdr (ParserStats& stats, const u_char *data_ptr, uint16_t data_len, Packet *pkt)
458
462
{
459
463
struct tcphdr *tcp = (struct tcphdr *) data_ptr;
460
464
if (sizeof (struct tcphdr ) > data_len) {
@@ -469,6 +473,9 @@ inline uint16_t parse_tcp_hdr(const u_char *data_ptr, uint16_t data_len, Packet
469
473
pkt->tcp_flags = (uint8_t ) *(data_ptr + 13 ) & 0xFF ;
470
474
pkt->tcp_window = ntohs (tcp->window );
471
475
476
+ stats.top_ports .insert (pkt->src_port );
477
+ stats.top_ports .insert (pkt->dst_port );
478
+
472
479
DEBUG_MSG (" TCP header:\n " );
473
480
DEBUG_MSG (" \t Src port:\t %u\n " , ntohs (tcp->source ));
474
481
DEBUG_MSG (" \t Dest port:\t %u\n " , ntohs (tcp->dest ));
@@ -529,7 +536,7 @@ inline uint16_t parse_tcp_hdr(const u_char *data_ptr, uint16_t data_len, Packet
529
536
* \param [out] pkt Pointer to Packet structure where parsed fields will be stored.
530
537
* \return Size of header in bytes.
531
538
*/
532
- inline uint16_t parse_udp_hdr (const u_char *data_ptr, uint16_t data_len, Packet *pkt)
539
+ inline uint16_t parse_udp_hdr (ParserStats& stats, const u_char *data_ptr, uint16_t data_len, Packet *pkt)
533
540
{
534
541
struct udphdr *udp = (struct udphdr *) data_ptr;
535
542
if (sizeof (struct udphdr ) > data_len) {
@@ -539,6 +546,9 @@ inline uint16_t parse_udp_hdr(const u_char *data_ptr, uint16_t data_len, Packet
539
546
pkt->src_port = ntohs (udp->source );
540
547
pkt->dst_port = ntohs (udp->dest );
541
548
549
+ stats.top_ports .insert (pkt->src_port );
550
+ stats.top_ports .insert (pkt->dst_port );
551
+
542
552
DEBUG_MSG (" UDP header:\n " );
543
553
DEBUG_MSG (" \t Src port:\t %u\n " , ntohs (udp->source ));
544
554
DEBUG_MSG (" \t Dest port:\t %u\n " , ntohs (udp->dest ));
@@ -727,10 +737,10 @@ void parse_packet(parser_opt_t *opt, ParserStats& stats, struct timeval ts, cons
727
737
728
738
l4_hdr_offset = data_offset;
729
739
if (pkt->ip_proto == IPPROTO_TCP) {
730
- data_offset += parse_tcp_hdr (data + data_offset, caplen - data_offset, pkt);
740
+ data_offset += parse_tcp_hdr (stats, data + data_offset, caplen - data_offset, pkt);
731
741
stats.tcp_packets ++;
732
742
} else if (pkt->ip_proto == IPPROTO_UDP) {
733
- data_offset += parse_udp_hdr (data + data_offset, caplen - data_offset, pkt);
743
+ data_offset += parse_udp_hdr (stats, data + data_offset, caplen - data_offset, pkt);
734
744
stats.udp_packets ++;
735
745
}
736
746
} catch (const char *err) {
0 commit comments