2 * iostat 2003 Ronnie Sahlberg
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/packet.h>
18 #include <epan/timestamp.h>
19 #include <wsutil/str_util.h>
20 #include <wsutil/cmdarg_err.h>
21 #include <ui/cli/tshark-tap.h>
23 typedef struct _io_users_t
{
30 iousers_draw(void *arg
)
32 conv_hash_t
*hash
= (conv_hash_t
*)arg
;
33 io_users_t
*iu
= (io_users_t
*)hash
->user_data
;
35 uint64_t last_frames
, max_frames
;
38 bool display_ports
= (!strncmp(iu
->type
, "TCP", 3) || !strncmp(iu
->type
, "UDP", 3) || !strncmp(iu
->type
, "SCTP", 4)) ? true : false;
40 printf("================================================================================\n");
41 printf("%s Conversations\n", iu
->type
);
42 printf("Filter:%s\n", iu
->filter
? iu
->filter
: "<No Filter>");
44 switch (timestamp_get_type()) {
47 printf("%s | <- | | -> | | Total | Absolute Time | Duration |\n",
48 display_ports
? " " : "");
49 printf("%s | Frames Size | | Frames Size | | Frames Size | Start | |\n",
50 display_ports
? " " : "");
52 case TS_ABSOLUTE_WITH_YMD
:
53 case TS_ABSOLUTE_WITH_YDOY
:
55 case TS_UTC_WITH_YDOY
:
56 printf("%s | <- | | -> | | Total | Absolute Date | Duration |\n",
57 display_ports
? " " : "");
58 printf("%s | Frames Size | | Frames Size | | Frames Size | Start | |\n",
59 display_ports
? " " : "");
62 printf("%s | <- | | -> | | Total | Relative | Duration |\n",
63 display_ports
? " " : "");
64 printf("%s | Frames Bytes | | Frames Bytes | | Frames Bytes | Start | |\n",
65 display_ports
? " " : "");
70 printf("%s | <- | | -> | | Total | Relative | Duration |\n",
71 display_ports
? " " : "");
72 printf("%s | Frames Bytes | | Frames Bytes | | Frames Bytes | Start | |\n",
73 display_ports
? " " : "");
77 max_frames
= UINT_MAX
;
80 for (i
=0; (iu
->hash
.conv_array
&& i
< iu
->hash
.conv_array
->len
); i
++) {
83 iui
= &g_array_index(iu
->hash
.conv_array
, conv_item_t
, i
);
84 tot_frames
= iui
->rx_frames
+ iui
->tx_frames
;
86 if ((tot_frames
> last_frames
) && (tot_frames
< max_frames
)) {
87 last_frames
= tot_frames
;
91 for (i
=0; (iu
->hash
.conv_array
&& i
< iu
->hash
.conv_array
->len
); i
++) {
93 char *src_addr
, *dst_addr
;
95 iui
= &g_array_index(iu
->hash
.conv_array
, conv_item_t
, i
);
96 tot_frames
= iui
->rx_frames
+ iui
->tx_frames
;
98 if (tot_frames
== last_frames
) {
99 char *rx_bytes
, *tx_bytes
, *total_bytes
;
101 rx_bytes
= format_size(iui
->rx_bytes
, FORMAT_SIZE_UNIT_BYTES
, 0);
102 tx_bytes
= format_size(iui
->tx_bytes
, FORMAT_SIZE_UNIT_BYTES
, 0);
103 total_bytes
= format_size(iui
->tx_bytes
+ iui
->rx_bytes
, FORMAT_SIZE_UNIT_BYTES
, 0);
105 /* XXX - TODO: make name / port resolution configurable (through gbl_resolv_flags?) */
106 src_addr
= get_conversation_address(NULL
, &iui
->src_address
, true);
107 dst_addr
= get_conversation_address(NULL
, &iui
->dst_address
, true);
109 char *src
, *dst
, *src_port
, *dst_port
;
110 src_port
= get_conversation_port(NULL
, iui
->src_port
, iui
->ctype
, true);
111 dst_port
= get_conversation_port(NULL
, iui
->dst_port
, iui
->ctype
, true);
112 src
= wmem_strconcat(NULL
, src_addr
, ":", src_port
, NULL
);
113 dst
= wmem_strconcat(NULL
, dst_addr
, ":", dst_port
, NULL
);
114 printf("%-26s <-> %-26s %6" PRIu64
" %-9s"
116 " %6" PRIu64
" %-9s ",
118 iui
->rx_frames
, rx_bytes
,
119 iui
->tx_frames
, tx_bytes
,
120 iui
->tx_frames
+iui
->rx_frames
,
123 wmem_free(NULL
, src_port
);
124 wmem_free(NULL
, dst_port
);
125 wmem_free(NULL
, src
);
126 wmem_free(NULL
, dst
);
128 printf("%-20s <-> %-20s %6" PRIu64
" %-9s"
130 " %6" PRIu64
" %-9s ",
132 iui
->rx_frames
, rx_bytes
,
133 iui
->tx_frames
, tx_bytes
,
134 iui
->tx_frames
+iui
->rx_frames
,
139 wmem_free(NULL
, src_addr
);
140 wmem_free(NULL
, dst_addr
);
141 wmem_free(NULL
, rx_bytes
);
142 wmem_free(NULL
, tx_bytes
);
143 wmem_free(NULL
, total_bytes
);
145 switch (timestamp_get_type()) {
147 tm_time
= localtime(&iui
->start_abs_time
.secs
);
148 if (tm_time
!= NULL
) {
149 printf("%02d:%02d:%02d",
156 case TS_ABSOLUTE_WITH_YMD
:
157 tm_time
= localtime(&iui
->start_abs_time
.secs
);
158 if (tm_time
!= NULL
) {
159 printf("%04d-%02d-%02d %02d:%02d:%02d",
160 tm_time
->tm_year
+ 1900,
167 printf("XXXX-XX-XX XX:XX:XX");
169 case TS_ABSOLUTE_WITH_YDOY
:
170 tm_time
= localtime(&iui
->start_abs_time
.secs
);
171 if (tm_time
!= NULL
) {
172 printf("%04d/%03d %02d:%02d:%02d",
173 tm_time
->tm_year
+ 1900,
174 tm_time
->tm_yday
+ 1,
179 printf("XXXX/XXX XX:XX:XX");
182 tm_time
= gmtime(&iui
->start_abs_time
.secs
);
183 if (tm_time
!= NULL
) {
184 printf("%02d:%02d:%02d",
191 case TS_UTC_WITH_YMD
:
192 tm_time
= gmtime(&iui
->start_abs_time
.secs
);
193 if (tm_time
!= NULL
) {
194 printf("%04d-%02d-%02d %02d:%02d:%02d",
195 tm_time
->tm_year
+ 1900,
202 printf("XXXX-XX-XX XX:XX:XX");
204 case TS_UTC_WITH_YDOY
:
205 tm_time
= gmtime(&iui
->start_abs_time
.secs
);
206 if (tm_time
!= NULL
) {
207 printf("%04d/%03d %02d:%02d:%02d",
208 tm_time
->tm_year
+ 1900,
209 tm_time
->tm_yday
+ 1,
214 printf("XXXX/XXX XX:XX:XX");
217 printf("%20.9f", nstime_to_sec(&iui
->start_abs_time
));
223 nstime_to_sec(&iui
->start_time
));
227 nstime_to_sec(&iui
->stop_time
) - nstime_to_sec(&iui
->start_time
));
230 max_frames
= last_frames
;
231 } while (last_frames
);
232 printf("================================================================================\n");
235 void init_iousers(struct register_ct
*ct
, const char *filter
)
238 GString
*error_string
;
240 iu
= g_new0(io_users_t
, 1);
241 iu
->type
= proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(ct
)));
242 iu
->filter
= g_strdup(filter
);
243 iu
->hash
.user_data
= iu
;
245 error_string
= register_tap_listener(proto_get_protocol_filter_name(get_conversation_proto_id(ct
)), &iu
->hash
, filter
, 0, NULL
, get_conversation_packet_func(ct
), iousers_draw
, NULL
);
248 cmdarg_err("Couldn't register conversations tap: %s",
250 g_string_free(error_string
, TRUE
);
257 * Editor modelines - https://www.wireshark.org/tools/modelines.html
262 * indent-tabs-mode: t
265 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
266 * :indentSize=8:tabSize=8:noTabs=false: