Coverage Report

Created: 2025-11-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/tocaboca.c
Line
Count
Source
1
/*
2
 * tocaboca.c
3
 *
4
 * Copyright (C) 2011-25 - ntop.org
5
 *
6
 * nDPI is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * nDPI is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 */
20
21
#include "ndpi_protocol_ids.h"
22
23
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_TOCA_BOCA
24
25
#include "ndpi_api.h"
26
#include "ndpi_private.h"
27
28
static void ndpi_int_toca_boca_add_connection(struct ndpi_detection_module_struct * const ndpi_struct,
29
                                              struct ndpi_flow_struct * const flow)
30
0
{
31
0
  NDPI_LOG_INFO(ndpi_struct, "found TocaBoca\n");
32
0
  ndpi_set_detected_protocol(ndpi_struct, flow,
33
0
                             NDPI_PROTOCOL_TOCA_BOCA, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
34
0
}
35
36
static void ndpi_search_toca_boca(struct ndpi_detection_module_struct *ndpi_struct,
37
                                  struct ndpi_flow_struct *flow)
38
23
{
39
23
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
40
23
  u_int32_t payload_len = packet->payload_packet_len;
41
42
23
  NDPI_LOG_DBG(ndpi_struct, "search TocaBoca\n");
43
44
23
  if (packet->udp != NULL)
45
23
  {
46
23
    if (payload_len >= 13
47
23
        && get_u_int32_t(packet->payload, 0) == 0x7d7d7d7d
48
0
        && get_u_int32_t(packet->payload, 4) == 0x7d7d7d7d)
49
0
    {
50
0
      ndpi_int_toca_boca_add_connection(ndpi_struct, flow);
51
0
      return;
52
0
    }
53
54
23
    if (flow->packet_counter == 1
55
23
        && payload_len >= 24
56
23
        && ntohl(get_u_int32_t(packet->payload, 0)) == 0xffff0001
57
23
        && ntohl(get_u_int32_t(packet->payload, 12)) == 0x02ff0104)
58
0
    {
59
0
      ndpi_int_toca_boca_add_connection(ndpi_struct, flow);
60
0
      return;
61
0
    }
62
63
23
    if (payload_len >= 32
64
23
        && (ntohs(get_u_int16_t(packet->payload, 2)) == 0x0001
65
23
            || ntohs(get_u_int16_t(packet->payload, 2)) == 0x0002
66
23
            || ntohs(get_u_int16_t(packet->payload, 2)) == 0x0003)
67
0
        && (ntohl(get_u_int32_t(packet->payload, 12)) == 0x01ff0000
68
0
            || ntohl(get_u_int32_t(packet->payload, 12)) == 0x01000000)
69
23
        && ntohl(get_u_int32_t(packet->payload, 16)) == 0x00000014)
70
0
    {
71
0
      ndpi_int_toca_boca_add_connection(ndpi_struct, flow);
72
0
      return;
73
0
    }
74
23
  }
75
76
23
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
77
23
}
78
79
void init_toca_boca_dissector(struct ndpi_detection_module_struct *ndpi_struct)
80
862
{
81
862
  register_dissector("TocaBoca", ndpi_struct,
82
862
                     ndpi_search_toca_boca,
83
862
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
84
862
                     1, NDPI_PROTOCOL_TOCA_BOCA);
85
862
}
86