Convert EUI64 address APIs to use wmem.

Change-Id: I57d2e435ac72ea07ec9a567e0b1ce4410966e3d2
Reviewed-on: https://code.wireshark.org/review/6419
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Michael Mann 2015-01-08 13:16:01 -05:00 committed by Anders Broman
parent 17f1a44168
commit 284229c0f8
10 changed files with 51 additions and 72 deletions

View File

@ -3111,41 +3111,20 @@ tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset)
}
const gchar *
ep_eui64_to_display(const guint64 addr_eui64)
eui64_to_display(wmem_allocator_t *allocator, const guint64 addr_eui64)
{
gchar *cur, *name;
guint8 *addr = (guint8 *)ep_alloc(8);
gchar *name;
guint8 *addr = (guint8 *)wmem_alloc(allocator, 8);
/* Copy and convert the address to network byte order. */
*(guint64 *)(void *)(addr) = pntoh64(&(addr_eui64));
if (!gbl_resolv_flags.mac_name || ((name = manuf_name_lookup(addr)) == NULL)) {
cur=ep_strdup_printf("%02x:%02x:%02x%02x:%02x:%02x%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
return cur;
return wmem_strdup_printf(allocator, "%02x:%02x:%02x%02x:%02x:%02x%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
}
cur=ep_strdup_printf("%s_%02x:%02x:%02x:%02x:%02x", name, addr[3], addr[4], addr[5], addr[6], addr[7]);
return cur;
return wmem_strdup_printf(allocator, "%s_%02x:%02x:%02x:%02x:%02x", name, addr[3], addr[4], addr[5], addr[6], addr[7]);
} /* ep_eui64_to_display */
const gchar *
ep_eui64_to_display_if_known(const guint64 addr_eui64)
{
gchar *cur, *name;
guint8 *addr = (guint8 *)ep_alloc(8);
/* Copy and convert the address to network byte order. */
*(guint64 *)(void *)(addr) = pntoh64(&(addr_eui64));
if ((name = manuf_name_lookup(addr)) == NULL) {
return NULL;
}
cur=ep_strdup_printf("%s_%02x:%02x:%02x:%02x:%02x", name, addr[3], addr[4], addr[5], addr[6], addr[7]);
return cur;
} /* ep_eui64_to_display_if_known */
} /* eui64_to_display */
#ifdef HAVE_C_ARES
#define GHI_TIMEOUT (250 * 1000)

View File

@ -216,13 +216,9 @@ WS_DLL_PUBLIC const gchar *tvb_get_manuf_name(tvbuff_t *tvb, gint offset);
*/
WS_DLL_PUBLIC const gchar *tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset);
/* ep_eui64_to_display returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
/* eui64_to_display returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" */
extern const gchar *ep_eui64_to_display(const guint64 addr);
/* ep_eui64_to_display_if_known returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known else NULL */
extern const gchar *ep_eui64_to_display_if_known(const guint64 addr);
extern const gchar *eui64_to_display(wmem_allocator_t *allocator, const guint64 addr);
/* get_ipxnet_name returns the logical name if found in an ipxnets file,
* or a string formatted with "%X" if not */

View File

@ -239,12 +239,12 @@ vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len)
XXX update the address_to_str stuff to use this function.
*/
gchar *
eui64_to_str(const guint64 ad) {
eui64_to_str(wmem_allocator_t *scope, const guint64 ad) {
gchar *buf;
guint8 *p_eui64;
p_eui64 = (guint8 *)ep_alloc(8);
buf=(gchar *)ep_alloc(EUI64_STR_LEN);
p_eui64=(guint8 *)wmem_alloc(scope, 8);
buf=(gchar *)wmem_alloc(scope, EUI64_STR_LEN);
/* Copy and convert the address to network byte order. */
*(guint64 *)(void *)(p_eui64) = pntoh64(&(ad));

View File

@ -740,9 +740,9 @@ dissect_ieee802154_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
TVB_SET_ADDRESS(&pinfo->dst, AT_EUI64, tvb, offset, 8);
if (tree) {
proto_tree_add_item(ieee802154_tree, hf_ieee802154_dst64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
proto_item_append_text(proto_root, ", Dst: %s", ep_eui64_to_display(packet->dst64));
proto_item_append_text(proto_root, ", Dst: %s", eui64_to_display(wmem_packet_scope(), packet->dst64));
}
col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: %s", ep_eui64_to_display(packet->dst64));
col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: %s", eui64_to_display(wmem_packet_scope(), packet->dst64));
offset += 8;
}
else if (packet->dst_addr_mode != IEEE802154_FCF_ADDR_NONE) {
@ -848,10 +848,10 @@ dissect_ieee802154_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
TVB_SET_ADDRESS(&pinfo->src, AT_EUI64, tvb, offset, 8);
if (tree) {
proto_tree_add_item(ieee802154_tree, hf_ieee802154_src64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
proto_item_append_text(proto_root, ", Src: %s", ep_eui64_to_display(packet->src64));
proto_item_append_text(proto_root, ", Src: %s", eui64_to_display(wmem_packet_scope(), packet->src64));
}
col_append_fstr(pinfo->cinfo, COL_INFO, ", Src: %s", ep_eui64_to_display(packet->src64));
col_append_fstr(pinfo->cinfo, COL_INFO, ", Src: %s", eui64_to_display(wmem_packet_scope(), packet->src64));
offset += 8;
}
else if (packet->src_addr_mode != IEEE802154_FCF_ADDR_NONE) {

View File

@ -1412,7 +1412,7 @@ static int dissect_zbee_beacon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tr
offset += 8;
/* Update the Info Column with the EPID. */
col_append_fstr(pinfo->cinfo, COL_INFO, ", EPID: %s", ep_eui64_to_display(epid));
col_append_fstr(pinfo->cinfo, COL_INFO, ", EPID: %s", eui64_to_display(wmem_packet_scope(), epid));
/*
* In ZigBee 2006 the Tx-Offset is optional, while in the 2007 and

View File

@ -159,7 +159,7 @@ dissect_zbee_zdp_req_end_device_bind(tvbuff_t *tvb, packet_info *pinfo, proto_tr
for (i=0; i<out_count; i++) zbee_parse_uint(field_tree, hf_zbee_zdp_out_cluster, tvb, &offset, sizeof_cluster, NULL);
if (version >= ZBEE_VERSION_2007) {
zbee_append_info(tree, pinfo, " Src: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, " Src: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
}
zbee_append_info(tree, pinfo, ", Target: 0x%04x", target);
@ -220,13 +220,13 @@ dissect_zbee_zdp_req_bind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g
}
if (version >= ZBEE_VERSION_2007) {
zbee_append_info(tree, pinfo, " Src: %s", ep_eui64_to_display(src64));
zbee_append_info(tree, pinfo, " Src: %s", eui64_to_display(wmem_packet_scope(), src64));
}
if (dst_mode == ZBEE_ZDP_ADDR_MODE_GROUP) {
zbee_append_info(tree, pinfo, ", Dst: 0x%04x", dst);
}
else {
zbee_append_info(tree, pinfo, ", Dst: %s", ep_eui64_to_display(dst64));
zbee_append_info(tree, pinfo, ", Dst: %s", eui64_to_display(wmem_packet_scope(), dst64));
}
/* Dump any leftover bytes. */
@ -286,13 +286,13 @@ dissect_zbee_zdp_req_unbind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
}
if (version >= ZBEE_VERSION_2007) {
zbee_append_info(tree, pinfo, " Src: %s", ep_eui64_to_display(src64));
zbee_append_info(tree, pinfo, " Src: %s", eui64_to_display(wmem_packet_scope(), src64));
}
if (dst_mode == ZBEE_ZDP_ADDR_MODE_GROUP) {
zbee_append_info(tree, pinfo, ", Dst: 0x%04x", dst);
}
else {
zbee_append_info(tree, pinfo, ", Dst: %s", ep_eui64_to_display(dst64));
zbee_append_info(tree, pinfo, ", Dst: %s", eui64_to_display(wmem_packet_scope(), dst64));
}
/* Dump any leftover bytes. */
@ -321,7 +321,7 @@ dissect_zbee_zdp_req_bind_register(tvbuff_t *tvb, packet_info *pinfo, proto_tree
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -355,8 +355,8 @@ dissect_zbee_zdp_req_replace_device(tvbuff_t *tvb, packet_info *pinfo, proto_tre
new_addr = zbee_parse_eui64(tree, hf_zbee_zdp_replacement, tvb, &offset, (int)sizeof(guint64), NULL);
/*new_ep =*/ zbee_parse_uint(tree, hf_zbee_zdp_replacement_ep, tvb, &offset, (int)sizeof(guint8), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Replacement: %s", ep_eui64_to_display(new_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
zbee_append_info(tree, pinfo, ", Replacement: %s", eui64_to_display(wmem_packet_scope(), new_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -406,7 +406,7 @@ dissect_zbee_zdp_req_store_bak_bind_entry(tvbuff_t *tvb, packet_info *pinfo, pro
}
else if (tree) proto_item_append_text(ti, " (Reserved)");
zbee_append_info(tree, pinfo, ", Src: %s", ep_eui64_to_display(src64));
zbee_append_info(tree, pinfo, ", Src: %s", eui64_to_display(wmem_packet_scope(), src64));
zbee_append_info(tree, pinfo, ", Src Endpoint: %d", src_ep);
zbee_append_info(tree, pinfo, ", Cluster: %d", cluster);
@ -458,7 +458,7 @@ dissect_zbee_zdp_req_remove_bak_bind_entry(tvbuff_t *tvb, packet_info *pinfo, pr
}
else if (tree) proto_item_append_text(ti, " (Reserved)");
zbee_append_info(tree, pinfo, ", Src: %s", ep_eui64_to_display(src64));
zbee_append_info(tree, pinfo, ", Src: %s", eui64_to_display(wmem_packet_scope(), src64));
zbee_append_info(tree, pinfo, ", Src Endpoint: %d", src_ep);
zbee_append_info(tree, pinfo, ", Cluster: %d", cluster);

View File

@ -61,7 +61,7 @@ dissect_zbee_zdp_req_nwk_addr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
/*req_type =*/ zbee_parse_uint(tree, hf_zbee_zdp_req_type, tvb, &offset, sizeof(guint8), NULL);
/*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, sizeof(guint8), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -344,7 +344,7 @@ dissect_zbee_zdp_req_discovery_cache(tvbuff_t *tvb, packet_info *pinfo, proto_tr
/*device =*/ zbee_parse_uint(tree, hf_zbee_zdp_device, tvb, &offset, (int)sizeof(guint16), NULL);
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -376,7 +376,7 @@ dissect_zbee_zdp_device_annce(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
/*capability =*/ zdp_parse_cinfo(tree, ett_zbee_zdp_cinfo, tvb, &offset);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -493,7 +493,7 @@ dissect_zbee_zdp_req_store_discovery(tvbuff_t *tvb, packet_info *pinfo, proto_tr
zbee_parse_uint(field_tree, hf_zbee_zdp_disc_simple_size, tvb, &offset, (int)sizeof(guint8), NULL);
}
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -524,7 +524,7 @@ dissect_zbee_zdp_req_store_node_desc(tvbuff_t *tvb, packet_info *pinfo, proto_tr
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zdp_parse_node_desc(tree, ett_zbee_zdp_node, tvb, &offset, version);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -555,7 +555,7 @@ dissect_zbee_zdp_req_store_power_desc(tvbuff_t *tvb, packet_info *pinfo, proto_t
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zdp_parse_power_desc(tree, ett_zbee_zdp_power, tvb, &offset);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -596,7 +596,7 @@ dissect_zbee_zdp_req_store_active_ep(tvbuff_t *tvb, packet_info *pinfo, proto_tr
(void)zbee_parse_uint(field_tree, hf_zbee_zdp_endpoint, tvb, &offset, (int)sizeof(guint8), NULL);
}
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -629,7 +629,7 @@ dissect_zbee_zdp_req_store_simple_desc(tvbuff_t *tvb, packet_info *pinfo, proto_
/*simple_len =*/ zbee_parse_uint(tree, hf_zbee_zdp_simple_length, tvb, &offset, (int)sizeof(guint8), NULL);
zdp_parse_simple_desc(tree, ett_zbee_zdp_simple, tvb, &offset, version);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -659,7 +659,7 @@ dissect_zbee_zdp_req_remove_node_cache(tvbuff_t *tvb, packet_info *pinfo, proto_
/*device =*/ zbee_parse_uint(tree, hf_zbee_zdp_device, tvb, &offset, (int)sizeof(guint16), NULL);
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -689,7 +689,7 @@ dissect_zbee_zdp_req_find_node_cache(tvbuff_t *tvb, packet_info *pinfo, proto_tr
/*device =*/ zbee_parse_uint(tree, hf_zbee_zdp_device, tvb, &offset, (int)sizeof(guint16), NULL);
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -808,7 +808,7 @@ dissect_zbee_zdp_rsp_nwk_addr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
if (status == ZBEE_ZDP_STATUS_SUCCESS) {
zbee_append_info(tree, pinfo, ", Device: %s = 0x%04x", ep_eui64_to_display(ext_addr), device);
zbee_append_info(tree, pinfo, ", Device: %s = 0x%04x", eui64_to_display(wmem_packet_scope(), ext_addr), device);
}
/* Dump any leftover bytes. */
@ -862,7 +862,7 @@ dissect_zbee_zdp_rsp_ext_addr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
if (status == ZBEE_ZDP_STATUS_SUCCESS) {
zbee_append_info(tree, pinfo, ", Device: 0x%04x = %s", device, ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: 0x%04x = %s", device, eui64_to_display(wmem_packet_scope(), ext_addr));
}
/* Dump any leftover bytes. */

View File

@ -372,7 +372,7 @@ dissect_zbee_zdp_req_mgmt_leave(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
offset += 1;
}
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);
@ -402,7 +402,7 @@ dissect_zbee_zdp_req_mgmt_direct_join(tvbuff_t *tvb, packet_info *pinfo, proto_t
ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, 8, NULL);
/*cinfo =*/ zdp_parse_cinfo(tree, ett_zbee_zdp_cinfo, tvb, &offset);
zbee_append_info(tree, pinfo, ", Device: %s", ep_eui64_to_display(ext_addr));
zbee_append_info(tree, pinfo, ", Device: %s", eui64_to_display(wmem_packet_scope(), ext_addr));
/* Dump any leftover bytes. */
zdp_dump_excess(tvb, offset, pinfo, tree);

View File

@ -4386,9 +4386,11 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
offset_r = (int)strlen(result);
break;
case FT_EUI64:
offset_r += protoo_strlcpy(result+offset_r,
eui64_to_str(fvalue_get_integer64(&finfo->value)),
size-offset_r);
{
char* str = eui64_to_str(NULL, fvalue_get_integer64(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
}
break;
case FT_IPv4:
@ -6237,9 +6239,11 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
case FT_EUI64:
integer64 = fvalue_get_integer64(&fi->value);
label_fill_descr(label_str, 0, hfinfo,
ep_eui64_to_display(integer64),
eui64_to_str(integer64));
addr_str = eui64_to_str(NULL, integer64);
tmp = (char*)eui64_to_display(NULL, integer64);
label_fill_descr(label_str, 0, hfinfo, tmp, addr_str);
wmem_free(NULL, tmp);
wmem_free(NULL, addr_str);
break;
case FT_STRING:
case FT_STRINGZ:

View File

@ -67,7 +67,7 @@ void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
void ip6_to_str_buf(const struct e_in6_addr *, gchar *);
extern gchar* ipx_addr_to_str(const guint32, const guint8 *);
extern gchar* ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
WS_DLL_PUBLIC gchar* eui64_to_str(const guint64 ad);
WS_DLL_PUBLIC gchar* eui64_to_str(wmem_allocator_t *scope, const guint64 ad);
WS_DLL_PUBLIC gchar* time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
gchar* time_secs_to_str_unsigned(wmem_allocator_t *scope, const guint32);