1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* tap-endpoints.c
* endpoints 2014 Michael Mann
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <epan/packet.h>
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <epan/conversation_table.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
typedef struct _endpoints_t {
const char *type;
const char *filter;
conv_hash_t hash;
} endpoints_t;
static void
endpoints_draw(void *arg)
{
conv_hash_t *hash = (conv_hash_t*)arg;
endpoints_t *iu = (endpoints_t *)hash->user_data;
endpoint_item_t *endpoint;
uint64_t last_frames, max_frames;
unsigned i;
bool display_port = (!strncmp(iu->type, "TCP", 3) || !strncmp(iu->type, "UDP", 3) || !strncmp(iu->type, "SCTP", 4)) ? true : false;
printf("================================================================================\n");
printf("%s Endpoints\n", iu->type);
printf("Filter:%s\n", iu->filter ? iu->filter : "<No Filter>");
printf(" | %sPackets | | Bytes | | Tx Packets | | Tx Bytes | | Rx Packets | | Rx Bytes |\n",
display_port ? "Port || " : "");
max_frames = UINT_MAX;
do {
last_frames = 0;
for (i=0; (iu->hash.conv_array && i < iu->hash.conv_array->len); i++) {
uint64_t tot_frames;
endpoint = &g_array_index(iu->hash.conv_array, endpoint_item_t, i);
tot_frames = endpoint->rx_frames + endpoint->tx_frames;
if ((tot_frames > last_frames) && (tot_frames < max_frames)) {
last_frames = tot_frames;
}
}
for (i=0; (iu->hash.conv_array && i < iu->hash.conv_array->len); i++) {
uint64_t tot_frames;
char *conversation_str, *port_str;
endpoint = &g_array_index(iu->hash.conv_array, endpoint_item_t, i);
tot_frames = endpoint->rx_frames + endpoint->tx_frames;
if (tot_frames == last_frames) {
/* XXX - TODO: make name resolution configurable (through gbl_resolv_flags?) */
conversation_str = get_conversation_address(NULL, &endpoint->myaddress, true);
if (display_port) {
/* XXX - TODO: make port resolution configurable (through gbl_resolv_flags?) */
port_str = get_endpoint_port(NULL, endpoint, true);
printf("%-20s %5s %6" PRIu64 " %9" PRIu64
" %6" PRIu64 " %9" PRIu64 " %6"
PRIu64 " %9" PRIu64 " \n",
conversation_str,
port_str,
endpoint->tx_frames+endpoint->rx_frames, endpoint->tx_bytes+endpoint->rx_bytes,
endpoint->tx_frames, endpoint->tx_bytes,
endpoint->rx_frames, endpoint->rx_bytes);
wmem_free(NULL, port_str);
} else {
printf("%-20s %6" PRIu64 " %9" PRIu64
" %6" PRIu64 " %9" PRIu64 " %6"
PRIu64 " %9" PRIu64 " \n",
/* XXX - TODO: make name resolution configurable (through gbl_resolv_flags?) */
conversation_str,
endpoint->tx_frames+endpoint->rx_frames, endpoint->tx_bytes+endpoint->rx_bytes,
endpoint->tx_frames, endpoint->tx_bytes,
endpoint->rx_frames, endpoint->rx_bytes);
}
wmem_free(NULL, conversation_str);
}
}
max_frames = last_frames;
} while (last_frames);
printf("================================================================================\n");
}
void init_endpoints(struct register_ct *ct, const char *filter)
{
endpoints_t *iu;
GString *error_string;
iu = g_new0(endpoints_t, 1);
iu->type = proto_get_protocol_short_name(find_protocol_by_id(get_conversation_proto_id(ct)));
iu->filter = g_strdup(filter);
iu->hash.user_data = iu;
error_string = register_tap_listener(proto_get_protocol_filter_name(get_conversation_proto_id(ct)), &iu->hash, filter, 0, NULL, get_endpoint_packet_func(ct), endpoints_draw, NULL);
if (error_string) {
g_free(iu);
cmdarg_err("Couldn't register endpoint tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/
|