Coverage Report

Created: 2026-02-21 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/teamspeak.c
Line
Count
Source
1
/*
2
 * teamspeak.c 
3
 *
4
 * Copyright (C) 2013 Remy Mudingay <mudingay@ill.fr>
5
 *
6
 * This module 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
 * This module 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
 * If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
#include "ndpi_protocol_ids.h"
21
22
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_TEAMSPEAK
23
24
#include "ndpi_api.h"
25
#include "ndpi_private.h"
26
27
static void ndpi_int_teamspeak_add_connection(struct ndpi_detection_module_struct
28
                                              *ndpi_struct, struct ndpi_flow_struct *flow)
29
1.16k
{
30
1.16k
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TEAMSPEAK, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
31
1.16k
}
32
33
34
static void ndpi_search_teamspeak(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
35
5.50M
{
36
5.50M
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
37
38
5.50M
  NDPI_LOG_DBG(ndpi_struct, "search teamspeak\n");
39
40
5.50M
  if (packet->payload_packet_len >= 20) {
41
3.41M
    if (packet->udp != NULL) {
42
795k
      if (memcmp(packet->payload, "TS3INIT1", strlen("TS3INIT1")) == 0)
43
517
      {
44
517
        NDPI_LOG_INFO(ndpi_struct, "found TEAMSPEAK udp\n");
45
517
        ndpi_int_teamspeak_add_connection(ndpi_struct, flow);
46
517
        return;
47
517
      }
48
2.62M
    } else if(packet->tcp != NULL) {
49
      /* https://github.com/Youx/soliloque-server/wiki/Connection-packet */
50
2.62M
      if(((memcmp(packet->payload, "\xf4\xbe\x03\x00", 4) == 0)) ||
51
2.62M
         ((memcmp(packet->payload, "\xf4\xbe\x02\x00", 4) == 0)) ||
52
2.62M
         ((memcmp(packet->payload, "\xf4\xbe\x01\x00", 4) == 0)))
53
221
      {
54
221
        NDPI_LOG_INFO(ndpi_struct, "found TEAMSPEAK tcp\n");
55
221
        ndpi_int_teamspeak_add_connection(ndpi_struct, flow);
56
221
        return;
57
221
      }  /* http://www.imfirewall.com/en/protocols/teamSpeak.htm  */
58
2.62M
    }
59
3.41M
  }
60
61
5.50M
  if (packet->udp != NULL)
62
970k
  {
63
970k
    if (packet->payload_packet_len == 16 &&
64
29.5k
        packet->payload[0] == 0x01 && packet->payload[3] == 0x02 &&
65
1.66k
        get_u_int32_t(packet->payload, 11) == 0x00000000 && packet->payload[15] == 0x00)
66
1.05k
    {
67
1.05k
      goto ts3_license_weblist;
68
1.05k
    }
69
70
969k
    if ((packet->payload_packet_len == 4 || packet->payload_packet_len == 8) &&
71
55.2k
        packet->payload[0] == 0x01 && packet->payload[3] == 0x01)
72
2.71k
    {
73
2.71k
      goto ts3_license_weblist;
74
2.71k
    }
75
76
966k
    if (packet->payload_packet_len == 5 &&
77
8.33k
        packet->payload[0] == 0x01 && packet->payload[3] == 0x02 &&
78
1.31k
        packet->payload[4] == 0x00)
79
1.14k
    {
80
1.14k
      goto ts3_license_weblist;
81
1.14k
    }
82
966k
  }
83
84
5.50M
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
85
5.50M
  return;
86
87
4.91k
ts3_license_weblist:
88
4.91k
  if (flow->packet_counter == 3)
89
425
  {
90
425
    NDPI_LOG_INFO(ndpi_struct, "found TEAMSPEAK license/weblist\n");
91
425
    ndpi_int_teamspeak_add_connection(ndpi_struct, flow);
92
425
    return;
93
425
  }
94
4.91k
}
95
96
void init_teamspeak_dissector(struct ndpi_detection_module_struct *ndpi_struct)
97
11.4k
{
98
11.4k
  ndpi_register_dissector("TeamSpeak", ndpi_struct,
99
11.4k
                     ndpi_search_teamspeak,
100
11.4k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
101
11.4k
                     1, NDPI_PROTOCOL_TEAMSPEAK);
102
11.4k
}
103