Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-time.c
blob9cf82b2661a45829f8fc93393629650e4b5120ff
1 /* packet-time.c
2 * Routines for Time Protocol (RFC 868) packet dissection
4 * Richard Sharpe <rsharpe@ns.aus.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-tftp.c
12 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/prefs.h>
19 #include <epan/to_str.h>
20 #include <epan/tfs.h>
21 #include <wsutil/array.h>
23 #include <wsutil/epochs.h>
25 void proto_reg_handoff_time(void);
26 void proto_register_time(void);
28 static dissector_handle_t time_handle;
30 static const enum_val_t time_display_types[] = {
31 { "UTC", "UTC", ABSOLUTE_TIME_UTC },
32 { "Local", "Local", ABSOLUTE_TIME_LOCAL},
33 { NULL, NULL, 0 }
36 static int proto_time;
37 static int hf_time_time;
38 static int hf_time_response;
40 static int ett_time;
42 /* Use int instead of a field_display_type_e enum to avoid incompatible
43 * pointer type warnings with prefs_register_enum_preference() */
44 static int time_display_type = ABSOLUTE_TIME_LOCAL;
46 /* This dissector works for TCP and UDP time packets */
47 #define TIME_PORT 37
49 static int
50 dissect_time(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
52 proto_tree *time_tree;
53 proto_item *ti;
55 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TIME");
57 col_add_fstr(pinfo->cinfo, COL_INFO, "TIME %s",
58 pinfo->srcport == pinfo->match_uint ? "Response":"Request");
60 ti = proto_tree_add_item(tree, proto_time, tvb, 0, -1, ENC_NA);
61 time_tree = proto_item_add_subtree(ti, ett_time);
63 proto_tree_add_boolean(time_tree, hf_time_response, tvb, 0, 0, pinfo->srcport==pinfo->match_uint);
64 if (pinfo->srcport == pinfo->match_uint) {
65 /* seconds since 1900-01-01 00:00:00 GMT, *not* 1970 */
66 uint32_t delta_seconds = tvb_get_ntohl(tvb, 0);
67 proto_tree_add_uint_format(time_tree, hf_time_time, tvb, 0, 4,
68 delta_seconds, "%s",
69 abs_time_secs_to_str(pinfo->pool, delta_seconds-EPOCH_DELTA_1900_01_01_00_00_00_UTC,
70 time_display_type, true));
72 return tvb_captured_length(tvb);
75 void
76 proto_register_time(void)
78 static hf_register_info hf[] = {
79 { &hf_time_time,
80 { "Time", "time.time",
81 FT_UINT32, BASE_DEC, NULL, 0x0,
82 "Seconds since 00:00 (midnight) 1 January 1900 GMT", HFILL }},
83 { &hf_time_response,
84 { "Type", "time.response",
85 FT_BOOLEAN, BASE_NONE, TFS(&tfs_response_request), 0x0,
86 "Response or Request", HFILL }}
89 static int *ett[] = {
90 &ett_time,
93 module_t *time_pref ;
95 proto_time = proto_register_protocol("Time Protocol", "TIME", "time");
96 proto_register_field_array(proto_time, hf, array_length(hf));
97 proto_register_subtree_array(ett, array_length(ett));
98 time_handle = register_dissector("time", dissect_time, proto_time);
100 time_pref = prefs_register_protocol(proto_time, NULL);
101 prefs_register_enum_preference(time_pref,
102 "display_time_type",
103 "Time Display",
104 "Time display type",
105 &time_display_type,
106 time_display_types,
107 false);
110 void
111 proto_reg_handoff_time(void)
113 dissector_add_uint_with_preference("udp.port", TIME_PORT, time_handle);
114 dissector_add_uint_with_preference("tcp.port", TIME_PORT, time_handle);
118 * Editor modelines - https://www.wireshark.org/tools/modelines.html
120 * Local variables:
121 * c-basic-offset: 4
122 * tab-width: 8
123 * indent-tabs-mode: nil
124 * End:
126 * vi: set shiftwidth=4 tabstop=8 expandtab:
127 * :indentSize=4:tabSize=8:noTabs=true: