Coverage Report

Created: 2025-08-29 06:29

/src/ndpi/src/lib/protocols/sonos.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * sonos.c
3
 *
4
 * Copyright (C) 2024 - 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_SONOS
27
28
#include "ndpi_api.h"
29
#include "ndpi_private.h"
30
31
0
static void ndpi_sonos_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
32
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SONOS, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
33
0
  NDPI_LOG_INFO(ndpi_struct, "Found Sonos flow\n");
34
0
}
35
36
663
void ndpi_search_sonos(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
37
663
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
38
39
663
  NDPI_LOG_DBG(ndpi_struct, "Searching Sonos\n");
40
41
663
  if((!ndpi_is_public_ipv4(ntohl(packet->iph->daddr)))
42
663
     && ((ntohl(packet->iph->daddr) & 0xF0000000) != 0xE0000000 /* Not a multicast address */)) {  
43
17
    if(packet->payload_packet_len == 48) {      
44
0
      u_int16_t sonos_port = htons(12301);
45
      
46
0
      if((packet->udp->dest == sonos_port) || (packet->udp->source == sonos_port)) { 
47
0
  ndpi_sonos_add_connection(ndpi_struct, flow);
48
0
      }
49
17
    } else {
50
17
      u_int16_t sonos_port = htons(7080);
51
      
52
17
      if((packet->udp->dest == sonos_port)
53
17
   && ((packet->payload_packet_len < 200)
54
0
       || ((packet->payload_packet_len > 1000) && (packet->payload_packet_len < 1100)))) {
55
0
  ndpi_sonos_add_connection(ndpi_struct, flow);
56
0
      }
57
17
    }
58
17
  }
59
  
60
663
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
61
663
}
62
63
64
void init_sonos_dissector(struct ndpi_detection_module_struct *ndpi_struct)
65
8.20k
{
66
8.20k
  register_dissector("Sonos", ndpi_struct,
67
8.20k
                     ndpi_search_sonos,
68
8.20k
                     NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD, /* Only IPv4 UDP traffic is expected. */
69
8.20k
                     1, NDPI_PROTOCOL_SONOS);
70
8.20k
}