forked from osmocom/wireshark
tcp: move & optimize printing tcp flags to seperate routine.
The formatting routine is quite simple so it can be replaced with g_stpcpy() and still keeping it clean. Change-Id: Ifbab1dc1140ee271d39bbbfb7586cfda6ded5c54 Reviewed-on: https://code.wireshark.org/review/1517 Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Evan Huus <eapache@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
f764765108
commit
be3a153707
1 changed files with 38 additions and 27 deletions
|
@ -4067,6 +4067,40 @@ dissect_tcp_payload(tvbuff_t *tvb, packet_info *pinfo, int offset, guint32 seq,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
tcp_flags_to_str(const struct tcpheader *tcph)
|
||||||
|
{
|
||||||
|
static const char flags[][4] = { "FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR", "NS" };
|
||||||
|
const int maxlength = 64; /* upper bounds, max 53B: 8 * 3 + 2 + strlen("Reserved") + 9 * 2 + 1 */
|
||||||
|
|
||||||
|
char *pbuf;
|
||||||
|
const char *buf;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
buf = pbuf = (char *) wmem_alloc(wmem_packet_scope(), maxlength);
|
||||||
|
*pbuf = '\0';
|
||||||
|
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
if (tcph->th_flags & (1 << i)) {
|
||||||
|
if (buf[0])
|
||||||
|
pbuf = g_stpcpy(pbuf, ", ");
|
||||||
|
pbuf = g_stpcpy(pbuf, flags[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcph->th_flags & TH_RES) {
|
||||||
|
if (buf[0])
|
||||||
|
pbuf = g_stpcpy(pbuf, ", ");
|
||||||
|
pbuf = g_stpcpy(pbuf, "Reserved");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[0] == '\0')
|
||||||
|
buf = "<None>";
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
{
|
{
|
||||||
|
@ -4078,10 +4112,7 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
proto_item *options_item;
|
proto_item *options_item;
|
||||||
proto_tree *options_tree;
|
proto_tree *options_tree;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
wmem_strbuf_t *flags_strbuf = wmem_strbuf_new_label(wmem_packet_scope());
|
const char *flags_str;
|
||||||
static const gchar *flags[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR", "NS"};
|
|
||||||
gint i;
|
|
||||||
guint bpos;
|
|
||||||
guint optlen;
|
guint optlen;
|
||||||
guint32 nxtseq = 0;
|
guint32 nxtseq = 0;
|
||||||
guint reported_len;
|
guint reported_len;
|
||||||
|
@ -4100,8 +4131,6 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
proto_item *item;
|
proto_item *item;
|
||||||
proto_tree *checksum_tree;
|
proto_tree *checksum_tree;
|
||||||
|
|
||||||
wmem_strbuf_append(flags_strbuf, "<None>");
|
|
||||||
|
|
||||||
tcph=wmem_new(wmem_packet_scope(), struct tcpheader);
|
tcph=wmem_new(wmem_packet_scope(), struct tcpheader);
|
||||||
SET_ADDRESS(&tcph->ip_src, pinfo->src.type, pinfo->src.len, pinfo->src.data);
|
SET_ADDRESS(&tcph->ip_src, pinfo->src.type, pinfo->src.len, pinfo->src.data);
|
||||||
SET_ADDRESS(&tcph->ip_dst, pinfo->dst.type, pinfo->dst.len, pinfo->dst.data);
|
SET_ADDRESS(&tcph->ip_dst, pinfo->dst.type, pinfo->dst.len, pinfo->dst.data);
|
||||||
|
@ -4289,27 +4318,9 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
} else
|
} else
|
||||||
tcph->th_have_seglen = FALSE;
|
tcph->th_have_seglen = FALSE;
|
||||||
|
|
||||||
{
|
flags_str = tcp_flags_to_str(tcph);
|
||||||
gboolean first_flag = TRUE;
|
|
||||||
for (i = 0; i < 9; i++) {
|
|
||||||
bpos = 1 << i;
|
|
||||||
if (tcph->th_flags & bpos) {
|
|
||||||
if (first_flag) {
|
|
||||||
wmem_strbuf_truncate(flags_strbuf, 0);
|
|
||||||
}
|
|
||||||
wmem_strbuf_append_printf(flags_strbuf, "%s%s", first_flag ? "" : ", ", flags[i]);
|
|
||||||
first_flag = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tcph->th_flags & 0x0E00) {
|
|
||||||
if (first_flag) {
|
|
||||||
wmem_strbuf_truncate(flags_strbuf, 0);
|
|
||||||
}
|
|
||||||
wmem_strbuf_append_printf(flags_strbuf, "%sReserved", first_flag ? "" : ", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
col_append_fstr(pinfo->cinfo, COL_INFO, " [%s] Seq=%u", wmem_strbuf_get_str(flags_strbuf), tcph->th_seq);
|
col_append_fstr(pinfo->cinfo, COL_INFO, " [%s] Seq=%u", flags_str, tcph->th_seq);
|
||||||
if (tcph->th_flags&TH_ACK) {
|
if (tcph->th_flags&TH_ACK) {
|
||||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Ack=%u", tcph->th_ack);
|
col_append_fstr(pinfo->cinfo, COL_INFO, " Ack=%u", tcph->th_ack);
|
||||||
}
|
}
|
||||||
|
@ -4378,7 +4389,7 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
proto_tree_add_uint_format_value(tcp_tree, hf_tcp_hdr_len, tvb, offset + 12, 1, tcph->th_hlen,
|
proto_tree_add_uint_format_value(tcp_tree, hf_tcp_hdr_len, tvb, offset + 12, 1, tcph->th_hlen,
|
||||||
"%u bytes", tcph->th_hlen);
|
"%u bytes", tcph->th_hlen);
|
||||||
tf = proto_tree_add_uint_format_value(tcp_tree, hf_tcp_flags, tvb, offset + 12, 2,
|
tf = proto_tree_add_uint_format_value(tcp_tree, hf_tcp_flags, tvb, offset + 12, 2,
|
||||||
tcph->th_flags, "0x%03x (%s)", tcph->th_flags, wmem_strbuf_get_str(flags_strbuf));
|
tcph->th_flags, "0x%03x (%s)", tcph->th_flags, flags_str);
|
||||||
field_tree = proto_item_add_subtree(tf, ett_tcp_flags);
|
field_tree = proto_item_add_subtree(tf, ett_tcp_flags);
|
||||||
proto_tree_add_boolean(field_tree, hf_tcp_flags_res, tvb, offset + 12, 1, tcph->th_flags);
|
proto_tree_add_boolean(field_tree, hf_tcp_flags_res, tvb, offset + 12, 1, tcph->th_flags);
|
||||||
proto_tree_add_boolean(field_tree, hf_tcp_flags_ns, tvb, offset + 12, 1, tcph->th_flags);
|
proto_tree_add_boolean(field_tree, hf_tcp_flags_ns, tvb, offset + 12, 1, tcph->th_flags);
|
||||||
|
|
Loading…
Reference in a new issue