HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-daytime.c
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
14 #define NEW_PROTO_TREE_API
15
16 #include "config.h"
17
18 #include <epan/packet.h>
19
20 void proto_register_daytime(void);
21 void proto_reg_handoff_daytime(void);
22
23 static dissector_handle_t daytime_handle;
24
25 static header_field_info *hfi_daytime = NULL;
26
27 #define DAYTIME_HFI_INIT HFI_INIT(proto_daytime)
28
29 static header_field_info hfi_daytime_string DAYTIME_HFI_INIT =
30 { "Daytime", "daytime.string",
31   FT_STRING, BASE_NONE, NULL, 0x0,
32   "String containing time and date", HFILL };
33
34 static header_field_info hfi_response_request DAYTIME_HFI_INIT =
35 { "Type", "daytime.response_request",
36   FT_BOOLEAN, 8, TFS(&tfs_response_request), 0x0,
37   NULL, HFILL };
38
39 static gint ett_daytime = -1;
40
41 /* This dissector works for TCP and UDP daytime packets */
42 #define DAYTIME_PORT 13
43
44 static int
45 dissect_daytime(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
46 {
47   proto_tree    *daytime_tree;
48   proto_item    *ti;
49
50   col_set_str(pinfo->cinfo, COL_PROTOCOL, "DAYTIME");
51
52   col_add_fstr(pinfo->cinfo, COL_INFO, "DAYTIME %s",
53     pinfo->srcport == pinfo->match_uint ? "Response":"Request");
54
55   if (tree) {
56
57     ti = proto_tree_add_item(tree, hfi_daytime, tvb, 0, -1, ENC_NA);
58     daytime_tree = proto_item_add_subtree(ti, ett_daytime);
59
60     proto_tree_add_boolean(daytime_tree, &hfi_response_request, tvb, 0, 0, pinfo->srcport==DAYTIME_PORT);
61     if (pinfo->srcport == DAYTIME_PORT) {
62       proto_tree_add_item(daytime_tree, &hfi_daytime_string, tvb, 0, -1, ENC_ASCII|ENC_NA);
63     }
64   }
65   return tvb_captured_length(tvb);
66 }
67
68 void
69 proto_register_daytime(void)
70 {
71 #ifndef HAVE_HFI_SECTION_INIT
72   static header_field_info *hfi[] = {
73     &hfi_daytime_string,
74     &hfi_response_request,
75   };
76 #endif
77
78   static gint *ett[] = {
79     &ett_daytime,
80   };
81
82   int proto_daytime;
83
84   proto_daytime = proto_register_protocol("Daytime Protocol", "DAYTIME", "daytime");
85   hfi_daytime = proto_registrar_get_nth(proto_daytime);
86
87   proto_register_fields(proto_daytime, hfi, array_length(hfi));
88   proto_register_subtree_array(ett, array_length(ett));
89
90   daytime_handle = create_dissector_handle(dissect_daytime, proto_daytime);
91 }
92
93 void
94 proto_reg_handoff_daytime(void)
95 {
96   dissector_add_uint_with_preference("udp.port", DAYTIME_PORT, daytime_handle);
97   dissector_add_uint_with_preference("tcp.port", DAYTIME_PORT, daytime_handle);
98 }
99
100 /*
101  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
102  *
103  * Local Variables:
104  * c-basic-offset: 2
105  * tab-width: 8
106  * indent-tabs-mode: nil
107  * End:
108  *
109  * ex: set shiftwidth=2 tabstop=8 expandtab:
110  * :indentSize=2:tabSize=8:noTabs=true:
111  */