Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-echo.c
Line
Count
Source
1
/* packet-echo.c
2
 * Routines for ECHO packet disassembly (RFC862)
3
 *
4
 * Only useful to mark the packets as ECHO in the summary and in the
5
 * protocol hierarchy statistics (since not so many fields to decode ;-)
6
 *
7
 * Laurent Deniel <laurent.deniel@free.fr>
8
 *
9
 * Wireshark - Network traffic analyzer
10
 * By Gerald Combs <gerald@wireshark.org>
11
 * Copyright 1998 Gerald Combs
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
16
#include "config.h"
17
18
#include <epan/packet.h>
19
20
28
#define ECHO_PORT  7
21
22
void proto_register_echo(void);
23
void proto_reg_handoff_echo(void);
24
25
static dissector_handle_t echo_handle;
26
static dissector_handle_t wol_handle;
27
static int proto_echo;
28
29
static int hf_echo_data;
30
static int hf_echo_request;
31
static int hf_echo_response;
32
33
static int ett_echo;
34
35
static int dissect_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
36
9
{
37
9
  bool        request;
38
9
  proto_tree *echo_tree;
39
9
  proto_item *ti, *hidden_item;
40
41
9
  request = (pinfo->destport == pinfo->match_uint);
42
43
9
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "ECHO");
44
9
  col_set_str(pinfo->cinfo, COL_INFO, request ? "Request" : "Response");
45
46
9
  ti = proto_tree_add_item(tree, proto_echo, tvb, 0, -1, ENC_NA);
47
9
  echo_tree = proto_item_add_subtree(ti, ett_echo);
48
49
9
  hidden_item = proto_tree_add_boolean(echo_tree,
50
9
      request ?  hf_echo_request : hf_echo_response, tvb, 0, 0, 1);
51
9
  proto_item_set_hidden(hidden_item);
52
53
9
  proto_tree_add_item(echo_tree, hf_echo_data, tvb, 0, -1, ENC_NA);
54
55
9
  return tvb_captured_length(tvb);
56
9
}
57
58
static int
59
dissect_echo_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
60
5
{
61
  /* Wake On Lan is commonly used over UDP port 7 and has strong heuristics,
62
   * whereas the echo dissector never rejects a packet, so try WOL first.
63
   * Unfortunately "echo" still ends up in frame.protocols this way.
64
   */
65
5
  if (wol_handle && call_dissector_only(wol_handle, tvb, pinfo, tree, data)) {
66
0
    return tvb_captured_length(tvb);
67
0
  }
68
5
  return dissect_echo(tvb, pinfo, tree, data);
69
5
}
70
71
void proto_register_echo(void)
72
14
{
73
74
14
  static hf_register_info hf[] = {
75
14
    { &hf_echo_data,
76
14
      { "Echo data", "echo.data", FT_BYTES, BASE_NONE,
77
14
        NULL, 0x0, NULL, HFILL }},
78
14
    { &hf_echo_request,
79
14
      { "Echo request", "echo.request", FT_BOOLEAN, BASE_NONE,
80
14
        NULL, 0x0, NULL, HFILL }},
81
14
    { &hf_echo_response,
82
14
      { "Echo response","echo.response", FT_BOOLEAN, BASE_NONE,
83
14
        NULL, 0x0, NULL, HFILL }}
84
14
  };
85
86
14
  static int *ett[] = {
87
14
    &ett_echo
88
14
  };
89
90
14
  proto_echo = proto_register_protocol("Echo", "ECHO", "echo");
91
14
  proto_register_field_array(proto_echo, hf, array_length(hf));
92
14
  proto_register_subtree_array(ett, array_length(ett));
93
14
  echo_handle = register_dissector("echo", dissect_echo, proto_echo);
94
14
}
95
96
void proto_reg_handoff_echo(void)
97
14
{
98
14
  dissector_add_uint_with_preference("udp.port", ECHO_PORT, create_dissector_handle(dissect_echo_udp, proto_echo));
99
14
  dissector_add_uint_with_preference("tcp.port", ECHO_PORT, echo_handle);
100
101
14
  wol_handle = find_dissector_add_dependency("wol", proto_echo);
102
14
}
103
104
/*
105
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
106
 *
107
 * Local Variables:
108
 * c-basic-offset: 2
109
 * tab-width: 8
110
 * indent-tabs-mode: nil
111
 * End:
112
 *
113
 * ex: set shiftwidth=2 tabstop=8 expandtab:
114
 * :indentSize=2:tabSize=8:noTabs=true:
115
 */