Coverage Report

Created: 2025-11-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/rtsp.c
Line
Count
Source
1
/*
2
 * rtsp.c
3
 *
4
 * Copyright (C) 2009-11 - ipoque GmbH
5
 * Copyright (C) 2011-25 - ntop.org
6
 *
7
 * This file is part of nDPI, an open source deep packet inspection
8
 * library based on the OpenDPI and PACE technology by ipoque GmbH
9
 *
10
 * nDPI is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * nDPI is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
#include "ndpi_protocol_ids.h"
26
27
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_RTSP
28
29
#include "ndpi_api.h"
30
#include "ndpi_private.h"
31
32
33
static void ndpi_int_rtsp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
34
           struct ndpi_flow_struct *flow)
35
4.45k
{
36
4.45k
  NDPI_LOG_INFO(ndpi_struct, "found RTSP\n");
37
4.45k
  ndpi_set_detected_protocol_keeping_master(ndpi_struct, flow, NDPI_PROTOCOL_RTSP,
38
4.45k
              NDPI_CONFIDENCE_DPI);
39
4.45k
}
40
41
/* this function searches for a rtsp-"handshake" over tcp or udp. */
42
static void ndpi_search_rtsp_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct,
43
             struct ndpi_flow_struct *flow)
44
3.58M
{
45
3.58M
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
46
47
3.58M
  NDPI_LOG_DBG(ndpi_struct, "search RTSP\n");
48
49
3.58M
  if (packet->parsed_lines == 0)
50
2.99M
  {
51
2.99M
    ndpi_parse_packet_line_info(ndpi_struct, flow);
52
2.99M
  }
53
54
3.58M
  if (packet->parsed_lines > 0 &&
55
873k
      (LINE_ENDS(packet->line[0], "RTSP/1.0") != 0 ||
56
870k
       LINE_STARTS(packet->line[0], "RTSP/1.0") != 0 || /* Response */
57
869k
       LINE_ENDS(packet->accept_line, "application/x-rtsp-tunnelled") != 0 ||
58
869k
       LINE_ENDS(packet->content_line, "application/x-rtsp-tunnelled") != 0
59
873k
       /* Should we also check for "rtsp://" in the packet? */))
60
4.45k
  {
61
4.45k
    ndpi_int_rtsp_add_connection(ndpi_struct, flow);
62
63
    /* Extract some metadata HTTP-like */
64
4.45k
    if(packet->user_agent_line.ptr != NULL)
65
2.78k
      ndpi_user_agent_set(flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
66
67
4.45k
    return;
68
4.45k
  }
69
70
3.58M
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
71
3.58M
}
72
73
74
void init_rtsp_dissector(struct ndpi_detection_module_struct *ndpi_struct)
75
8.07k
{
76
8.07k
  register_dissector("RTSP", ndpi_struct,
77
8.07k
                     ndpi_search_rtsp_tcp_udp,
78
8.07k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
79
8.07k
                     1, NDPI_PROTOCOL_RTSP);
80
8.07k
}