Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-exablaze.c
blobce73887694945aa72283dabbbef8e87992e927ad
1 /* packet-exablaze.c
2 * Routines for dissection of Exablaze trailers
3 * Copyright 2018 Exablaze
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <math.h>
16 #include <epan/packet.h>
18 void proto_register_exablaze(void);
19 void proto_reg_handoff_exablaze(void);
21 static int proto_exablaze;
23 static int hf_exablaze_original_fcs;
24 static int hf_exablaze_device;
25 static int hf_exablaze_port;
26 static int hf_exablaze_timestamp;
27 static int hf_exablaze_timestamp_integer;
28 static int hf_exablaze_timestamp_fractional;
30 static int ett_exablaze;
31 static int ett_exablaze_timestamp;
33 static int
34 dissect_exablaze(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
35 void *data _U_)
37 proto_item *ti;
38 proto_tree *exablaze_tree;
39 proto_tree *timestamp_tree;
41 unsigned trailer_length;
42 unsigned fcs_length;
43 unsigned offset;
44 bool trailer_found;
46 uint8_t device;
47 uint8_t port;
48 uint32_t timestamp_sec;
49 uint64_t timestamp_frac;
51 nstime_t timestamp;
52 double timestamp_frac_double;
53 struct tm *tm;
55 trailer_length = tvb_reported_length(tvb);
57 if (trailer_length != tvb_captured_length(tvb)) {
58 /* The heuristics require the whole trailer to be captured */
59 return 0;
62 /* Try matching with and without FCS */
63 trailer_found = false;
64 for (fcs_length = 0; fcs_length <= 4; fcs_length += 4)
66 if (trailer_length < fcs_length + 16)
67 continue;
69 offset = trailer_length - fcs_length - 16;
71 device = tvb_get_uint8(tvb, offset + 4);
72 port = tvb_get_uint8(tvb, offset + 5);
73 timestamp_sec = tvb_get_ntohl(tvb, offset + 6);
74 timestamp_frac = tvb_get_ntoh40(tvb, offset + 10);
76 /* If the capture time and timestamp differ by more than a week,
77 * then this is probably not a valid Exablaze trailer */
78 if (timestamp_sec > (unsigned)pinfo->abs_ts.secs) {
79 if (timestamp_sec - pinfo->abs_ts.secs > 604800)
80 continue;
81 } else {
82 if (pinfo->abs_ts.secs - timestamp_sec > 604800)
83 continue;
86 trailer_found = true;
87 break;
90 if (!trailer_found)
91 return 0;
93 /* Fractional part is a 40 bit binary fraction of a second */
94 timestamp.secs = timestamp_sec;
95 timestamp_frac_double = ldexp((double)timestamp_frac, -40);
96 timestamp.nsecs = (int)(timestamp_frac_double * 1000000000);
98 ti = proto_tree_add_item(tree, proto_exablaze, tvb, offset, 16, ENC_NA);
99 proto_item_append_text(ti, ", Device: %u, Port: %u, Timestamp: ",
100 device, port);
102 tm = localtime(&timestamp.secs);
103 if (tm)
104 proto_item_append_text(ti, "%02u:%02u:%02.12f",
105 tm->tm_hour, tm->tm_min, tm->tm_sec + timestamp_frac_double);
106 else
107 proto_item_append_text(ti, "<Not representable>");
109 exablaze_tree = proto_item_add_subtree(ti, ett_exablaze);
110 proto_tree_add_item(exablaze_tree, hf_exablaze_original_fcs, tvb,
111 offset, 4, ENC_BIG_ENDIAN);
112 proto_tree_add_item(exablaze_tree, hf_exablaze_device, tvb,
113 offset + 4, 1, ENC_BIG_ENDIAN);
114 proto_tree_add_item(exablaze_tree, hf_exablaze_port, tvb,
115 offset + 5, 1, ENC_BIG_ENDIAN);
117 ti = proto_tree_add_time(exablaze_tree, hf_exablaze_timestamp, tvb,
118 offset + 6, 9, &timestamp);
119 timestamp_tree = proto_item_add_subtree(ti, ett_exablaze_timestamp);
121 proto_tree_add_item(timestamp_tree, hf_exablaze_timestamp_integer, tvb,
122 offset + 6, 4, ENC_BIG_ENDIAN);
123 proto_tree_add_double_format_value(timestamp_tree,
124 hf_exablaze_timestamp_fractional, tvb, offset + 10, 5,
125 timestamp_frac_double, "%.12f", timestamp_frac_double);
127 return offset + 16;
130 static bool
131 dissect_exablaze_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
133 return dissect_exablaze(tvb, pinfo, tree, data) > 0;
136 void
137 proto_register_exablaze(void)
139 static hf_register_info hf[] = {
141 &hf_exablaze_original_fcs,
143 "Original FCS", "exablaze.original_fcs",
144 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL
148 &hf_exablaze_device,
150 "Device ID", "exablaze.device",
151 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
155 &hf_exablaze_port,
157 "Port", "exablaze.port",
158 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
162 &hf_exablaze_timestamp,
164 "Timestamp", "exablaze.timestamp",
165 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL
168 { &hf_exablaze_timestamp_integer,
170 "Seconds since epoch", "exablaze.timestamp.seconds",
171 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL
174 { &hf_exablaze_timestamp_fractional,
176 "Fractional seconds",
177 "exablaze.timestamp.fractional_seconds",
178 FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL
183 static int *ett[] = {
184 &ett_exablaze,
185 &ett_exablaze_timestamp
188 proto_exablaze = proto_register_protocol("Exablaze trailer", "Exablaze",
189 "exablaze");
190 proto_register_field_array(proto_exablaze, hf, array_length(hf));
191 proto_register_subtree_array(ett, array_length(ett));
194 void
195 proto_reg_handoff_exablaze(void)
197 heur_dissector_add("eth.trailer", dissect_exablaze_heur, "Exablaze trailer",
198 "exablaze_eth", proto_exablaze, HEURISTIC_DISABLE);
202 * Editor modelines - https://www.wireshark.org/tools/modelines.html
204 * Local variables:
205 * c-basic-offset: 4
206 * tab-width: 8
207 * indent-tabs-mode: nil
208 * End:
210 * vi: set shiftwidth=4 tabstop=8 expandtab:
211 * :indentSize=4:tabSize=8:noTabs=true: