}
}
+void
+col_add_lstr(column_info *cinfo, const gint el, const gchar *str, ...)
+{
+ va_list ap;
+ int i;
+ int pos;
+ int max_len;
+
+ if (!CHECK_COL(cinfo, el))
+ return;
+
+ if (el == COL_INFO)
+ max_len = COL_MAX_INFO_LEN;
+ else
+ max_len = COL_MAX_LEN;
+
+ for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
+ if (cinfo->fmt_matx[i][el]) {
+ pos = cinfo->col_fence[i];
+ if (pos != 0) {
+ /*
+ * We will append the string after the fence.
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
+ } else {
+ /*
+ * There's no fence, so we can just write to the string.
+ */
+ cinfo->col_data[i] = cinfo->col_buf[i];
+ }
+
+ va_start(ap, str);
+ do {
+ if G_UNLIKELY(str == NULL)
+ str = "(null)";
+
+ pos += g_strlcpy(&cinfo->col_buf[i][pos], str, max_len - pos);
+
+ } while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
+ va_end(ap);
+ }
+ }
+}
+
/* Adds a vararg list to a packet info string. */
void
-col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...) {
+col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
+{
va_list ap;
int i;
int fence;
*/
WS_DLL_PUBLIC void col_add_str(column_info *cinfo, const gint col, const gchar *str);
+/* terminator argument for col_add_lstr() function */
+#define COL_ADD_LSTR_TERMINATOR (const char *) -1
+WS_DLL_PUBLIC void col_add_lstr(column_info *cinfo, const gint el, const gchar *str, ...);
+
/** Add (replace) the text of a column element, the text will be formatted and copied.
*
* Same function as col_add_str() but using a printf-like format string.
case REQUEST_LINE:
is_known_request = sip_is_known_request(tvb, offset, token_1_len, ¤t_method_idx);
descr = is_known_request ? "Request" : "Unknown request";
- col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
- descr,
- tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1));
+ col_add_lstr(pinfo->cinfo, COL_INFO,
+ descr, ": ",
+ tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1),
+ COL_ADD_LSTR_TERMINATOR);
DPRINT(("got %s: %s", descr,
tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1)));
break;
case STATUS_LINE:
descr = "Status";
- col_add_fstr(pinfo->cinfo, COL_INFO, "Status: %s",
- tvb_format_text(tvb, offset + SIP2_HDR_LEN + 1, linelen - SIP2_HDR_LEN - 1));
+ col_add_lstr(pinfo->cinfo, COL_INFO,
+ "Status: ",
+ tvb_format_text(tvb, offset + SIP2_HDR_LEN + 1, linelen - SIP2_HDR_LEN - 1),
+ COL_ADD_LSTR_TERMINATOR);
stat_info->reason_phrase = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + SIP2_HDR_LEN + 5,
linelen - (SIP2_HDR_LEN + 5),ENC_UTF_8|ENC_NA);
DPRINT(("got Response: %s",
msg_class_str = val_to_str_const(msg_type_class, classes, "Unknown");
msg_method_str = val_to_str_const(msg_type_method, methods, "Unknown");
- col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
- msg_method_str, msg_class_str);
+ col_add_lstr(pinfo->cinfo, COL_INFO,
+ msg_method_str,
+ " ",
+ msg_class_str,
+ COL_ADD_LSTR_TERMINATOR);
ti = proto_tree_add_item(tree, proto_stun, tvb, 0, -1, ENC_NA);
tcph->th_sport = tvb_get_ntohs(tvb, offset);
tcph->th_dport = tvb_get_ntohs(tvb, offset + 2);
- col_add_fstr(pinfo->cinfo, COL_INFO, "%s \xe2\x86\x92 %s", /* UTF8_RIGHTWARDS_ARROW */
- ep_tcp_port_to_display(tcph->th_sport), ep_tcp_port_to_display(tcph->th_dport));
+ col_add_lstr(pinfo->cinfo, COL_INFO,
+ ep_tcp_port_to_display(tcph->th_sport),
+ "\xe2\x86\x92", /* UTF8_RIGHTWARDS_ARROW */
+ ep_tcp_port_to_display(tcph->th_dport),
+ COL_ADD_LSTR_TERMINATOR);
+
if (tree) {
if (tcp_summary_in_tree) {
ti = proto_tree_add_protocol_format(tree, proto_tcp, tvb, 0, -1,
udph->uh_sport=tvb_get_ntohs(tvb, offset);
udph->uh_dport=tvb_get_ntohs(tvb, offset+2);
- col_add_fstr(pinfo->cinfo, COL_INFO, "Source port: %s Destination port: %s",
- ep_udp_port_to_display(udph->uh_sport), ep_udp_port_to_display(udph->uh_dport));
+ col_add_lstr(pinfo->cinfo, COL_INFO,
+ "Source port: ", ep_udp_port_to_display(udph->uh_sport), " "
+ "Destination port: ", ep_udp_port_to_display(udph->uh_dport),
+ COL_ADD_LSTR_TERMINATOR);
if (tree) {
if (udp_summary_in_tree) {
#include "packet-vlan.h"
#include <epan/etypes.h>
#include <epan/prefs.h>
+#include <epan/to_str.h>
void proto_register_vlan(void);
void proto_reg_handoff_vlan(void);
}
}
+static void
+columns_set_vlan(column_info *cinfo, guint16 tci)
+{
+ static const char fast_str[][2] = { "0", "1", "2", "3", "4", "5", "6", "7" };
+
+ char id_str[16];
+
+ guint32_to_str_buf(tci & 0xFFF, id_str, sizeof(id_str));
+
+ col_add_lstr(cinfo, COL_INFO,
+ "PRI: ", fast_str[(tci >> 13) & 7], " "
+ "CFI: ", fast_str[(tci >> 12) & 1], " "
+ "ID: ", id_str,
+ COL_ADD_LSTR_TERMINATOR);
+ col_add_str(cinfo, COL_8021Q_VLAN_ID, id_str);
+}
+
static void
dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
tci = tvb_get_ntohs( tvb, 0 );
- col_add_fstr(pinfo->cinfo, COL_INFO, "PRI: %u CFI: %u ID: %u",
- (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
- col_add_fstr(pinfo->cinfo, COL_8021Q_VLAN_ID, "%u", (tci & 0xFFF));
+ columns_set_vlan(pinfo->cinfo, tci);
vlan_tree = NULL;