Coverage Report

Created: 2026-04-04 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/mpegts.c
Line
Count
Source
1
/*
2
 * mpegts.c (MPEG Transport Stream)
3
 *          https://en.wikipedia.org/wiki/MPEG_transport_stream
4
 *
5
 * Copyright (C) 2015-22 - ntop.org
6
 *
7
 * nDPI is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * nDPI is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
#include "ndpi_protocol_ids.h"
23
24
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MPEGTS
25
26
#include "ndpi_api.h"
27
#include "ndpi_private.h"
28
29
static void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
30
0
{
31
0
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
32
33
0
  NDPI_LOG_DBG(ndpi_struct, "search MPEGTS\n");
34
35
0
  if((packet->udp != NULL) && ((packet->payload_packet_len % 188) == 0)) {
36
0
    u_int i, num_chunks = packet->payload_packet_len / 188;
37
    
38
0
    for(i=0; i<num_chunks; i++) {
39
0
      u_int offset = 188 * i;
40
41
0
      if(packet->payload[offset] != 0x47) goto no_mpegts;
42
0
    }
43
44
    /* This looks MPEG TS */
45
0
    NDPI_LOG_INFO(ndpi_struct, "found MPEGTS\n");
46
0
    ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MPEGTS, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
47
0
    return;
48
0
  }    
49
50
0
 no_mpegts:
51
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
52
0
}
53
54
55
void init_mpegts_dissector(struct ndpi_detection_module_struct *ndpi_struct)
56
0
{
57
0
  ndpi_register_dissector("MPEG_TS", ndpi_struct,
58
0
                     ndpi_search_mpegts,
59
0
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
60
0
                      1, NDPI_PROTOCOL_MPEGTS);
61
0
}
62