LATER... ei_kerberos_kdc_session_key ...
[wireshark-sm.git] / ui / cli / tap-iousers.c
blob922f0bf89ae502cb11188f406a50bd1412e3f5bd
1 /* tap-iousers.c
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
9 */
11 #include "config.h"
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <string.h>
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 {
24 const char *type;
25 const char *filter;
26 conv_hash_t hash;
27 } io_users_t;
29 static void
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;
34 conv_item_t *iui;
35 uint64_t last_frames, max_frames;
36 struct tm * tm_time;
37 unsigned i;
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()) {
45 case TS_ABSOLUTE:
46 case TS_UTC:
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 ? " " : "");
51 break;
52 case TS_ABSOLUTE_WITH_YMD:
53 case TS_ABSOLUTE_WITH_YDOY:
54 case TS_UTC_WITH_YMD:
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 ? " " : "");
60 break;
61 case TS_EPOCH:
62 printf("%s | <- | | -> | | Total | Relative | Duration |\n",
63 display_ports ? " " : "");
64 printf("%s | Frames Bytes | | Frames Bytes | | Frames Bytes | Start | |\n",
65 display_ports ? " " : "");
66 break;
67 case TS_RELATIVE:
68 case TS_NOT_SET:
69 default:
70 printf("%s | <- | | -> | | Total | Relative | Duration |\n",
71 display_ports ? " " : "");
72 printf("%s | Frames Bytes | | Frames Bytes | | Frames Bytes | Start | |\n",
73 display_ports ? " " : "");
74 break;
77 max_frames = UINT_MAX;
78 do {
79 last_frames = 0;
80 for (i=0; (iu->hash.conv_array && i < iu->hash.conv_array->len); i++) {
81 uint64_t tot_frames;
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++) {
92 uint64_t tot_frames;
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);
108 if (display_ports) {
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"
115 " %6" PRIu64 " %-9s"
116 " %6" PRIu64 " %-9s ",
117 src, dst,
118 iui->rx_frames, rx_bytes,
119 iui->tx_frames, tx_bytes,
120 iui->tx_frames+iui->rx_frames,
121 total_bytes
123 wmem_free(NULL, src_port);
124 wmem_free(NULL, dst_port);
125 wmem_free(NULL, src);
126 wmem_free(NULL, dst);
127 } else {
128 printf("%-20s <-> %-20s %6" PRIu64 " %-9s"
129 " %6" PRIu64 " %-9s"
130 " %6" PRIu64 " %-9s ",
131 src_addr, dst_addr,
132 iui->rx_frames, rx_bytes,
133 iui->tx_frames, tx_bytes,
134 iui->tx_frames+iui->rx_frames,
135 total_bytes
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()) {
146 case TS_ABSOLUTE:
147 tm_time = localtime(&iui->start_abs_time.secs);
148 if (tm_time != NULL) {
149 printf("%02d:%02d:%02d",
150 tm_time->tm_hour,
151 tm_time->tm_min,
152 tm_time->tm_sec);
153 } else
154 printf("XX:XX:XX");
155 break;
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,
161 tm_time->tm_mon + 1,
162 tm_time->tm_mday,
163 tm_time->tm_hour,
164 tm_time->tm_min,
165 tm_time->tm_sec);
166 } else
167 printf("XXXX-XX-XX XX:XX:XX");
168 break;
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,
175 tm_time->tm_hour,
176 tm_time->tm_min,
177 tm_time->tm_sec);
178 } else
179 printf("XXXX/XXX XX:XX:XX");
180 break;
181 case TS_UTC:
182 tm_time = gmtime(&iui->start_abs_time.secs);
183 if (tm_time != NULL) {
184 printf("%02d:%02d:%02d",
185 tm_time->tm_hour,
186 tm_time->tm_min,
187 tm_time->tm_sec);
188 } else
189 printf("XX:XX:XX");
190 break;
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,
196 tm_time->tm_mon + 1,
197 tm_time->tm_mday,
198 tm_time->tm_hour,
199 tm_time->tm_min,
200 tm_time->tm_sec);
201 } else
202 printf("XXXX-XX-XX XX:XX:XX");
203 break;
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,
210 tm_time->tm_hour,
211 tm_time->tm_min,
212 tm_time->tm_sec);
213 } else
214 printf("XXXX/XXX XX:XX:XX");
215 break;
216 case TS_EPOCH:
217 printf("%20.9f", nstime_to_sec(&iui->start_abs_time));
218 break;
219 case TS_RELATIVE:
220 case TS_NOT_SET:
221 default:
222 printf("%14.9f",
223 nstime_to_sec(&iui->start_time));
224 break;
226 printf(" %12.4f\n",
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)
237 io_users_t *iu;
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);
246 if (error_string) {
247 g_free(iu);
248 cmdarg_err("Couldn't register conversations tap: %s",
249 error_string->str);
250 g_string_free(error_string, TRUE);
251 exit(1);
257 * Editor modelines - https://www.wireshark.org/tools/modelines.html
259 * Local variables:
260 * c-basic-offset: 8
261 * tab-width: 8
262 * indent-tabs-mode: t
263 * End:
265 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
266 * :indentSize=8:tabSize=8:noTabs=false: