Coverage Report

Created: 2023-06-29 06:44

/src/ndpi/src/lib/protocols/nintendo.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * nintendo.c
3
 *
4
 * Copyright (C) 2017-18 by 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
0
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NINTENDO
27
28
#include "ndpi_api.h"
29
30
static void ndpi_int_nintendo_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
31
               struct ndpi_flow_struct *flow,
32
0
               u_int8_t due_to_correlation) {
33
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NINTENDO, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
34
0
}
35
36
37
0
static void ndpi_search_nintendo(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
38
0
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
39
0
  u_int32_t payload_len = packet->payload_packet_len;
40
41
0
  if(packet->udp != NULL) {
42
0
    if(payload_len > 48) {
43
0
      const char *payload = (const char *)packet->payload;
44
0
      const char nintendo_pattern[] = { 0x32, 0xab, 0x98, 0x64, 0x02 };
45
46
0
      if(memcmp(payload, nintendo_pattern, 5) == 0) {
47
0
  NDPI_LOG_INFO(ndpi_struct, "found nintendo\n");
48
0
  ndpi_int_nintendo_add_connection(ndpi_struct, flow, 0);
49
0
  return;
50
0
      }
51
0
    }
52
0
  }
53
54
0
  NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
55
0
}
56
57
void init_nintendo_dissector(struct ndpi_detection_module_struct *ndpi_struct,
58
0
           u_int32_t *id) {
59
0
  ndpi_set_bitmask_protocol_detection("Nintendo", ndpi_struct, *id,
60
0
              NDPI_PROTOCOL_NINTENDO,
61
0
              ndpi_search_nintendo,
62
0
              NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
63
0
              SAVE_DETECTION_BITMASK_AS_UNKNOWN,
64
0
              ADD_TO_DETECTION_BITMASK);
65
0
  *id += 1;
66
0
}
67