| File: | ui/cli/tap-flow.c |
| Warning: | line 100, column 16 Potential leak of memory pointed to by 'flow_info' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* tap-flow.c | |||
| 2 | * | |||
| 3 | * Wireshark - Network traffic analyzer | |||
| 4 | * By Gerald Combs <gerald@wireshark.org> | |||
| 5 | * Copyright 1998 Gerald Combs | |||
| 6 | * | |||
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later | |||
| 8 | */ | |||
| 9 | ||||
| 10 | /* This module provides udp and tcp follow stream capabilities to tshark. | |||
| 11 | * It is only used by tshark and not wireshark. | |||
| 12 | */ | |||
| 13 | ||||
| 14 | #include "config.h" | |||
| 15 | ||||
| 16 | #include <stdio.h> | |||
| 17 | #include <stdlib.h> | |||
| 18 | ||||
| 19 | #include <epan/sequence_analysis.h> | |||
| 20 | #include <epan/stat_tap_ui.h> | |||
| 21 | #include <epan/tap.h> | |||
| 22 | #include <wsutil/cmdarg_err.h> | |||
| 23 | ||||
| 24 | void register_tap_listener_flow(void); | |||
| 25 | ||||
| 26 | #define STR_FLOW"flow," "flow," | |||
| 27 | #define STR_STANDARD",standard" ",standard" | |||
| 28 | #define STR_NETWORK",network" ",network" | |||
| 29 | ||||
| 30 | static void | |||
| 31 | flow_draw(void *arg) | |||
| 32 | { | |||
| 33 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg; | |||
| 34 | ||||
| 35 | sequence_analysis_get_nodes(flow_info); | |||
| 36 | ||||
| 37 | sequence_analysis_dump_to_file(stdoutstdout, flow_info, 0); | |||
| 38 | } | |||
| 39 | ||||
| 40 | static void | |||
| 41 | flow_finish(void *arg) | |||
| 42 | { | |||
| 43 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg; | |||
| 44 | //clean up the data | |||
| 45 | sequence_analysis_list_free(flow_info); | |||
| 46 | sequence_analysis_info_free(flow_info); | |||
| 47 | } | |||
| 48 | ||||
| 49 | static void | |||
| 50 | flow_reset(void *arg) | |||
| 51 | { | |||
| 52 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg; | |||
| 53 | sequence_analysis_list_free(flow_info); | |||
| 54 | } | |||
| 55 | ||||
| 56 | static bool_Bool flow_arg_strncmp(const char **opt_argp, const char *strp) | |||
| 57 | { | |||
| 58 | size_t len = strlen(strp); | |||
| 59 | ||||
| 60 | if (strncmp(*opt_argp, strp, len) == 0) | |||
| 61 | { | |||
| 62 | *opt_argp += len; | |||
| 63 | return true1; | |||
| 64 | } | |||
| 65 | return false0; | |||
| 66 | } | |||
| 67 | ||||
| 68 | static bool_Bool | |||
| 69 | flow_arg_mode(const char **opt_argp, seq_analysis_info_t *flow_info) | |||
| 70 | { | |||
| 71 | if (flow_arg_strncmp(opt_argp, STR_STANDARD",standard")) | |||
| 72 | { | |||
| 73 | flow_info->any_addr = 1; | |||
| 74 | } | |||
| 75 | else if (flow_arg_strncmp(opt_argp, STR_NETWORK",network")) | |||
| 76 | { | |||
| 77 | flow_info->any_addr = 0; | |||
| 78 | } | |||
| 79 | else | |||
| 80 | { | |||
| 81 | cmdarg_err("Invalid address type."); | |||
| 82 | return false0; | |||
| 83 | } | |||
| 84 | ||||
| 85 | return true1; | |||
| 86 | } | |||
| 87 | ||||
| 88 | static bool_Bool | |||
| 89 | flow_init(const char *opt_argp, void *userdata) | |||
| 90 | { | |||
| 91 | seq_analysis_info_t *flow_info = g_new0(seq_analysis_info_t, 1)((seq_analysis_info_t *) g_malloc0_n ((1), sizeof (seq_analysis_info_t ))); | |||
| ||||
| 92 | GString *errp; | |||
| 93 | register_analysis_t* analysis = (register_analysis_t*)userdata; | |||
| 94 | const char *filter=NULL((void*)0); | |||
| 95 | ||||
| 96 | opt_argp += strlen(STR_FLOW"flow,"); | |||
| 97 | opt_argp += strlen(sequence_analysis_get_name(analysis)); | |||
| 98 | ||||
| 99 | if (!flow_arg_mode(&opt_argp, flow_info)) | |||
| 100 | return false0; | |||
| ||||
| 101 | ||||
| 102 | if (*opt_argp == ',') { | |||
| 103 | filter = opt_argp + 1; | |||
| 104 | } | |||
| 105 | ||||
| 106 | sequence_analysis_list_free(flow_info); | |||
| 107 | ||||
| 108 | errp = register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), flow_info, filter, sequence_analysis_get_tap_flags(analysis), | |||
| 109 | flow_reset, sequence_analysis_get_packet_func(analysis), flow_draw, flow_finish); | |||
| 110 | ||||
| 111 | if (errp != NULL((void*)0)) | |||
| 112 | { | |||
| 113 | sequence_analysis_list_free(flow_info); | |||
| 114 | sequence_analysis_info_free(flow_info); | |||
| 115 | cmdarg_err("Couldn't register %s tap: %s", | |||
| 116 | sequence_analysis_get_tap_listener_name(analysis), errp->str); | |||
| 117 | g_string_free(errp, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (errp), ((!(0)))) : g_string_free_and_steal (errp)) : (g_string_free ) ((errp), ((!(0))))); | |||
| 118 | return false0; | |||
| 119 | } | |||
| 120 | ||||
| 121 | return true1; | |||
| 122 | } | |||
| 123 | ||||
| 124 | static bool_Bool | |||
| 125 | flow_register(const void *key _U___attribute__((unused)), void *value, void *userdata _U___attribute__((unused))) | |||
| 126 | { | |||
| 127 | register_analysis_t* analysis = (register_analysis_t*)value; | |||
| 128 | stat_tap_ui flow_ui; | |||
| 129 | GString *cmd_str = g_string_new(STR_FLOW"flow,"); | |||
| 130 | char *cli_string; | |||
| 131 | ||||
| 132 | g_string_append(cmd_str, sequence_analysis_get_name(analysis))(__builtin_constant_p (sequence_analysis_get_name(analysis)) ? __extension__ ({ const char * const __val = (sequence_analysis_get_name (analysis)); g_string_append_len_inline (cmd_str, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val))) : (gssize ) -1); }) : g_string_append_len_inline (cmd_str, sequence_analysis_get_name (analysis), (gssize) -1)); | |||
| 133 | cli_string = g_string_free(cmd_str, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((cmd_str ), ((0))) : g_string_free_and_steal (cmd_str)) : (g_string_free ) ((cmd_str), ((0)))); | |||
| 134 | ||||
| 135 | flow_ui.group = REGISTER_STAT_GROUP_GENERIC; | |||
| 136 | flow_ui.title = NULL((void*)0); /* construct this from the protocol info? */ | |||
| 137 | flow_ui.cli_string = cli_string; | |||
| 138 | flow_ui.tap_init_cb = flow_init; | |||
| 139 | flow_ui.nparams = 0; | |||
| 140 | flow_ui.params = NULL((void*)0); | |||
| 141 | register_stat_tap_ui(&flow_ui, analysis); | |||
| 142 | g_free(cli_string); | |||
| 143 | return false0; | |||
| 144 | } | |||
| 145 | ||||
| 146 | void | |||
| 147 | register_tap_listener_flow(void) | |||
| 148 | { | |||
| 149 | sequence_analysis_table_iterate_tables(flow_register, NULL((void*)0)); | |||
| 150 | } | |||
| 151 | ||||
| 152 | /* | |||
| 153 | * Editor modelines - https://www.wireshark.org/tools/modelines.html | |||
| 154 | * | |||
| 155 | * Local Variables: | |||
| 156 | * c-basic-offset: 4 | |||
| 157 | * tab-width: 8 | |||
| 158 | * indent-tabs-mode: nil | |||
| 159 | * End: | |||
| 160 | * | |||
| 161 | * ex: set shiftwidth=2 tabstop=8 expandtab: | |||
| 162 | * :indentSize=2:tabSize=8:noTabs=true: | |||
| 163 | */ |