@@ -465,7 +465,7 @@ inline uint16_t parse_ipv6_hdr(const u_char* data_ptr, uint16_t data_len, Packet
465
465
* \param [out] pkt Pointer to Packet structure where parsed fields will be stored.
466
466
* \return Size of header in bytes.
467
467
*/
468
- inline uint16_t parse_tcp_hdr (const u_char* data_ptr, uint16_t data_len, Packet* pkt)
468
+ inline uint16_t parse_tcp_hdr (const u_char* data_ptr, uint16_t data_len, Packet* pkt, ParserStats& stats )
469
469
{
470
470
struct tcphdr * tcp = (struct tcphdr *) data_ptr;
471
471
if (sizeof (struct tcphdr ) > data_len) {
@@ -479,6 +479,9 @@ inline uint16_t parse_tcp_hdr(const u_char* data_ptr, uint16_t data_len, Packet*
479
479
pkt->tcp_flags = (uint8_t ) *(data_ptr + 13 ) & 0xFF ;
480
480
pkt->tcp_window = ntohs (tcp->window );
481
481
482
+ stats.top_ports .increment_tcp_frequency (pkt->src_port );
483
+ stats.top_ports .increment_tcp_frequency (pkt->dst_port );
484
+
482
485
DEBUG_MSG (" TCP header:\n " );
483
486
DEBUG_MSG (" \t Src port:\t %u\n " , ntohs (tcp->source ));
484
487
DEBUG_MSG (" \t Dest port:\t %u\n " , ntohs (tcp->dest ));
@@ -544,7 +547,7 @@ inline uint16_t parse_tcp_hdr(const u_char* data_ptr, uint16_t data_len, Packet*
544
547
* \param [out] pkt Pointer to Packet structure where parsed fields will be stored.
545
548
* \return Size of header in bytes.
546
549
*/
547
- inline uint16_t parse_udp_hdr (const u_char* data_ptr, uint16_t data_len, Packet* pkt)
550
+ inline uint16_t parse_udp_hdr (const u_char* data_ptr, uint16_t data_len, Packet* pkt, ParserStats& stats )
548
551
{
549
552
struct udphdr * udp = (struct udphdr *) data_ptr;
550
553
if (sizeof (struct udphdr ) > data_len) {
@@ -554,6 +557,9 @@ inline uint16_t parse_udp_hdr(const u_char* data_ptr, uint16_t data_len, Packet*
554
557
pkt->src_port = ntohs (udp->source );
555
558
pkt->dst_port = ntohs (udp->dest );
556
559
560
+ stats.top_ports .increment_udp_frequency (pkt->src_port );
561
+ stats.top_ports .increment_udp_frequency (pkt->dst_port );
562
+
557
563
DEBUG_MSG (" UDP header:\n " );
558
564
DEBUG_MSG (" \t Src port:\t %u\n " , ntohs (udp->source ));
559
565
DEBUG_MSG (" \t Dest port:\t %u\n " , ntohs (udp->dest ));
@@ -749,10 +755,10 @@ void parse_packet(
749
755
750
756
l4_hdr_offset = data_offset;
751
757
if (pkt->ip_proto == IPPROTO_TCP) {
752
- data_offset += parse_tcp_hdr (data + data_offset, caplen - data_offset, pkt);
758
+ data_offset += parse_tcp_hdr (data + data_offset, caplen - data_offset, pkt, stats );
753
759
stats.tcp_packets ++;
754
760
} else if (pkt->ip_proto == IPPROTO_UDP) {
755
- data_offset += parse_udp_hdr (data + data_offset, caplen - data_offset, pkt);
761
+ data_offset += parse_udp_hdr (data + data_offset, caplen - data_offset, pkt, stats );
756
762
stats.udp_packets ++;
757
763
}
758
764
} catch (const char * err) {
0 commit comments