column-utils: Refactor col_append_port() to col_append_ports()
Having a single function call to format source-destination port column info serves the current (and presently only) use case better by having a single place to manage the display format. This commit does not introduce any actual formatting changes. Change-Id: I1d479d0fd5690d12afb47e538057fdc2dd369ca2 Reviewed-on: https://code.wireshark.org/review/11539 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
parent
31f004f1ca
commit
24bfb7e35d
|
@ -130,7 +130,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
|
|||
col_add_str@Base 1.9.1
|
||||
col_append_fstr@Base 1.9.1
|
||||
col_append_lstr@Base 1.99.0
|
||||
col_append_port@Base 2.1.0
|
||||
col_append_ports@Base 2.1.0
|
||||
col_append_sep_fstr@Base 1.9.1
|
||||
col_append_sep_str@Base 1.9.1
|
||||
col_append_str@Base 1.9.1
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <epan/strutil.h>
|
||||
#include <epan/epan.h>
|
||||
#include <epan/dfilter/dfilter.h>
|
||||
#include <wsutil/utf8_entities.h>
|
||||
|
||||
/* Allocate all the data structures for constructing column data, given
|
||||
the number of columns. */
|
||||
|
@ -418,19 +419,29 @@ col_append_str_uint(column_info *cinfo, const gint col, const gchar *abbrev, gui
|
|||
col_append_lstr(cinfo, col, sep ? sep : "", abbrev, "=", buf, COL_ADD_LSTR_TERMINATOR);
|
||||
}
|
||||
|
||||
void
|
||||
col_append_port(column_info *cinfo, const gint col, port_type typ, guint16 val, const gchar *sep)
|
||||
static int
|
||||
col_snprint_port(gchar *buf, gulong buf_siz, port_type typ, guint16 val)
|
||||
{
|
||||
const char *str;
|
||||
char buf[32];
|
||||
int n;
|
||||
|
||||
if (gbl_resolv_flags.transport_name &&
|
||||
(str = try_serv_name_lookup(typ, val)) != NULL) {
|
||||
g_snprintf(buf, sizeof(buf), "%s(%u)", str, val);
|
||||
n = g_snprintf(buf, buf_siz, "%s(%"G_GUINT16_FORMAT")", str, val);
|
||||
} else {
|
||||
g_snprintf(buf, sizeof(buf), "%u", val);
|
||||
n = g_snprintf(buf, buf_siz, "%"G_GUINT16_FORMAT, val);
|
||||
}
|
||||
col_append_lstr(cinfo, col, sep ? sep : "", buf, COL_ADD_LSTR_TERMINATOR);
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
col_append_ports(column_info *cinfo, const gint col, port_type typ, guint16 src, guint16 dst)
|
||||
{
|
||||
char buf_src[32], buf_dst[32];
|
||||
|
||||
col_snprint_port(buf_src, 32, typ, src);
|
||||
col_snprint_port(buf_dst, 32, typ, dst);
|
||||
col_append_lstr(cinfo, col, buf_src, UTF8_RIGHTWARDS_ARROW, buf_dst, COL_ADD_LSTR_TERMINATOR);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -279,15 +279,15 @@ WS_DLL_PUBLIC void col_append_str(column_info *cinfo, const gint col, const gcha
|
|||
*/
|
||||
WS_DLL_PUBLIC void col_append_str_uint(column_info *cinfo, const gint col, const gchar *abbrev, guint32 val, const gchar *sep);
|
||||
|
||||
/** Append a transport port to a column element, the text will be copied.
|
||||
/** Append a transport port pair to a column element, the text will be copied.
|
||||
*
|
||||
* @param cinfo the current packet row
|
||||
* @param col the column to use, e.g. COL_INFO
|
||||
* @param typ the port type to resolve
|
||||
* @param val the port value to append
|
||||
* @param sep an optional separator to _prepend_ to the port string
|
||||
* @param typ the port type to resolve, e.g. PT_UDP
|
||||
* @param src the source port value to append
|
||||
* @param dst the destination port value to append
|
||||
*/
|
||||
WS_DLL_PUBLIC void col_append_port(column_info *cinfo, const gint col, port_type typ, guint16 val, const gchar *sep);
|
||||
WS_DLL_PUBLIC void col_append_ports(column_info *cinfo, const gint col, port_type typ, guint16 src, guint16 dst);
|
||||
|
||||
/* Append the given strings (terminated by COL_ADD_LSTR_TERMINATOR) to a column element,
|
||||
*
|
||||
|
|
|
@ -618,9 +618,7 @@ dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
|
|||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, "DCCP");
|
||||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_DCCP, dccph->sport, NULL);
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_DCCP, dccph->dport, UTF8_RIGHTWARDS_ARROW);
|
||||
col_append_ports(pinfo->cinfo, COL_INFO, PT_DCCP, dccph->sport, dccph->dport);
|
||||
|
||||
dccp_item = proto_tree_add_item(tree, proto_dccp, tvb, offset, -1, ENC_NA);
|
||||
if (dccp_summary_in_tree) {
|
||||
|
|
|
@ -4849,9 +4849,7 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TCP");
|
||||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_TCP, tcph->th_sport, NULL);
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_TCP, tcph->th_dport, UTF8_RIGHTWARDS_ARROW);
|
||||
col_append_ports(pinfo->cinfo, COL_INFO, PT_TCP, tcph->th_sport, tcph->th_dport);
|
||||
|
||||
if (tree) {
|
||||
ti = proto_tree_add_item(tree, proto_tcp, tvb, 0, -1, ENC_NA);
|
||||
|
|
|
@ -717,9 +717,7 @@ dissect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 ip_proto)
|
|||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, (ip_proto == IP_PROTO_UDP) ? "UDP" : "UDP-Lite");
|
||||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_UDP, udph->uh_sport, NULL);
|
||||
col_append_port(pinfo->cinfo, COL_INFO, PT_UDP, udph->uh_dport, UTF8_RIGHTWARDS_ARROW);
|
||||
col_append_ports(pinfo->cinfo, COL_INFO, PT_UDP, udph->uh_sport, udph->uh_dport);
|
||||
|
||||
reported_len = tvb_reported_length(tvb);
|
||||
len = tvb_captured_length(tvb);
|
||||
|
|
Loading…
Reference in New Issue