Example #1
0
WSLUA_METAMETHOD NSTime__tostring(lua_State* L) {
    NSTime nstime = checkNSTime(L,1);
    gchar *str;
    long secs = (long)nstime->secs;
    gint nsecs = nstime->nsecs;
    gboolean negative_zero = FALSE;

    /* Time is defined as sec + nsec/10^9, both parts can be negative.
     * Translate this into the more familiar sec.nsec notation instead. */
    if (secs > 0 && nsecs < 0) {
        /* sign mismatch: (2, -3ns) -> 1.7 */
        nsecs += NS_PER_S;
        secs--;
    } else if (secs < 0 && nsecs > 0) {
        /* sign mismatch: (-2, 3ns) -> -1.7 */
        nsecs = NS_PER_S - nsecs;
        secs--;
    } else if (nsecs < 0) {
        /* Drop sign, the integer part already has it: (-2, -3ns) -> -2.3 */
        nsecs = -nsecs;
        /* In case the integer part is zero, it does not has a sign, so remember
         * that it must be explicitly added. */
        negative_zero = secs == 0;
    }

    if (negative_zero) {
        str = wmem_strdup_printf(NULL, "-0.%09d", nsecs);
    } else {
        str = wmem_strdup_printf(NULL, "%ld.%09d", secs, nsecs);
    }
    lua_pushstring(L, str);
    wmem_free(NULL, str);

    WSLUA_RETURN(1); /* The string representing the nstime. */
}
Example #2
0
/* -------------------------- */
static int
time_stamp(tvbuff_t *tvb, proto_tree *nasdaq_itch_tree, int id, int offset, int size)
{

  if (nasdaq_itch_tree) {
      guint32     ms, val;
      const char *display   = "";
      const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size);

      ms = val = (guint32)strtoul(str_value, NULL, 10);
      switch (size) {
      case 3:
          display = wmem_strdup_printf(wmem_packet_scope(), " %03u" , val);
          break;
      case 5:
          ms = val *1000;
      case 8: /* 0 86 400 000 */
          display = wmem_strdup_printf(wmem_packet_scope(), " %u (%02u:%02u:%02u.%03u)", val,
              ms/3600000, (ms % 3600000)/60000, (ms % 60000)/1000, ms %1000);
          break;
      }
      proto_tree_add_uint_format_value(nasdaq_itch_tree, id, tvb, offset, size, val, "%s", display);
  }
  return offset + size;
}
Example #3
0
static void
wmem_test_strutls(void)
{
    wmem_allocator_t   *allocator;
    const char         *orig_str;
    char               *new_str;
    char              **split_str;

    allocator = wmem_allocator_new(WMEM_ALLOCATOR_STRICT);

    orig_str = "TEST1";
    new_str  = wmem_strdup(allocator, orig_str);
    g_assert_cmpstr(new_str, ==, orig_str);
    new_str[0] = 'X';
    g_assert_cmpstr(new_str, >, orig_str);
    wmem_strict_check_canaries(allocator);

    orig_str = "TEST123456789";
    new_str  = wmem_strndup(allocator, orig_str, 6);
    g_assert_cmpstr(new_str, ==, "TEST12");
    g_assert_cmpstr(new_str, <, orig_str);
    new_str[0] = 'X';
    g_assert_cmpstr(new_str, >, orig_str);
    wmem_strict_check_canaries(allocator);

    new_str = wmem_strdup_printf(allocator, "abc %s %% %d", "boo", 23);
    g_assert_cmpstr(new_str, ==, "abc boo % 23");
    new_str = wmem_strdup_printf(allocator, "%s", STRING_80);
    g_assert_cmpstr(new_str, ==, STRING_80);
    wmem_strict_check_canaries(allocator);

    new_str = wmem_strconcat(allocator, "ABC", NULL);
    g_assert_cmpstr(new_str, ==, "ABC");
    new_str = wmem_strconcat(allocator, "ABC", "DEF", NULL);
    g_assert_cmpstr(new_str, ==, "ABCDEF");
    wmem_strict_check_canaries(allocator);
    new_str = wmem_strconcat(allocator, "", "", "ABCDEF", "", "GH", NULL);
    g_assert_cmpstr(new_str, ==, "ABCDEFGH");
    wmem_strict_check_canaries(allocator);

    split_str = wmem_strsplit(allocator, "A-C", "-", 2);
    g_assert_cmpstr(split_str[0], ==, "A");
    g_assert_cmpstr(split_str[1], ==, "C");
    split_str = wmem_strsplit(allocator, "--aslkf-asio--asfj-as--", "-", 10);
    g_assert_cmpstr(split_str[0], ==, "aslkf");
    g_assert_cmpstr(split_str[1], ==, "asio");
    g_assert_cmpstr(split_str[2], ==, "asfj");
    g_assert_cmpstr(split_str[3], ==, "as");
    split_str = wmem_strsplit(allocator, "--aslkf-asio--asfj-as--", "-", 4);
    g_assert_cmpstr(split_str[0], ==, "aslkf");
    g_assert_cmpstr(split_str[1], ==, "asio");
    g_assert_cmpstr(split_str[2], ==, "-asfj-as--");
    wmem_strict_check_canaries(allocator);

    orig_str = "TeStAsCiIsTrDoWn";
    new_str = wmem_ascii_strdown(allocator, orig_str, -1);
    g_assert_cmpstr(new_str, ==, "testasciistrdown");

    wmem_destroy_allocator(allocator);
}
static void
dissect_UDPR1(tvbuff_t *tvb, packet_info *pinfo,
	      proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
	      gchar** info_string)
{
	const gchar *status_string;
	guint32 seq_num, status;

	status = tvb_get_letohl(tvb, 0);
	status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
	if (status_string) {
		*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Status: %s", status_string);
	} else {
		*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Undefined error code %d", status);
	}

	/* Get the transaction identifier */
	seq_num = tvb_get_letohl(tvb, 4);
	adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);

	if (! adwin_tree)
		return;

	SET_PACKET_TYPE(adwin_tree, APT_UDPR1);
	ADWIN_ADD_LE(adwin_tree, status,         0,  4);
	ADWIN_ADD_LE(adwin_tree, packet_index,   4,  4);
	ADWIN_ADD_LE(adwin_tree, val1,           8,  4);
	ADWIN_ADD_LE(adwin_tree, val1f,          8,  4);
	ADWIN_ADD_LE(adwin_tree, val2,          12,  4);
	ADWIN_ADD_LE(adwin_tree, val3,          16,  4);
	ADWIN_ADD_LE(adwin_tree, val4,          20,  4);
	ADWIN_ADD_LE(adwin_debug_tree, unused,  24,  8);
}
Example #5
0
char * lbttcp_transport_source_string(const address * source_address, guint16 source_port, guint32 session_id)
{
    char * bufptr = NULL;

    if (session_id == 0)
    {
        bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT, address_to_str(wmem_packet_scope(), source_address), source_port);
    }
    else
    {
        bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT ":%08x", address_to_str(wmem_packet_scope(), source_address), source_port, session_id);
    }
    return (bufptr);
}
static void
dissect_UDPR2(tvbuff_t *tvb, packet_info *pinfo,
	      proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
	      gchar** info_string)
{
	const gchar *status_string;
	guint32 i, status, seq_num;

	status = tvb_get_letohl(tvb, 0);
	status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
	if (status_string) {
	        *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Status: %s", status_string);
	} else {
		*info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Undefined error code %d", status);
	}

	/* Get the transaction identifier */
	seq_num = tvb_get_letohl(tvb, 4);
	adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);

	if (! adwin_tree)
		return;

	SET_PACKET_TYPE(adwin_tree, APT_UDPR2);
	ADWIN_ADD_LE(adwin_tree, status,         0,  4);
	ADWIN_ADD_LE(adwin_tree, packet_index,   4,  4);

	if (! global_adwin_dissect_data) {
		proto_tree_add_text(adwin_debug_tree, tvb, 8, 250 * 4, "Data");
		return;
	}

	for (i = 0; i < 250; i++) {
		proto_item *item;
		guint32 offset = 8 + i * (int)sizeof(guint32);
		gint32 value = tvb_get_letohl(tvb, offset);
		void * fvalue = &value;
		proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
				    "Data[%3d]: %10d - %10f - 0x%08x",
				    i, value, *(float*)fvalue, value);
		item = ADWIN_ADD_LE(adwin_debug_tree, data_int,   offset, 4);
		PROTO_ITEM_SET_HIDDEN(item);
		item = ADWIN_ADD_LE(adwin_debug_tree, data_float, offset, 4);
		PROTO_ITEM_SET_HIDDEN(item);
		item = ADWIN_ADD_LE(adwin_debug_tree, data_hex,   offset, 4);
		PROTO_ITEM_SET_HIDDEN(item);
	}
}
Example #7
0
void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
{
    char *szValue;
    int iOffset = *pOffset;
    gint32 iLen = tvb_get_letohl(tvb, iOffset);
    iOffset += 4;

    if (iLen == -1)
    {
        proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
        proto_item_append_text(item, "[OpcUa Null ByteString]");
        proto_item_set_end(item, tvb, *pOffset + 4);
    }
    else if (iLen == 0)
    {
        proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
        proto_item_append_text(item, "[OpcUa Empty ByteString]");
        proto_item_set_end(item, tvb, *pOffset + 4);
    }
    else if (iLen > 0)
    {
        proto_tree_add_item(tree, hfIndex, tvb, iOffset, iLen, ENC_NA);
        iOffset += iLen; /* eat the whole bytestring */
    }
    else
    {
        proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 0, ENC_NA);
        szValue = wmem_strdup_printf(wmem_packet_scope(), "[Invalid ByteString] Invalid length: %d", iLen);
        proto_item_append_text(item, "%s", szValue);
        proto_item_set_end(item, tvb, *pOffset + 4);
    }

    *pOffset = iOffset;
}
Example #8
0
/* dissect a bt dht error from tvb, start at offset. it's like "li201e9:error msge" */
static int
dissect_bt_dht_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, const char **result, const char *label )
{
  proto_item *ti;
  proto_tree *sub_tree;
  const char *error_no, *error_msg;

  error_no  = NULL;
  error_msg = NULL;

  ti       = proto_tree_add_item( tree, hf_bt_dht_error, tvb, offset, 0, ENC_NA );
  sub_tree = proto_item_add_subtree( ti, ett_bt_dht_error);

  /* we have confirmed that the first byte is 'l' */
  offset += 1;

  /* dissect bt-dht error number and message */
  offset = dissect_bencoded_int( tvb, pinfo, sub_tree, offset, &error_no, "Error ID" );
  offset = dissect_bencoded_string( tvb, pinfo, sub_tree, offset, &error_msg, FALSE, "Error Message" );

  proto_item_set_text( ti, "%s: error %s, %s", label, error_no, error_msg );
  col_append_fstr( pinfo->cinfo, COL_INFO, "error_no=%s error_msg=%s ", error_no, error_msg );
  *result = wmem_strdup_printf(wmem_packet_scope(), "error %s, %s", error_no, error_msg );

  return offset;
}
Example #9
0
static int
call_dop_oid_callback(const char *base_string, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, const char *col_info, void* data)
{
  char* binding_param;

  binding_param = wmem_strdup_printf(wmem_packet_scope(), "%s.%s", base_string, binding_type ? binding_type : "");

  col_append_fstr(pinfo->cinfo, COL_INFO, " %s", col_info);

  if (dissector_try_string(dop_dissector_table, binding_param, tvb, pinfo, tree, data)) {
     offset = tvb_reported_length (tvb);
  } else {
     proto_item *item=NULL;
     proto_tree *next_tree=NULL;

     item = proto_tree_add_text(tree, tvb, 0, tvb_length_remaining(tvb, offset), "Dissector for parameter %s OID:%s not implemented. Contact Wireshark developers if you want this supported", base_string, binding_type ? binding_type : "<empty>");
     if (item) {
        next_tree = proto_item_add_subtree(item, ett_dop_unknown);
     }
     offset = dissect_unknown_ber(pinfo, tvb, offset, next_tree);
     expert_add_info(pinfo, item, &ei_dop_unknown_binding_parameter);
   }

   return offset;
}
Example #10
0
static const gchar *gen_olc_key(guint16 lc_num, address *dst_addr, address *src_addr)
{
  return wmem_strdup_printf(wmem_packet_scope(), "%s/%s/%u",
          address_to_str(wmem_packet_scope(), dst_addr),
          address_to_str(wmem_packet_scope(), src_addr),
          lc_num);
}
Example #11
0
char *get_hostlist_filter(hostlist_talker_t *host)
{
    char *sport, *src_addr;
    char *str;

    sport = ct_port_to_str(host->ptype, host->port);
    src_addr = address_to_str(NULL, &host->myaddress);
    if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == AT_USB) {
        char *new_addr;

        new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
        wmem_free(NULL, src_addr);
        src_addr = new_addr;
    }

    str = g_strdup_printf("%s==%s%s%s%s%s",
                          hostlist_get_filter_name(host, CONV_FT_ANY_ADDRESS),
                          src_addr,
                          sport?" && ":"",
                          sport?hostlist_get_filter_name(host, CONV_FT_ANY_PORT):"",
                          sport?"==":"",
                          sport?sport:"");

    g_free(sport);
    wmem_free(NULL, src_addr);
    return str;
}
Example #12
0
static void
cmpp_msg_id(proto_tree *tree, tvbuff_t *tvb, gint  field, gint offset)
{
	guint8      month,day,hour,minute,second;
	guint32     ismg_code;
	proto_item *pi;
	proto_tree *sub_tree;
	char       *strval;

	pi = proto_tree_add_item(tree, field, tvb, offset, 8, ENC_BIG_ENDIAN);
	sub_tree = proto_item_add_subtree(pi, ett_msg_id);

	month = (tvb_get_guint8(tvb, offset) & 0xF0) >> 4;
	day = (tvb_get_ntohs(tvb, offset) & 0x0F80) >> 7;
	hour = (tvb_get_guint8(tvb, offset + 1) & 0x7C) >> 2;
	minute = (tvb_get_ntohs(tvb, offset + 1) & 0x03F0) >> 4;
	second = (tvb_get_ntohs(tvb, offset + 2) & 0x0FC0) >> 6;
	strval = wmem_strdup_printf(wmem_packet_scope(), "%02u/%02u %02u:%02u:%02u", month, day,
		hour, minute, second);

	ismg_code = (tvb_get_ntohl(tvb, offset + 3) & 0x3FFFFF00) >> 16;

	proto_tree_add_string(sub_tree, hf_msg_id_timestamp, tvb, offset, 4, strval);
	proto_tree_add_uint(sub_tree, hf_msg_id_ismg_code, tvb, offset + 3, 3, ismg_code);
	cmpp_uint2(sub_tree, tvb, hf_msg_id_sequence_id, offset + 6);
}
Example #13
0
static void
xmpp_error(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element)
{
    proto_item *error_item;
    proto_tree *error_tree;

    xmpp_element_t *text_element, *cond_element;

    xmpp_attr_info attrs_info[] = {
        {"type", &hf_xmpp_error_type, TRUE, TRUE, NULL, NULL},
        {"code", &hf_xmpp_error_code, FALSE, TRUE, NULL, NULL},
        {"condition", &hf_xmpp_error_condition, TRUE, TRUE, NULL, NULL} /*TODO: validate list to the condition element*/
    };

    gchar *error_info;

    xmpp_attr_t *fake_condition = NULL;

    error_info = wmem_strdup(wmem_packet_scope(), "Stanza error");

    error_item = proto_tree_add_item(tree, hf_xmpp_error, tvb, element->offset, element->length, ENC_BIG_ENDIAN);
    error_tree = proto_item_add_subtree(error_item, ett_xmpp_query_item);

    cond_element = xmpp_steal_element_by_attr(element, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
    if(cond_element)
    {
        fake_condition = xmpp_ep_init_attr_t(cond_element->name, cond_element->offset, cond_element->length);
        g_hash_table_insert(element->attrs, (gpointer)"condition", fake_condition);

        error_info = wmem_strdup_printf(wmem_packet_scope(), "%s: %s;", error_info, cond_element->name);
    }


    xmpp_display_attrs(error_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));

    while((text_element = xmpp_steal_element_by_name(element, "text")) != NULL)
    {
        xmpp_error_text(error_tree, tvb, text_element);

        error_info = wmem_strdup_printf(wmem_packet_scope(), "%s Text: %s", error_info, text_element->data?text_element->data->value:"");
    }

    expert_add_info_format(pinfo, error_item, &ei_xmpp_response, "%s", error_info);

    xmpp_unknown(error_tree, tvb, pinfo, element);
}
Example #14
0
static void
xmpp_failure_text(proto_tree *tree, tvbuff_t *tvb, xmpp_element_t *element)
{
    xmpp_attr_t *lang = xmpp_get_attr(element,"xml:lang");

    proto_tree_add_text(tree, tvb, element->offset, element->length, "TEXT%s: %s",
            lang?wmem_strdup_printf(wmem_packet_scope(), "(%s)",lang->value):"",
            element->data?element->data->value:"");
}
Example #15
0
WSLUA_METAMETHOD NSTime__tostring(lua_State* L) {
    NSTime nstime = checkNSTime(L,1);
    gchar *str;

    str = wmem_strdup_printf(NULL, "%ld.%09d", (long)nstime->secs, nstime->nsecs);
    lua_pushstring(L, str);
    wmem_free(NULL, str);

    WSLUA_RETURN(1); /* The string representing the nstime. */
}
Example #16
0
/* dissect a bt dht values list from tvb, start at offset. it's like "l6:....6:....e" */
static int
dissect_bt_dht_values(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, const char **result, const char *label )
{
  proto_item *ti;
  proto_tree *sub_tree;
  proto_item *value_ti;
  proto_tree *value_tree;

  guint       peer_index;
  guint       string_len;

  ti = proto_tree_add_item( tree, hf_bt_dht_peers, tvb, offset, 0, ENC_NA );
  sub_tree = proto_item_add_subtree( ti, ett_bt_dht_peers);

  peer_index = 0;
  /* we has confirmed that the first byte is 'l' */
  offset += 1;

  /* dissect bt-dht values */
  while( tvb_get_guint8(tvb,offset)!='e' )
  {
    string_len = bencoded_string_length(tvb, &offset);

    /* 4 bytes ip, 2 bytes port */
    for( ; string_len>=6; string_len-=6, offset+=6 )
    {
      peer_index += 1;

      value_ti = proto_tree_add_item( sub_tree, hf_bt_dht_peer, tvb, offset, 6, ENC_NA );
      proto_item_append_text(value_ti, " %d", peer_index);
      value_tree = proto_item_add_subtree( value_ti, ett_bt_dht_peers);

      proto_tree_add_item( value_tree, hf_ip, tvb, offset, 4, ENC_BIG_ENDIAN);
      proto_item_append_text(value_ti, " (IP/Port: %s", tvb_ip_to_str(tvb, offset));
      proto_tree_add_item( value_tree, hf_port, tvb, offset+4, 2, ENC_BIG_ENDIAN);
      proto_item_append_text(value_ti, ":%u)", tvb_get_ntohs( tvb, offset+4 ));

    }
    /* truncated data */
    if( string_len>0 )
    {
      proto_tree_add_item( tree, hf_truncated_data, tvb, offset, string_len, ENC_NA );
      offset += string_len;
    }
  }

  if (tvb_get_guint8(tvb,offset)=='e') /* list ending delimiter */
    offset++;

  proto_item_set_text( ti, "%s: %d peers", label, peer_index );
  col_append_fstr( pinfo->cinfo, COL_INFO, "reply=%d peers ", peer_index );
  *result = wmem_strdup_printf(wmem_packet_scope(), "%d peers", peer_index);

  return offset;
}
Example #17
0
static const gchar *
key_to_val(const gchar *key, int keylen, const value_string_keyval *kv, const gchar *fmt) {
  int i = 0;
  while (kv[i].key) {
    if (!strncmp(kv[i].key, key, keylen)) {
      return(kv[i].val);
    }
    i++;
  }
  return wmem_strdup_printf(wmem_packet_scope(), fmt, key);
}
Example #18
0
static int is_banner_exchange_for(const gchar *type, tvbuff_t *tvb) {
    gchar *pmproxy_exchange_string;

    /* Exchange packets have to be this length */
    if(tvb_ensure_captured_length_remaining(tvb, PMPROXY_START_OF_PACKET) != PMPROXY_CLIENT_SERVER_VERSION_LENGTH) {
        return 0;
    }

    pmproxy_exchange_string = (gchar *) tvb_get_string_enc(wmem_packet_scope(), tvb, PMPROXY_START_OF_PACKET,
                                                           PMPROXY_CLIENT_SERVER_VERSION_LENGTH, ENC_ASCII);
    return g_strcmp0(pmproxy_exchange_string, wmem_strdup_printf(wmem_packet_scope(), "pmproxy-%s 1\n", type)) == 0;
}
Example #19
0
gchar *
p_get_proto_name_and_key(wmem_allocator_t *scope, struct _packet_info* pinfo, guint pfd_index){
  frame_proto_data  *temp;

  if (scope == pinfo->pool) {
    temp = (frame_proto_data*)g_slist_nth_data(pinfo->proto_data, pfd_index);
  } else {
    temp = (frame_proto_data*)g_slist_nth_data(pinfo->fd->pfd, pfd_index);
  }

  return wmem_strdup_printf(wmem_packet_scope(),"[%s, key %u]",proto_get_protocol_name(temp->proto), temp->key);
}
Example #20
0
gchar *
val_to_str_wmem(wmem_allocator_t *scope, const guint32 val, const value_string *vs, const char *fmt)
{
    const gchar *ret;

    DISSECTOR_ASSERT(fmt != NULL);

    ret = try_val_to_str(val, vs);
    if (ret != NULL)
        return wmem_strdup(scope, ret);

    return wmem_strdup_printf(scope, fmt, val);
}
Example #21
0
/* Like val_to_str except for range_string */
const gchar *
rval_to_str(const guint32 val, const range_string *rs, const char *fmt)
{
    const gchar *ret = NULL;

    DISSECTOR_ASSERT(fmt != NULL);

    ret = try_rval_to_str(val, rs);
    if(ret != NULL)
        return ret;

    return wmem_strdup_printf(wmem_packet_scope(), fmt, val);
}
Example #22
0
/* Like val_to_str for extended value strings */
const gchar *
val_to_str_ext(const guint32 val, value_string_ext *vse, const char *fmt)
{
    const gchar *ret;

    DISSECTOR_ASSERT(fmt != NULL);

    ret = try_val_to_str_ext(val, vse);
    if (ret != NULL)
        return ret;

    return wmem_strdup_printf(wmem_packet_scope(), fmt, val);
}
Example #23
0
/* Like val_to_str except for string_string */
const gchar *
str_to_str(const gchar *val, const string_string *vs, const char *fmt)
{
    const gchar *ret;

    DISSECTOR_ASSERT(fmt != NULL);

    ret = try_str_to_str(val, vs);
    if (ret != NULL)
        return ret;

    return wmem_strdup_printf(wmem_packet_scope(), fmt, val);
}
Example #24
0
static int tap_packet_cb_error_handler(lua_State* L) {
    const gchar* error =  lua_tostring(L,1);
    static gchar* last_error = NULL;
    static int repeated = 0;
    static int next = 2;
    gchar* where =  (lua_pinfo) ?
        wmem_strdup_printf(NULL, "Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->num) :
        wmem_strdup_printf(NULL, "Lua: Error During execution of Listener Packet Callback") ;

    /* show the error the 1st, 3rd, 5th, 9th, 17th, 33th... time it appears to avoid window flooding */
    /* XXX the last series of identical errors won't be shown (the user however gets at least one message) */

    if (! last_error) {
        report_failure("%s:\n%s",where,error);
        last_error = g_strdup(error);
        repeated = 0;
        next = 2;
        wmem_free(NULL, where);
        return 0;
    }

    if (g_str_equal(last_error,error) ) {
        repeated++;
        if ( repeated == next ) {
            report_failure("%s happened %i times:\n %s",where,repeated,error);
            next *= 2;
        }
    } else {
        report_failure("%s happened %i times:\n %s",where,repeated,last_error);
        g_free(last_error);
        last_error = g_strdup(error);
        repeated = 0;
        next = 2;
        report_failure("%s:\n %s",where,error);
    }

    wmem_free(NULL, where);
    return 0;
}
Example #25
0
static const gchar*
extval_to_str_idx(guint32 val, const ext_value_string *vs, gint *idx, const char *fmt) {
	const gchar *ret;

	if (!fmt)
		fmt="Unknown";

	ret = match_strextval_idx(val, vs, idx);
	if (ret != NULL)
		return ret;

	return wmem_strdup_printf(wmem_packet_scope(), fmt, val);
}
Example #26
0
gchar *
val64_to_str_ext_wmem(wmem_allocator_t *scope, const guint64 val, val64_string_ext *vse, const char *fmt)
{
    const gchar *ret;

    DISSECTOR_ASSERT(fmt != NULL);

    ret = try_val64_to_str_ext(val, vse);
    if (ret != NULL)
        return wmem_strdup(scope, ret);

    return wmem_strdup_printf(scope, fmt, val);
}
Example #27
0
static char*
cmpp_version(proto_tree *tree, tvbuff_t *tvb, gint  field, gint offset)
{
	gint8  version, major, minor;
	char  *strval;

	version = tvb_get_guint8(tvb, offset);
	minor   = version & 0x0F;
	major   = (version & 0xF0) >> 4;
	strval  = wmem_strdup_printf(wmem_packet_scope(), "%02u.%02u", major, minor);
	/* TODO: the version should be added as a uint_format */
	proto_tree_add_string(tree, field, tvb, offset, 1, strval);
	return strval;
}
Example #28
0
static gchar*
message_hash_key_convo(packet_info *pinfo,
				  guint64 value_frame_flags,
				  guint64 value_message_num)
{
	// Derive the hash key to use
	// msgtype:srcport:destport:messagenum

	const gchar *msg_type = get_message_type(value_frame_flags);
	gchar *hash_key = wmem_strdup_printf(wmem_packet_scope(), "%s:%u:%u:%" G_GINT64_MODIFIER "u",
			msg_type, pinfo->srcport, pinfo->destport, value_message_num);

	return hash_key;
}
Example #29
0
void gef_ctx_update_key(gef_ctx_t *gefx) {
  const gchar *parent_key;

  if (!gefx) return;
  parent_key = (gefx->parent) ? gefx->parent->key : NULL;
  gefx->key = wmem_strdup_printf(wmem_packet_scope(), 
    "%s%s"    /* parent prefix */
    "%s%s%s"  /* type, id */
    "%s%s"    /* subid */,
    (parent_key) ? parent_key : "", (parent_key) ? "/" : "",
    (gefx->type) ? gefx->type : "", (gefx->type && (gefx->id || gefx->subid)) ? "/" : "", (gefx->id) ? gefx->id : "",
    (gefx->subid) ? "-" : "", (gefx->subid) ? gefx->subid : ""
  );
}
Example #30
0
char *get_conversation_port(wmem_allocator_t *allocator, guint32 port, port_type ptype, gboolean resolve_names)
{

    if(!resolve_names) ptype = PT_NONE;

    switch(ptype) {
    case(PT_TCP):
        return tcp_port_to_display(allocator, port);
    case(PT_UDP):
        return udp_port_to_display(allocator, port);
    case(PT_SCTP):
        return sctp_port_to_display(allocator, port);
    default:
        return wmem_strdup_printf(allocator, "%d", port);
    }
}