diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2015-10-15 02:44:04 +0100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-11-07 21:15:11 +0000 |
commit | 24bfb7e35d619c004e0458f38a1d5ae538a898fb (patch) | |
tree | 643dbf00491cb77bedcf715a30467c1d77606bd8 | |
parent | 31f004f1caee87d744610f48c93fae1efa8e7b56 (diff) |
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>
-rw-r--r-- | debian/libwireshark0.symbols | 2 | ||||
-rw-r--r-- | epan/column-utils.c | 23 | ||||
-rw-r--r-- | epan/column-utils.h | 10 | ||||
-rw-r--r-- | epan/dissectors/packet-dccp.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-tcp.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-udp.c | 4 |
6 files changed, 26 insertions, 21 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index a99d25e0c2..b3ee4bb360 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -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 diff --git a/epan/column-utils.c b/epan/column-utils.c index b52e08ff8f..261e459cd6 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -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 diff --git a/epan/column-utils.h b/epan/column-utils.h index d89a745678..5c5a83cd7b 100644 --- a/epan/column-utils.h +++ b/epan/column-utils.h @@ -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, * diff --git a/epan/dissectors/packet-dccp.c b/epan/dissectors/packet-dccp.c index 427e29e9cf..c71e5cd81e 100644 --- a/epan/dissectors/packet-dccp.c +++ b/epan/dissectors/packet-dccp.c @@ -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) { diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index e4c0e850a2..948e512b9f 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -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); diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c index a6c0409be9..d60f9d68da 100644 --- a/epan/dissectors/packet-udp.c +++ b/epan/dissectors/packet-udp.c @@ -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); |