Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-time.c
Line
Count
Source
1
/* packet-time.c
2
 * Routines for Time Protocol (RFC 868) packet dissection
3
 *
4
 * Richard Sharpe <rsharpe@ns.aus.com>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * Copied from packet-tftp.c
11
 *
12
 * SPDX-License-Identifier: GPL-2.0-or-later
13
 */
14
15
#include "config.h"
16
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>
22
23
#include <wsutil/epochs.h>
24
25
void proto_reg_handoff_time(void);
26
void proto_register_time(void);
27
28
static dissector_handle_t time_handle;
29
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 }
34
};
35
36
static int proto_time;
37
static int hf_time_time;
38
static int hf_time_response;
39
40
static int ett_time;
41
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;
45
46
/* This dissector works for TCP and UDP time packets */
47
30
#define TIME_PORT 37
48
49
static int
50
dissect_time(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
51
10
{
52
10
    proto_tree    *time_tree;
53
10
    proto_item    *ti;
54
55
10
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "TIME");
56
57
10
    col_add_fstr(pinfo->cinfo, COL_INFO, "TIME %s",
58
10
            pinfo->srcport == pinfo->match_uint ? "Response":"Request");
59
60
10
    ti = proto_tree_add_item(tree, proto_time, tvb, 0, -1, ENC_NA);
61
10
    time_tree = proto_item_add_subtree(ti, ett_time);
62
63
10
    proto_tree_add_boolean(time_tree, hf_time_response, tvb, 0, 0, pinfo->srcport==pinfo->match_uint);
64
10
    if (pinfo->srcport == pinfo->match_uint) {
65
        /* seconds since 1900-01-01 00:00:00 GMT, *not* 1970 */
66
4
        uint32_t delta_seconds = tvb_get_ntohl(tvb, 0);
67
4
        proto_tree_add_uint_format(time_tree, hf_time_time, tvb, 0, 4,
68
4
                delta_seconds, "%s",
69
4
                abs_time_secs_to_str(pinfo->pool, delta_seconds-EPOCH_DELTA_1900_01_01_00_00_00_UTC,
70
4
                                        time_display_type, true));
71
4
    }
72
10
    return tvb_captured_length(tvb);
73
10
}
74
75
void
76
proto_register_time(void)
77
15
{
78
15
    static hf_register_info hf[] = {
79
15
        { &hf_time_time,
80
15
            { "Time", "time.time",
81
15
                FT_UINT32, BASE_DEC, NULL, 0x0,
82
15
                "Seconds since 00:00 (midnight) 1 January 1900 GMT", HFILL }},
83
15
        { &hf_time_response,
84
15
            { "Type", "time.response",
85
15
                FT_BOOLEAN, BASE_NONE, TFS(&tfs_response_request), 0x0,
86
15
                "Response or Request", HFILL }}
87
15
    };
88
89
15
    static int *ett[] = {
90
15
        &ett_time,
91
15
    };
92
93
15
    module_t *time_pref ;
94
95
15
    proto_time = proto_register_protocol("Time Protocol", "TIME", "time");
96
15
    proto_register_field_array(proto_time, hf, array_length(hf));
97
15
    proto_register_subtree_array(ett, array_length(ett));
98
15
    time_handle = register_dissector("time", dissect_time, proto_time);
99
100
15
    time_pref = prefs_register_protocol(proto_time, NULL);
101
15
    prefs_register_enum_preference(time_pref,
102
15
            "display_time_type",
103
15
            "Time Display",
104
15
            "Time display type",
105
15
            &time_display_type,
106
15
            time_display_types,
107
15
            false);
108
15
}
109
110
void
111
proto_reg_handoff_time(void)
112
15
{
113
15
    dissector_add_uint_with_preference("udp.port", TIME_PORT, time_handle);
114
15
    dissector_add_uint_with_preference("tcp.port", TIME_PORT, time_handle);
115
15
}
116
117
/*
118
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
119
 *
120
 * Local variables:
121
 * c-basic-offset: 4
122
 * tab-width: 8
123
 * indent-tabs-mode: nil
124
 * End:
125
 *
126
 * vi: set shiftwidth=4 tabstop=8 expandtab:
127
 * :indentSize=4:tabSize=8:noTabs=true:
128
 */