/src/wireshark/epan/dissectors/packet-daytime.c
Line | Count | Source |
1 | | /* packet-daytime.c |
2 | | * Routines for Daytime Protocol (RFC 867) packet dissection |
3 | | * Copyright 2006, Stephen Fisher (see AUTHORS file) |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * Copied from packet-time.c |
10 | | * |
11 | | * SPDX-License-Identifier: GPL-2.0-or-later |
12 | | */ |
13 | | #include "config.h" |
14 | | |
15 | | #include <epan/packet.h> |
16 | | #include <epan/tfs.h> |
17 | | |
18 | | void proto_register_daytime(void); |
19 | | void proto_reg_handoff_daytime(void); |
20 | | |
21 | | static dissector_handle_t daytime_handle; |
22 | | |
23 | | static int proto_daytime; |
24 | | |
25 | | static int hf_daytime_string; |
26 | | static int hf_response_request; |
27 | | |
28 | | static int ett_daytime; |
29 | | |
30 | | /* This dissector works for TCP and UDP daytime packets */ |
31 | 50 | #define DAYTIME_PORT 13 |
32 | | |
33 | | static int |
34 | | dissect_daytime(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
35 | 11 | { |
36 | 11 | proto_tree *daytime_tree; |
37 | 11 | proto_item *ti; |
38 | | |
39 | 11 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "DAYTIME"); |
40 | | |
41 | 11 | col_add_fstr(pinfo->cinfo, COL_INFO, "DAYTIME %s", |
42 | 11 | pinfo->srcport == pinfo->match_uint ? "Response":"Request"); |
43 | | |
44 | 11 | if (tree) { |
45 | | |
46 | 11 | ti = proto_tree_add_item(tree, proto_daytime, tvb, 0, -1, ENC_NA); |
47 | 11 | daytime_tree = proto_item_add_subtree(ti, ett_daytime); |
48 | | |
49 | 11 | proto_tree_add_boolean(daytime_tree, hf_response_request, tvb, 0, 0, pinfo->srcport==DAYTIME_PORT); |
50 | 11 | if (pinfo->srcport == DAYTIME_PORT) { |
51 | 2 | proto_tree_add_item(daytime_tree, hf_daytime_string, tvb, 0, -1, ENC_ASCII); |
52 | 2 | } |
53 | 11 | } |
54 | 11 | return tvb_captured_length(tvb); |
55 | 11 | } |
56 | | |
57 | | void |
58 | | proto_register_daytime(void) |
59 | 14 | { |
60 | 14 | static hf_register_info hf[] = { |
61 | 14 | { &hf_daytime_string, |
62 | 14 | { "Daytime", "daytime.string", |
63 | 14 | FT_STRING, BASE_NONE, NULL, 0x0, |
64 | 14 | "String containing time and date", HFILL } |
65 | 14 | }, |
66 | 14 | { &hf_response_request, |
67 | 14 | { "Type", "daytime.response_request", |
68 | 14 | FT_BOOLEAN, BASE_NONE, TFS(&tfs_response_request), 0x0, |
69 | 14 | NULL, HFILL } |
70 | 14 | }, |
71 | 14 | }; |
72 | | |
73 | 14 | static int *ett[] = { |
74 | 14 | &ett_daytime, |
75 | 14 | }; |
76 | | |
77 | 14 | proto_daytime = proto_register_protocol("Daytime Protocol", "DAYTIME", "daytime"); |
78 | 14 | proto_register_field_array(proto_daytime, hf, array_length(hf)); |
79 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
80 | | |
81 | 14 | daytime_handle = register_dissector("daytime", dissect_daytime, proto_daytime); |
82 | 14 | } |
83 | | |
84 | | void |
85 | | proto_reg_handoff_daytime(void) |
86 | 14 | { |
87 | 14 | dissector_add_uint_with_preference("udp.port", DAYTIME_PORT, daytime_handle); |
88 | 14 | dissector_add_uint_with_preference("tcp.port", DAYTIME_PORT, daytime_handle); |
89 | 14 | } |
90 | | |
91 | | /* |
92 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
93 | | * |
94 | | * Local Variables: |
95 | | * c-basic-offset: 2 |
96 | | * tab-width: 8 |
97 | | * indent-tabs-mode: nil |
98 | | * End: |
99 | | * |
100 | | * ex: set shiftwidth=2 tabstop=8 expandtab: |
101 | | * :indentSize=2:tabSize=8:noTabs=true: |
102 | | */ |