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
17 #include <epan/packet.h>
18 #include <epan/prefs.h>
19 #include <epan/to_str.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
},
36 static int proto_time
;
37 static int hf_time_time
;
38 static int hf_time_response
;
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 */
50 dissect_time(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
52 proto_tree
*time_tree
;
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,
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
);
76 proto_register_time(void)
78 static hf_register_info hf
[] = {
80 { "Time", "time.time",
81 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
82 "Seconds since 00:00 (midnight) 1 January 1900 GMT", HFILL
}},
84 { "Type", "time.response",
85 FT_BOOLEAN
, BASE_NONE
, TFS(&tfs_response_request
), 0x0,
86 "Response or Request", HFILL
}}
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
,
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
123 * indent-tabs-mode: nil
126 * vi: set shiftwidth=4 tabstop=8 expandtab:
127 * :indentSize=4:tabSize=8:noTabs=true: