Coverage Report

Created: 2025-08-29 06:20

/src/ndpi/src/lib/protocols/monero.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * monero.c
3
 *
4
 * Copyright (C) 2023 - ntop.org
5
 *
6
 * This file is part of nDPI, an open source deep packet inspection
7
 * library based on the OpenDPI and PACE technology by ipoque GmbH
8
 *
9
 * nDPI is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Lesser General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * nDPI is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
#include "ndpi_protocol_ids.h"
25
26
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MONERO
27
28
#include "ndpi_api.h"
29
#include "ndpi_private.h"
30
31
static void ndpi_int_monero_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
32
                                           struct ndpi_flow_struct *flow)
33
0
{
34
0
  NDPI_LOG_INFO(ndpi_struct, "found Monero Protocol\n");
35
36
0
  ndpi_set_detected_protocol(ndpi_struct, flow,
37
0
                             NDPI_PROTOCOL_MONERO, NDPI_PROTOCOL_UNKNOWN,
38
0
                             NDPI_CONFIDENCE_DPI);
39
40
0
  if(ndpi_struct->mining_cache)
41
0
  {
42
0
    ndpi_lru_add_to_cache(ndpi_struct->mining_cache,
43
0
                          mining_make_lru_cache_key(flow),
44
0
                          NDPI_PROTOCOL_MONERO,
45
0
                          ndpi_get_current_time(flow));
46
0
  }
47
0
}
48
49
static void ndpi_search_monero(struct ndpi_detection_module_struct *ndpi_struct,
50
                               struct ndpi_flow_struct *flow)
51
0
{
52
0
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
53
54
0
  NDPI_LOG_DBG(ndpi_struct, "search Monero Protocol\n");
55
56
0
  if (packet->payload_packet_len < 8)
57
0
  {
58
0
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
59
0
    return;
60
0
  }
61
62
0
  if (get_u_int64_t(packet->payload, 0) == ndpi_htonll(0x0121010101010101))
63
0
  {
64
0
    ndpi_int_monero_add_connection(ndpi_struct, flow);
65
0
    return;
66
0
  }
67
68
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
69
0
}
70
71
void init_monero_dissector(struct ndpi_detection_module_struct *ndpi_struct)
72
0
{
73
0
  register_dissector("Monero", ndpi_struct,
74
0
                     ndpi_search_monero,
75
0
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
76
0
                      1, NDPI_PROTOCOL_MONERO);
77
0
}