From 3d3f97320b90296bdb3649929bcc73a55823dee9 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 21 Dec 2014 08:02:26 -0500 Subject: Replace ip_to_str with [ep_]address_to_str and tvb_ip_to_str. Change-Id: I40d0c8253743183aecef252040b7dd6742ae5c71 Reviewed-on: https://code.wireshark.org/review/5934 Reviewed-by: Michael Mann --- epan/address_to_str.c | 13 ------ epan/dissectors/packet-aim.c | 3 +- epan/dissectors/packet-aodv.c | 56 ++++++++++------------- epan/dissectors/packet-arp.c | 12 ++--- epan/dissectors/packet-babel.c | 10 ++++- epan/dissectors/packet-bat.c | 44 +++++-------------- epan/dissectors/packet-bgp.c | 83 +++++++++++++++++------------------ epan/dissectors/packet-bootp.c | 7 +-- epan/dissectors/packet-btsdp.c | 3 +- epan/dissectors/packet-cdp.c | 5 +-- epan/dissectors/packet-cigi.c | 4 +- epan/dissectors/packet-dcom-remunkn.c | 2 +- epan/dissectors/packet-dcom.c | 22 +++++++--- epan/dissectors/packet-dcom.h | 6 +-- epan/dissectors/packet-dtpt.c | 18 +++----- epan/dissectors/packet-eigrp.c | 7 ++- epan/dissectors/packet-gsm_a_gm.c | 4 +- epan/dissectors/packet-gtp.c | 44 +++++++------------ epan/dissectors/packet-igmp.c | 16 +++---- epan/dissectors/packet-igrp.c | 4 +- epan/dissectors/packet-ip.c | 12 ++--- epan/dissectors/packet-isis-lsp.c | 10 ++--- epan/dissectors/packet-ldp.c | 41 +++++++---------- epan/dissectors/packet-lisp.c | 4 +- epan/dissectors/packet-lldp.c | 12 ++--- epan/dissectors/packet-mount.c | 2 +- epan/dissectors/packet-msnip.c | 14 ++---- epan/dissectors/packet-netflow.c | 4 +- epan/dissectors/packet-nsip.c | 4 +- epan/dissectors/packet-nt-tpcp.c | 8 +--- epan/dissectors/packet-ospf.c | 2 +- epan/dissectors/packet-pcep.c | 4 +- epan/dissectors/packet-radius.c | 8 ++-- epan/dissectors/packet-sflow.c | 35 +++++++-------- epan/dissectors/packet-smb.c | 4 +- epan/dissectors/packet-stun.c | 4 +- epan/dissectors/packet-tcp.c | 20 ++++----- epan/dissectors/packet-udp.c | 4 +- epan/dissectors/packet-vxi11.c | 5 +-- epan/dissectors/packet-wccp.c | 2 +- epan/dissectors/packet-winsrepl.c | 20 +++++---- epan/dissectors/packet-xmcp.c | 4 +- epan/follow.c | 4 +- epan/proto.c | 13 ++++-- epan/to_str.h | 1 - 45 files changed, 263 insertions(+), 341 deletions(-) (limited to 'epan') diff --git a/epan/address_to_str.c b/epan/address_to_str.c index 4ca6546077..4f752fdaf8 100644 --- a/epan/address_to_str.c +++ b/epan/address_to_str.c @@ -83,19 +83,6 @@ tvb_ether_to_str(tvbuff_t *tvb, const gint offset) return bytestring_to_ep_str(tvb_get_ptr(tvb, offset, 6), 6, ':'); } -/* - This function is very fast and this function is called a lot. - XXX update the ep_address_to_str stuff to use this function. -*/ -const gchar * -ip_to_str(const guint8 *ad) { - gchar *buf; - - buf=(gchar *)ep_alloc(MAX_IP_STR_LEN); - ip_to_str_buf(ad, buf, MAX_IP_STR_LEN); - return buf; -} - #define IPV4_LENGTH 4 const gchar * tvb_ip_to_str(tvbuff_t *tvb, const gint offset) diff --git a/epan/dissectors/packet-aim.c b/epan/dissectors/packet-aim.c index 294cbfd743..2435254085 100644 --- a/epan/dissectors/packet-aim.c +++ b/epan/dissectors/packet-aim.c @@ -1186,8 +1186,7 @@ dissect_aim_tlv_value_uint16 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb int dissect_aim_tlv_value_ipv4 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { - guint32 ipv4_address = tvb_get_ipv4(tvb, 0); - proto_item_set_text(ti, "Value: %s", ip_to_str((guint8 *)&ipv4_address)); + proto_item_set_text(ti, "Value: %s", tvb_ip_to_str(tvb, 0)); return 4; } diff --git a/epan/dissectors/packet-aodv.c b/epan/dissectors/packet-aodv.c index 6f03755a38..a3bc0f5ad5 100644 --- a/epan/dissectors/packet-aodv.c +++ b/epan/dissectors/packet-aodv.c @@ -202,10 +202,10 @@ dissect_aodv_rreq(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, guint8 flags; guint8 hop_count; guint32 rreq_id; - guint32 dest_addr_v4; + const gchar *dest_addr_v4; struct e_in6_addr dest_addr_v6; guint32 dest_seqno; - guint32 orig_addr_v4; + const gchar *orig_addr_v4; struct e_in6_addr orig_addr_v6; guint32 orig_seqno; int extlen; @@ -255,15 +255,13 @@ dissect_aodv_rreq(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, ip6_to_str(&dest_addr_v6)); offset += INET6_ADDRLEN; } else { - dest_addr_v4 = tvb_get_ipv4(tvb, offset); + dest_addr_v4 = tvb_ip_to_str(tvb, offset); if (aodv_tree) { - proto_tree_add_ipv4(aodv_tree, hf_aodv_dest_ip, tvb, offset, 4, - dest_addr_v4); - proto_item_append_text(ti, ", Dest IP: %s", - ip_to_str((guint8 *)&dest_addr_v4)); + proto_tree_add_item(aodv_tree, hf_aodv_dest_ip, tvb, offset, 4, + ENC_BIG_ENDIAN); + proto_item_append_text(ti, ", Dest IP: %s", dest_addr_v4); } - col_append_fstr(pinfo->cinfo, COL_INFO, ", D: %s", - ip_to_str((guint8 *)&dest_addr_v4)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", D: %s", dest_addr_v4); offset += 4; } @@ -284,15 +282,13 @@ dissect_aodv_rreq(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, ip6_to_str(&orig_addr_v6)); offset += INET6_ADDRLEN; } else { - orig_addr_v4 = tvb_get_ipv4(tvb, offset); + orig_addr_v4 = tvb_ip_to_str(tvb, offset); if (aodv_tree) { - proto_tree_add_ipv4(aodv_tree, hf_aodv_orig_ip, tvb, offset, 4, - orig_addr_v4); - proto_item_append_text(ti, ", Orig IP: %s", - ip_to_str((guint8 *)&orig_addr_v4)); + proto_tree_add_item(aodv_tree, hf_aodv_orig_ip, tvb, offset, 4, + ENC_BIG_ENDIAN); + proto_item_append_text(ti, ", Orig IP: %s", orig_addr_v4); } - col_append_fstr(pinfo->cinfo, COL_INFO, ", O: %s", - ip_to_str((guint8 *)&orig_addr_v4)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", O: %s", orig_addr_v4); offset += 4; } @@ -320,10 +316,10 @@ dissect_aodv_rrep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, guint8 flags; guint8 prefix_sz; guint8 hop_count; - guint32 dest_addr_v4; + const gchar *dest_addr_v4; struct e_in6_addr dest_addr_v6; guint32 dest_seqno; - guint32 orig_addr_v4; + const gchar *orig_addr_v4; struct e_in6_addr orig_addr_v6; guint32 lifetime; int extlen; @@ -367,15 +363,13 @@ dissect_aodv_rrep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, ip6_to_str(&dest_addr_v6)); offset += INET6_ADDRLEN; } else { - dest_addr_v4 = tvb_get_ipv4(tvb, offset); + dest_addr_v4 = tvb_ip_to_str(tvb, offset); if (aodv_tree) { - proto_tree_add_ipv4(aodv_tree, hf_aodv_dest_ip, tvb, offset, 4, - dest_addr_v4); - proto_item_append_text(ti, ", Dest IP: %s", - ip_to_str((guint8 *)&dest_addr_v4)); + proto_tree_add_item(aodv_tree, hf_aodv_dest_ip, tvb, offset, 4, + ENC_BIG_ENDIAN); + proto_item_append_text(ti, ", Dest IP: %s", dest_addr_v4); } - col_append_fstr(pinfo->cinfo, COL_INFO, ", D: %s", - ip_to_str((guint8 *)&dest_addr_v4)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", D: %s", dest_addr_v4); offset += 4; } @@ -397,15 +391,13 @@ dissect_aodv_rrep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aodv_tree, ip6_to_str(&orig_addr_v6)); offset += INET6_ADDRLEN; } else { - orig_addr_v4 = tvb_get_ipv4(tvb, offset); + orig_addr_v4 = tvb_ip_to_str(tvb, offset); if (aodv_tree) { - proto_tree_add_ipv4(aodv_tree, hf_aodv_orig_ip, tvb, offset, 4, - orig_addr_v4); - proto_item_append_text(ti, ", Orig IP: %s", - ip_to_str((guint8 *)&orig_addr_v4)); + proto_tree_add_item(aodv_tree, hf_aodv_orig_ip, tvb, offset, 4, + ENC_BIG_ENDIAN); + proto_item_append_text(ti, ", Orig IP: %s", orig_addr_v4); } - col_append_fstr(pinfo->cinfo, COL_INFO, ", O: %s", - ip_to_str((guint8 *)&orig_addr_v4)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", O: %s", orig_addr_v4); offset += 4; } diff --git a/epan/dissectors/packet-arp.c b/epan/dissectors/packet-arp.c index 9df897ddb6..7cdf042a5e 100644 --- a/epan/dissectors/packet-arp.c +++ b/epan/dissectors/packet-arp.c @@ -379,20 +379,20 @@ tvb_arphrdaddr_to_str(tvbuff_t *tvb, gint offset, int ad_len, guint16 type) static const gchar * arpproaddr_to_str(const guint8 *ad, int ad_len, guint16 type) { + address addr; + if (ad_len == 0) return ""; if (ARP_PRO_IS_IPv4(type, ad_len)) { /* IPv4 address. */ - return ip_to_str(ad); + SET_ADDRESS(&addr, AT_IPv4, 4, ad); + + return address_to_str(wmem_packet_scope(), &addr); } if (ARP_HW_IS_AX25(type, ad_len)) { { /* AX.25 address */ - address addr; - - addr.type = AT_AX25; - addr.len = AX25_ADDR_LEN; - addr.data = ad; + SET_ADDRESS(&addr, AT_AX25, AX25_ADDR_LEN, ad); return address_to_str(wmem_packet_scope(), &addr); } diff --git a/epan/dissectors/packet-babel.c b/epan/dissectors/packet-babel.c index 65910db306..298007bb20 100644 --- a/epan/dissectors/packet-babel.c +++ b/epan/dissectors/packet-babel.c @@ -104,10 +104,18 @@ static const unsigned char v4prefix[16] = static const char * format_address(const unsigned char *prefix) { + address addr; + if (prefix == NULL) return "corrupt"; else if (memcmp(prefix, v4prefix, 12) == 0) - return ip_to_str(prefix + 12); + { + addr.type = AT_IPv4; + addr.len = 4; + addr.data = prefix + 12; + + return address_to_str(wmem_packet_scope(), &addr); + } else return ip6_to_str((const struct e_in6_addr*)prefix); } diff --git a/epan/dissectors/packet-bat.c b/epan/dissectors/packet-bat.c index 54b9dfe046..51163484b0 100644 --- a/epan/dissectors/packet-bat.c +++ b/epan/dissectors/packet-bat.c @@ -268,13 +268,9 @@ static int dissect_bat_batman_v5(tvbuff_t *tvb, int offset, packet_info *pinfo, if (tree) { proto_item *ti; - if (PTREE_DATA(tree)->visible) { - ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, offset, BATMAN_PACKET_V5_SIZE, + ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, offset, BATMAN_PACKET_V5_SIZE, "B.A.T.M.A.N., Orig: %s (%s)", - get_hostname(orig), ip_to_str((const guint8 *)batman_packeth->orig.data)); - } else { - ti = proto_tree_add_item(tree, proto_bat_plugin, tvb, offset, BATMAN_PACKET_V5_SIZE, ENC_NA); - } + get_hostname(orig), address_to_str(wmem_packet_scope(), &batman_packeth->orig)); bat_batman_tree = proto_item_add_subtree(ti, ett_bat_batman); } @@ -481,19 +477,15 @@ static void dissect_bat_vis_v22(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t /* Set info column */ col_add_fstr(pinfo->cinfo, COL_INFO, "Src: %s (%s)", - get_hostname(sender_ip), ip_to_str((const guint8 *)vis_packeth->sender_ip.data)); + get_hostname(sender_ip), address_to_str(wmem_packet_scope(), &vis_packeth->sender_ip)); /* Set tree info */ if (tree) { proto_item *ti; - if (PTREE_DATA(tree)->visible) { - ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V22_SIZE, + ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V22_SIZE, "B.A.T.M.A.N. Vis, Src: %s (%s)", - get_hostname(sender_ip), ip_to_str((const guint8 *)vis_packeth->sender_ip.data)); - } else { - ti = proto_tree_add_item(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V22_SIZE, ENC_NA); - } + get_hostname(sender_ip), address_to_str(wmem_packet_scope(), &vis_packeth->sender_ip)); bat_vis_tree = proto_item_add_subtree(ti, ett_bat_vis); /* items */ @@ -562,14 +554,10 @@ static void dissect_vis_entry_v22(tvbuff_t *tvb, packet_info *pinfo _U_, proto_t proto_item *ti; proto_tree *bat_vis_entry_tree; - if (PTREE_DATA(tree)->visible) { - ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, 7, + ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, 7, "VIS Entry: [%s] %s (%s)", val_to_str(vis_datah->type, vis_packettypenames, "Unknown (0x%02x)"), - get_hostname(ip), ip_to_str((const guint8 *)vis_datah->ip.data)); - } else { - ti = proto_tree_add_item(tree, proto_bat_plugin, tvb, 0, 7, ENC_NA); - } + get_hostname(ip), address_to_str(wmem_packet_scope(), &vis_datah->ip)); bat_vis_entry_tree = proto_item_add_subtree(ti, ett_bat_vis_entry); proto_tree_add_item(bat_vis_entry_tree, hf_bat_vis_data_type, tvb, 0, 1, ENC_BIG_ENDIAN); @@ -614,19 +602,15 @@ static void dissect_bat_vis_v23(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t /* Set info column */ col_add_fstr(pinfo->cinfo, COL_INFO, "Src: %s (%s)", - get_hostname(sender_ip), ip_to_str((const guint8 *)vis_packeth->sender_ip.data)); + get_hostname(sender_ip), address_to_str(wmem_packet_scope(), &vis_packeth->sender_ip)); /* Set tree info */ if (tree) { proto_item *ti; - if (PTREE_DATA(tree)->visible) { - ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V23_SIZE, + ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V23_SIZE, "B.A.T.M.A.N. Vis, Src: %s (%s)", - get_hostname(sender_ip), ip_to_str((const guint8 *)vis_packeth->sender_ip.data)); - } else { - ti = proto_tree_add_item(tree, proto_bat_plugin, tvb, 0, VIS_PACKET_V23_SIZE, ENC_NA); - } + get_hostname(sender_ip), address_to_str(wmem_packet_scope(), &vis_packeth->sender_ip)); bat_vis_tree = proto_item_add_subtree(ti, ett_bat_vis); /* items */ @@ -695,14 +679,10 @@ static void dissect_vis_entry_v23(tvbuff_t *tvb, packet_info *pinfo _U_, proto_t proto_item *ti; proto_tree *bat_vis_entry_tree; - if (PTREE_DATA(tree)->visible) { - ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, 7, + ti = proto_tree_add_protocol_format(tree, proto_bat_plugin, tvb, 0, 7, "VIS Entry: [%s] %s (%s)", val_to_str(vis_datah->type, vis_packettypenames, "Unknown (0x%02x)"), - get_hostname(ip), ip_to_str((const guint8 *)vis_datah->ip.data)); - } else { - ti = proto_tree_add_item(tree, proto_bat_plugin, tvb, 0, 7, ENC_NA); - } + get_hostname(ip), address_to_str(wmem_packet_scope(), &vis_datah->ip)); bat_vis_entry_tree = proto_item_add_subtree(ti, ett_bat_vis_entry); proto_tree_add_item(bat_vis_entry_tree, hf_bat_vis_data_type, tvb, 0, 1, ENC_BIG_ENDIAN); diff --git a/epan/dissectors/packet-bgp.c b/epan/dissectors/packet-bgp.c index 483a1ad4fe..5317bec388 100644 --- a/epan/dissectors/packet-bgp.c +++ b/epan/dissectors/packet-bgp.c @@ -1713,6 +1713,8 @@ decode_path_prefix4(proto_tree *tree, packet_info *pinfo, int hf_path_id, int hf guint8 plen; /* prefix length */ int length; /* number of octets needed for prefix */ guint32 path_identifier; + address addr; + /* snarf path identifier length and prefix */ path_identifier = tvb_get_ntohl(tvb, offset); plen = tvb_get_guint8(tvb, offset + 4); @@ -1723,9 +1725,10 @@ decode_path_prefix4(proto_tree *tree, packet_info *pinfo, int hf_path_id, int hf return -1; } /* put prefix into protocol tree */ + SET_ADDRESS(&addr, AT_IPv4, 4, ip_addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + 1 + length, ett_bgp_prefix, NULL, "%s/%u PathId %u ", - ip_to_str(ip_addr.addr_bytes), plen, path_identifier); + address_to_str(wmem_packet_scope(), &addr), plen, path_identifier); proto_tree_add_uint(prefix_tree, hf_path_id, tvb, offset, 4, path_identifier); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, offset + 4, 1, plen, "%s prefix length: %u", @@ -1749,6 +1752,7 @@ decode_prefix4(proto_tree *tree, packet_info *pinfo, proto_item *parent_item, in } ip_addr; /* IP address */ guint8 plen; /* prefix length */ int length; /* number of octets needed for prefix */ + address addr; /* snarf length and prefix */ plen = tvb_get_guint8(tvb, offset); @@ -1760,13 +1764,13 @@ decode_prefix4(proto_tree *tree, packet_info *pinfo, proto_item *parent_item, in } /* put prefix into protocol tree */ + SET_ADDRESS(&addr, AT_IPv4, 4, ip_addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, offset, tlen != 0 ? tlen : 1 + length, ett_bgp_prefix, NULL, - "%s/%u", ip_to_str(ip_addr.addr_bytes), plen); - /* append parent item if not NULL */ - if (parent_item != NULL) - proto_item_append_text(parent_item, " (%s/%u)", - ip_to_str(ip_addr.addr_bytes), plen); + "%s/%u", address_to_str(wmem_packet_scope(), &addr), plen); + + proto_item_append_text(parent_item, " (%s/%u)", + address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, offset, 1, plen, "%s prefix length: %u", tag, plen); @@ -2615,7 +2619,6 @@ static int mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, wmem_strbuf_t *strbuf, gint nhlen) { int length; /* length of the address in byte */ - guint32 ip4addr,ip4addr2; /* IPv4 address */ guint16 rd_type; /* Route Distinguisher type */ struct e_in6_addr ip6addr; /* IPv6 address */ @@ -2639,9 +2642,8 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, wmem_strbu } break; case SAFNUM_TUNNEL: - length = 4 ; - ip4addr = tvb_get_ipv4(tvb, offset); - wmem_strbuf_append(strbuf, ip_to_str((guint8 *)&ip4addr)); + length = 4; + wmem_strbuf_append(strbuf, tvb_ip_to_str(tvb, offset)); break; case SAFNUM_LAB_VPNUNICAST: case SAFNUM_LAB_VPNMULCAST: @@ -2650,30 +2652,26 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, wmem_strbu wmem_strbuf_truncate(strbuf, 0); switch (rd_type) { case FORMAT_AS2_LOC: - length = 8 + sizeof(ip4addr); - ip4addr = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */ + length = 12; wmem_strbuf_append_printf(strbuf, "Empty Label Stack RD=%u:%u IPv4=%s", tvb_get_ntohs(tvb, offset + 2), tvb_get_ntohl(tvb, offset + 4), - ip_to_str((guint8 *)&ip4addr)); + tvb_ip_to_str(tvb, offset + 8)); /* Next Hop */ break; case FORMAT_IP_LOC: - length = 8 + sizeof(ip4addr); - ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */ - ip4addr2 = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */ + length = 12; wmem_strbuf_append_printf(strbuf, "Empty Label Stack RD=%s:%u IPv4=%s", - ip_to_str((guint8 *)&ip4addr), + tvb_get_ipv4(tvb, offset + 2), /* IP part of the RD */ tvb_get_ntohs(tvb, offset + 6), - ip_to_str((guint8 *)&ip4addr2)); + tvb_get_ipv4(tvb, offset + 8)); /* Next Hop */ break ; case FORMAT_AS4_LOC: - length = 8 + sizeof(ip4addr); - ip4addr = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */ + length = 12; wmem_strbuf_append_printf(strbuf, "Empty Label Stack RD=%u.%u:%u IPv4=%s", tvb_get_ntohs(tvb, offset + 2), tvb_get_ntohs(tvb, offset + 4), tvb_get_ntohs(tvb, offset + 6), - ip_to_str((guint8 *)&ip4addr)); + tvb_get_ipv4(tvb, offset + 8)); /* Next Hop */ break ; default: length = 0 ; @@ -2716,10 +2714,9 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, wmem_strbu break; case FORMAT_IP_LOC: length = 8 + 16; - ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */ tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */ wmem_strbuf_append_printf(strbuf, "Empty Label Stack RD=%s:%u IPv6=%s", - ip_to_str((guint8 *)&ip4addr), + tvb_ip_to_str(tvb, offset + 2), /* IP part of the RD */ tvb_get_ntohs(tvb, offset + 6), ip6_to_str(&ip6addr)); break ; @@ -2752,9 +2749,8 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, wmem_strbu case SAFNUM_LAB_VPNUNIMULC: case SAFNUM_VPLS: length = 4; /* the next-hop is simply an ipv4 addr */ - ip4addr = tvb_get_ipv4(tvb, offset + 0); wmem_strbuf_append_printf(strbuf, "IPv4=%s", - ip_to_str((guint8 *)&ip4addr)); + tvb_ip_to_str(tvb, offset)); break; default: length = 0 ; @@ -3891,6 +3887,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, guint8 addr_bytes[4]; guint32 addr; } ip4addr, ip4addr2; /* IPv4 address */ + address addr; struct e_in6_addr ip6addr; /* IPv6 address */ guint16 rd_type; /* Route Distinguisher type */ guint16 nlri_type; /* NLRI Type */ @@ -3934,12 +3931,13 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, return -1; } + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, start_offset, (offset + length) - start_offset, ett_bgp_prefix, NULL, "Label Stack=%s IPv4=%s/%u", wmem_strbuf_get_str(stack_strbuf), - ip_to_str(ip4addr.addr_bytes), plen); + address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, start_offset, 1, plen + labnum * 3 * 8, "%s Prefix length: %u", tag, plen + labnum * 3 * 8); proto_tree_add_string_format(prefix_tree, hf_bgp_label_stack, tvb, start_offset + 1, 3 * labnum, wmem_strbuf_get_str(stack_strbuf), @@ -4020,12 +4018,11 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, return -1; } offset += 1; - ip4addr.addr = tvb_get_ipv4(tvb, offset); proto_tree_add_text(tree, tvb, offset, offset + 4, "Endpoint Address: %s", - ip_to_str((guint8 *)&ip4addr)); + tvb_ip_to_str(tvb, offset)); total_length = 5; /* length(1 octet) + address(4 octets) */ break; @@ -4047,11 +4044,12 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, tag, plen + 16); return -1; } + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, start_offset, (offset + length) - start_offset, ett_bgp_prefix, NULL, "Tunnel Identifier=0x%x IPv4=%s/%u", - tnl_id, ip_to_str(ip4addr.addr_bytes), plen); + tnl_id, address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, start_offset, 1, plen + 16, "%s Prefix length: %u", tag, plen + 16); @@ -4097,7 +4095,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, tag, plen + (labnum * 3*8) + 8*8); return -1; } - + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, start_offset, (offset + 8 + length) - start_offset, ett_bgp_prefix, NULL, @@ -4105,7 +4103,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, wmem_strbuf_get_str(stack_strbuf), tvb_get_ntohs(tvb, offset + 2), tvb_get_ntohl(tvb, offset + 4), - ip_to_str(ip4addr.addr_bytes), plen); + address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, start_offset, 1, plen + labnum * 3 * 8 + 8 * 8, "%s Prefix length: %u", tag, plen + labnum * 3 * 8 + 8 * 8); @@ -4130,14 +4128,15 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, return -1; } + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr2.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, start_offset, (offset + 8 + length) - start_offset, ett_bgp_prefix, NULL, "Label Stack=%s RD=%s:%u, IPv4=%s/%u", wmem_strbuf_get_str(stack_strbuf), - ip_to_str(ip4addr.addr_bytes), + tvb_ip_to_str(tvb, offset + 2), tvb_get_ntohs(tvb, offset + 6), - ip_to_str(ip4addr2.addr_bytes), + address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, start_offset, 1, plen + labnum * 3 * 8 + 8 * 8, "%s Prefix length: %u", @@ -4145,7 +4144,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, proto_tree_add_string_format(prefix_tree, hf_bgp_label_stack, tvb, start_offset + 1, 3 * labnum, wmem_strbuf_get_str(stack_strbuf), "%s Label Stack: %s", tag, wmem_strbuf_get_str(stack_strbuf)); proto_tree_add_text(prefix_tree, tvb, start_offset + 1 + 3 * labnum, 8, - "%s Route Distinguisher: %s:%u", tag, ip_to_str(ip4addr.addr_bytes), + "%s Route Distinguisher: %s:%u", tag, tvb_ip_to_str(tvb, offset + 2), tvb_get_ntohs(tvb, offset + 6)); proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb, offset + 8, length, ip4addr2.addr); @@ -4161,6 +4160,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, return -1; } + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr.addr_bytes); prefix_tree = proto_tree_add_subtree_format(tree, tvb, start_offset, (offset + 8 + length) - start_offset, ett_bgp_prefix, NULL, @@ -4169,7 +4169,7 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, tvb_get_ntohs(tvb, offset + 2), tvb_get_ntohs(tvb, offset + 4), tvb_get_ntohs(tvb, offset + 6), - ip_to_str(ip4addr.addr_bytes), plen); + address_to_str(wmem_packet_scope(), &addr), plen); proto_tree_add_uint_format(prefix_tree, hf_bgp_prefix_length, tvb, start_offset, 1, plen + labnum * 3 * 8 + 8 * 8, "%s Prefix length: %u", tag, plen + labnum * 3 * 8 + 8 * 8); @@ -4346,11 +4346,12 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, } /* XXX - break up into multiple fields */ + SET_ADDRESS(&addr, AT_IPv4, 4, ip4addr.addr_bytes); proto_tree_add_string_format(tree, hf_bgp_label_stack, tvb, start_offset, (offset + 8 + length) - start_offset, wmem_strbuf_get_str(stack_strbuf), "Label Stack=%s RD=%s:%u, IPv6=%s/%u", wmem_strbuf_get_str(stack_strbuf), - ip_to_str(ip4addr.addr_bytes), + address_to_str(wmem_packet_scope(), &addr), tvb_get_ntohs(tvb, offset + 6), ip6_to_str(&ip6addr), plen); total_length = (1 + labnum * 3 + 8) + length; @@ -4462,13 +4463,12 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, switch (rd_type) { case FORMAT_AS2_LOC: - tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 6, 4); proto_tree_add_text(tree, tvb, start_offset, (offset + plen + 1) - start_offset, "RD: %u:%s, CE-ID: %u, Label-Block Offset: %u, " "Label-Block Size: %u Label Base %s", tvb_get_ntohs(tvb, offset + 4), - ip_to_str(ip4addr.addr_bytes), + tvb_ip_to_str(tvb, offset + 6), ce_id, labblk_off, labblk_size, @@ -4476,12 +4476,11 @@ decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6, break; case FORMAT_IP_LOC: - tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 4, 4); proto_tree_add_text(tree, tvb, offset, (offset + plen + 1) - start_offset, "RD: %s:%u, CE-ID: %u, Label-Block Offset: %u, " "Label-Block Size: %u, Label Base %s", - ip_to_str(ip4addr.addr_bytes), + tvb_ip_to_str(tvb, offset + 4), tvb_get_ntohs(tvb, offset + 8), ce_id, labblk_off, @@ -5154,7 +5153,6 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen, proto_tree *community_tree; proto_item *communities_item=NULL; proto_item *community_item=NULL; - guint32 ipaddr; /* IPv4 address */ gfloat linkband; /* Link bandwidth */ guint16 as_num; /* Autonomous System Number */ @@ -5249,8 +5247,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen, proto_tree_add_item(community_tree, hf_bgp_ext_com_value_IP4, tvb, offset+2, 4, ENC_BIG_ENDIAN); proto_tree_add_item(community_tree, hf_bgp_ext_com_value_ospf_rtype, tvb, offset+6, 1, ENC_BIG_ENDIAN); proto_tree_add_item(community_tree, hf_bgp_ext_com_value_ospf_rtype_option, tvb, offset+7, 1, ENC_BIG_ENDIAN); - ipaddr = tvb_get_ipv4(tvb,offset+2); - proto_item_append_text(community_item, " Area: %s, Type: %s", ip_to_str((guint8 *)&ipaddr), + proto_item_append_text(community_item, " Area: %s, Type: %s", tvb_ip_to_str(tvb,offset+2), val_to_str_const(tvb_get_guint8(tvb,offset+6), bgpext_com_ospf_rtype, "Unknown")); } else { proto_tree_add_item(community_tree, hf_bgp_ext_com_value_unknown16, tvb, offset+2, 4, ENC_BIG_ENDIAN); diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c index 1ffb02a56b..dca21900d1 100644 --- a/epan/dissectors/packet-bootp.c +++ b/epan/dissectors/packet-bootp.c @@ -4932,7 +4932,6 @@ dissect_packetcable_ietf_ccc(packet_info *pinfo, proto_item *v_ti, proto_tree *v { int suboptoff = optoff; guint8 subopt, subopt_len; - guint32 ipv4addr; guint8 prov_type, fetch_tgt, timer_val; guint16 sec_tcm; proto_tree *pkt_s_tree; @@ -4964,9 +4963,8 @@ dissect_packetcable_ietf_ccc(packet_info *pinfo, proto_item *v_ti, proto_tree *v expert_add_info(pinfo, vti, &ei_bootp_missing_subopt_value); return (optend); } - ipv4addr = tvb_get_ipv4(tvb, suboptoff); proto_item_append_text(vti, "%s (%u byte%s%s)", - ip_to_str((guint8 *)&ipv4addr), + tvb_ip_to_str(tvb, suboptoff), subopt_len, plurality(subopt_len, "", "s"), subopt_len != 4 ? " [Invalid]" : ""); @@ -4993,9 +4991,8 @@ dissect_packetcable_ietf_ccc(packet_info *pinfo, proto_item *v_ti, proto_tree *v expert_add_info(pinfo, vti, &ei_bootp_missing_subopt_value); return (optend); } - ipv4addr = tvb_get_ipv4(tvb, suboptoff); proto_item_append_text(vti, "%s (%u byte%s%s)", - ip_to_str((guint8 *)&ipv4addr), + tvb_ip_to_str(tvb, suboptoff), subopt_len, plurality(subopt_len, "", "s"), subopt_len != 5 ? " [Invalid]" : ""); diff --git a/epan/dissectors/packet-btsdp.c b/epan/dissectors/packet-btsdp.c index d6596c741d..3bd004da99 100644 --- a/epan/dissectors/packet-btsdp.c +++ b/epan/dissectors/packet-btsdp.c @@ -2280,8 +2280,7 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, switch (attribute) { case 0x306: proto_tree_add_item(next_tree, hf_wap_network_address, tvb, offset, 4, ENC_BIG_ENDIAN); - value = tvb_get_ntohl(tvb, offset); - wmem_strbuf_append(info_buf, ip_to_str((guint8 *)&value)); + wmem_strbuf_append(info_buf, tvb_ip_to_str(tvb, offset)); break; case 0x307: proto_tree_add_item(next_tree, hf_wap_gateway, tvb, offset, 1, ENC_BIG_ENDIAN); diff --git a/epan/dissectors/packet-cdp.c b/epan/dissectors/packet-cdp.c index 3b6bd1249e..36d47daefe 100644 --- a/epan/dissectors/packet-cdp.c +++ b/epan/dissectors/packet-cdp.c @@ -1167,7 +1167,7 @@ static void dissect_nrgyz_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, guint16 length, guint16 num, proto_tree *tree) { - guint32 tlvt, tlvl, ip_addr; + guint32 tlvt, tlvl; proto_tree *etree = NULL; char const *ttext = NULL; @@ -1196,11 +1196,10 @@ dissect_nrgyz_tlv(tvbuff_t *tvb, packet_info* pinfo, int offset, guint16 length, ); break; case TYPE_NRGYZ_REPLYTO: - ip_addr = tvb_get_ipv4(tvb, offset + 12); etree = proto_tree_add_subtree_format(tree, tvb, offset, tlvl, ett_cdp_nrgyz_tlv, NULL, "EnergyWise %s: %s port %u", ttext, - ip_to_str((guint8 *)&ip_addr), + tvb_ip_to_str(tvb, offset + 12), tvb_get_ntohs(tvb, offset + 10) ); break; diff --git a/epan/dissectors/packet-cigi.c b/epan/dissectors/packet-cigi.c index 8fc621f3b6..93ef9cfcb1 100644 --- a/epan/dissectors/packet-cigi.c +++ b/epan/dissectors/packet-cigi.c @@ -2637,14 +2637,14 @@ dissect_cigi_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } /* Format the Info String */ - src_str = (const char*)ip_to_str((const guint8 *)pinfo->src.data); + src_str = address_to_str(wmem_packet_scope(), &pinfo->src); if ( !g_ascii_strcasecmp(global_host_ip, src_str) ) { src_str = "Host"; } else if ( !g_ascii_strcasecmp(global_ig_ip, src_str) ) { src_str = "IG"; } - dest_str = (const char*)ip_to_str((const guint8 *)pinfo->dst.data); + dest_str = address_to_str(wmem_packet_scope(), &pinfo->dst); if ( !g_ascii_strcasecmp(global_host_ip, dest_str) ) { dest_str = "Host"; } else if ( !g_ascii_strcasecmp(global_ig_ip, dest_str) ) { diff --git a/epan/dissectors/packet-dcom-remunkn.c b/epan/dissectors/packet-dcom-remunkn.c index 93471108cf..efaa246c58 100644 --- a/epan/dissectors/packet-dcom-remunkn.c +++ b/epan/dissectors/packet-dcom-remunkn.c @@ -180,7 +180,7 @@ dissect_remunk_remqueryinterface_resp(tvbuff_t *tvb, int offset, /* add interface instance to database (we currently only handle IPv4) */ if(pinfo->net_src.type == AT_IPv4) { dcom_interface_new(pinfo, - (guint8 *)pinfo->net_src.data, + &pinfo->net_src, &iid, oxid, oid, &ipid); } diff --git a/epan/dissectors/packet-dcom.c b/epan/dissectors/packet-dcom.c index 9adb31f416..6da11e5288 100644 --- a/epan/dissectors/packet-dcom.c +++ b/epan/dissectors/packet-dcom.c @@ -263,7 +263,7 @@ void dcom_interface_dump(void) { for(machines = dcom_machines; machines != NULL; machines = g_list_next(machines)) { machine = (dcom_machine_t *)machines->data; - g_warning("Machine(#%4u): IP:%s", machine->first_packet, ip_to_str(machine->ip)); + g_warning("Machine(#%4u): IP:%s", machine->first_packet, address_to_str(wmem_packet_scope(), &machine->ip)); for(objects = machine->objects; objects != NULL; objects = g_list_next(objects)) { object = (dcom_object_t *)objects->data; @@ -280,7 +280,7 @@ void dcom_interface_dump(void) { } #endif -dcom_interface_t *dcom_interface_find(packet_info *pinfo _U_, const guint8 *ip _U_, e_uuid_t *ipid) +dcom_interface_t *dcom_interface_find(packet_info *pinfo _U_, const address *addr _U_, e_uuid_t *ipid) { dcom_interface_t *interf; GList *interfaces; @@ -303,7 +303,7 @@ dcom_interface_t *dcom_interface_find(packet_info *pinfo _U_, const guint8 *ip _ } -dcom_interface_t *dcom_interface_new(packet_info *pinfo, const guint8 *ip, e_uuid_t *iid, guint64 oxid, guint64 oid, e_uuid_t *ipid) +dcom_interface_t *dcom_interface_new(packet_info *pinfo, const address *addr, e_uuid_t *iid, guint64 oxid, guint64 oid, e_uuid_t *ipid) { GList *dcom_iter; dcom_machine_t *machine; @@ -335,7 +335,7 @@ dcom_interface_t *dcom_interface_new(packet_info *pinfo, const guint8 *ip, e_uui dcom_iter = dcom_machines; while(dcom_iter != NULL) { machine = (dcom_machine_t *)dcom_iter->data; - if(memcmp(machine->ip, ip, 4) == 0) { + if(CMP_ADDRESS(&machine->ip, addr) == 0) { break; } dcom_iter = g_list_next(dcom_iter); @@ -344,7 +344,7 @@ dcom_interface_t *dcom_interface_new(packet_info *pinfo, const guint8 *ip, e_uui /* create new machine if not found */ if(dcom_iter == NULL) { machine = g_new(dcom_machine_t,1); - memcpy(machine->ip, ip, 4); + COPY_ADDRESS(&machine->ip, addr); machine->objects = NULL; machine->first_packet = pinfo->fd->num; dcom_machines = g_list_append(dcom_machines, machine); @@ -1816,9 +1816,13 @@ dissect_dcom_DUALSTRINGARRAY(tvbuff_t *tvb, gint offset, packet_info *pinfo, first_ip = curr_ip; } else { if(first_ip != curr_ip) { + address first_ip_addr, curr_ip_addr; + + SET_ADDRESS(&first_ip_addr, AT_IPv4, 4, &first_ip); + SET_ADDRESS(&curr_ip_addr, AT_IPv4, 4, &curr_ip); expert_add_info_format(pinfo, pi, &ei_dcom_dualstringarray_mult_ip, "DUALSTRINGARRAY: multiple IP's %s %s", - ip_to_str( (guint8 *) &first_ip), ip_to_str( (guint8 *) &curr_ip)); + address_to_str(wmem_packet_scope(), &first_ip_addr), address_to_str(wmem_packet_scope(), &curr_ip_addr)); } } } @@ -2072,8 +2076,11 @@ dissect_dcom_OBJREF(tvbuff_t *tvb, gint offset, packet_info *pinfo, if(u32Flags == 0x1 || u32Flags == 0x2) { /* add interface instance to database (we currently only handle IPv4) */ if(pinfo->net_src.type == AT_IPv4) { + address addr; + + SET_ADDRESS(&addr, AT_IPv4, 4, ip); dcom_if = dcom_interface_new(pinfo, - (guint8 *) ip, + &addr, &iid, oxid, oid, &ipid); } } @@ -2170,6 +2177,7 @@ static void dcom_reinit( void) { objects->data = NULL; /* for good measure */ } g_list_free(machine->objects); + g_free((void*)machine->ip.data); machine->objects = NULL; /* for good measure */ } diff --git a/epan/dissectors/packet-dcom.h b/epan/dissectors/packet-dcom.h index 3d38131830..20865fc990 100644 --- a/epan/dissectors/packet-dcom.h +++ b/epan/dissectors/packet-dcom.h @@ -45,7 +45,7 @@ typedef struct dcom_machine_s { GList *objects; gint first_packet; - guint8 ip[4]; + address ip; } dcom_machine_t; typedef struct dcom_object_s { @@ -78,8 +78,8 @@ typedef struct dcom_marshaler_s { dcom_dissect_fn_t routine; } dcom_marshaler_t; -WS_DLL_PUBLIC dcom_interface_t *dcom_interface_new(packet_info *pinfo, const guint8 *ip, e_uuid_t *iid, guint64 oxid, guint64 oid, e_uuid_t *ipid); -WS_DLL_PUBLIC dcom_interface_t *dcom_interface_find(packet_info *pinfo, const guint8 *ip, e_uuid_t *ipid); +WS_DLL_PUBLIC dcom_interface_t *dcom_interface_new(packet_info *pinfo, const address *addr, e_uuid_t *iid, guint64 oxid, guint64 oid, e_uuid_t *ipid); +WS_DLL_PUBLIC dcom_interface_t *dcom_interface_find(packet_info *pinfo, const address *addr, e_uuid_t *ipid); #ifdef DEBUG extern void dcom_interface_dump(void); #endif diff --git a/epan/dissectors/packet-dtpt.c b/epan/dissectors/packet-dtpt.c index 45406f0180..2e245fb8a2 100644 --- a/epan/dissectors/packet-dtpt.c +++ b/epan/dissectors/packet-dtpt.c @@ -352,16 +352,14 @@ dissect_dtpt_sockaddr(tvbuff_t *tvb, guint offset, proto_tree *tree, int hfindex switch (family) { case WINSOCK_AF_INET: { guint16 port; - guint32 addr; port = tvb_get_ntohs(tvb,offset+2); proto_tree_add_uint(sockaddr_tree, hf_dtpt_sockaddr_port, - tvb, offset+2,2,port); - addr = tvb_get_ipv4(tvb,offset+4); - proto_tree_add_ipv4(sockaddr_tree, hf_dtpt_sockaddr_address, - tvb, offset+4,4,addr); + tvb, offset+2,2,port); + proto_tree_add_item(sockaddr_tree, hf_dtpt_sockaddr_address, + tvb, offset+4,4,ENC_BIG_ENDIAN); proto_tree_add_item(sockaddr_tree, hf_dtpt_padding, tvb, offset+8, 8, ENC_NA); - proto_item_append_text(sockaddr_item, ": %s:%d", ip_to_str((guint8*)&addr), port); + proto_item_append_text(sockaddr_item, ": %s:%d", tvb_ip_to_str(tvb,offset+4), port); } break; } @@ -376,17 +374,15 @@ dissect_dtpt_sockaddr(tvbuff_t *tvb, guint offset, proto_tree *tree, int hfindex switch (family) { case WINSOCK_AF_INET: { guint16 port; - guint32 addr; proto_tree_add_item(sockaddr_tree, hf_dtpt_padding, tvb, offset+4, 4, ENC_NA); port = tvb_get_ntohs(tvb,offset+8); proto_tree_add_uint(sockaddr_tree, hf_dtpt_sockaddr_port, tvb, offset+8,2,port); - addr = tvb_get_ipv4(tvb,offset+10); - proto_tree_add_ipv4(sockaddr_tree, hf_dtpt_sockaddr_address, - tvb, offset+10,4,addr); + proto_tree_add_item(sockaddr_tree, hf_dtpt_sockaddr_address, + tvb, offset+10,4,ENC_BIG_ENDIAN); proto_tree_add_item(sockaddr_tree, hf_dtpt_padding, tvb, offset+14, 16, ENC_NA); - proto_item_append_text(sockaddr_item, ": %s:%d", ip_to_str((guint8*)&addr), port); + proto_item_append_text(sockaddr_item, ": %s:%d", tvb_ip_to_str(tvb,offset+10), port); } break; } diff --git a/epan/dissectors/packet-eigrp.c b/epan/dissectors/packet-eigrp.c index e51f5d7121..282a1948a8 100644 --- a/epan/dissectors/packet-eigrp.c +++ b/epan/dissectors/packet-eigrp.c @@ -1072,15 +1072,18 @@ dissect_eigrp_ipv4_addr (proto_item *ti, proto_tree *tree, tvbuff_t *tvb, addr_len = 4; /* assure we can exit the loop */ } else { + address addr; + proto_tree_add_item(tree, hf_eigrp_ipv4_prefixlen, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1; + SET_ADDRESS(&addr, AT_IPv4, 4, ip_addr); ti_dst = proto_tree_add_text(tree, tvb, offset, addr_len, - "Destination: %s", ip_to_str(ip_addr)); + "Destination: %s", address_to_str(wmem_packet_scope(), &addr)); /* add it to the top level line */ proto_item_append_text(ti," %c %s/%u", first ? '=':',', - ip_to_str(ip_addr), length); + address_to_str(wmem_packet_scope(), &addr), length); if (unreachable) { expert_add_info(pinfo, ti_dst, &ei_eigrp_unreachable); diff --git a/epan/dissectors/packet-gsm_a_gm.c b/epan/dissectors/packet-gsm_a_gm.c index dd6af5ba7f..338db917b6 100644 --- a/epan/dissectors/packet-gsm_a_gm.c +++ b/epan/dissectors/packet-gsm_a_gm.c @@ -4161,7 +4161,6 @@ de_sm_pco(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, g guchar oct; struct e_in6_addr ipv6_addrx; int link_dir; - guint32 ipv4_addrx; proto_item *pco_item; proto_tree *pco_tree; @@ -4259,9 +4258,8 @@ de_sm_pco(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, g case 0x000C: case 0x000D: if ((link_dir == P2P_DIR_DL) && (e_len > 0)) { - ipv4_addrx = tvb_get_ipv4(tvb, curr_offset); proto_tree_add_text(pco_tree, tvb, curr_offset, 4, "IPv4: %s", - ip_to_str((guint8 *)&ipv4_addrx)); + tvb_ip_to_str(tvb, curr_offset)); } break; case 0x000E: diff --git a/epan/dissectors/packet-gtp.c b/epan/dissectors/packet-gtp.c index f25f8418f6..e26638df11 100644 --- a/epan/dissectors/packet-gtp.c +++ b/epan/dissectors/packet-gtp.c @@ -3906,7 +3906,6 @@ decode_gtp_user_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ guint16 length; guint8 pdp_typ, pdp_org; - guint32 addr_ipv4; struct e_in6_addr addr_ipv6; proto_tree *ext_tree_user; proto_item *te; @@ -3934,9 +3933,8 @@ decode_gtp_user_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ } else if (length > 2) { switch (pdp_typ) { case 0x21: - addr_ipv4 = tvb_get_ipv4(tvb, offset + 5); - proto_tree_add_ipv4(ext_tree_user, hf_gtp_user_ipv4, tvb, offset + 5, 4, addr_ipv4); - proto_item_append_text(te, " : %s", ip_to_str((guint8 *) & addr_ipv4)); + proto_tree_add_item(ext_tree_user, hf_gtp_user_ipv4, tvb, offset + 5, 4, ENC_BIG_ENDIAN); + proto_item_append_text(te, " : %s", tvb_ip_to_str(tvb, offset + 5)); break; case 0x57: tvb_get_ipv6(tvb, offset + 5, &addr_ipv6); @@ -3944,11 +3942,10 @@ decode_gtp_user_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ proto_item_append_text(te, " : %s", ip6_to_str((struct e_in6_addr *) &addr_ipv6)); break; case 0x8d: - addr_ipv4 = tvb_get_ipv4(tvb, offset + 5); - proto_tree_add_ipv4(ext_tree_user, hf_gtp_user_ipv4, tvb, offset + 5, 4, addr_ipv4); + proto_tree_add_item(ext_tree_user, hf_gtp_user_ipv4, tvb, offset + 5, 4, ENC_BIG_ENDIAN); tvb_get_ipv6(tvb, offset + 9, &addr_ipv6); proto_tree_add_ipv6(ext_tree_user, hf_gtp_user_ipv6, tvb, offset + 9, 16, (guint8 *) & addr_ipv6); - proto_item_append_text(te, " : %s / %s", ip_to_str((guint8 *) & addr_ipv4), + proto_item_append_text(te, " : %s / %s", tvb_ip_to_str(tvb, offset + 5), ip6_to_str((struct e_in6_addr *) &addr_ipv6)); break; } @@ -5006,7 +5003,6 @@ decode_gtp_gsn_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_t guint8 addr_type, addr_len; guint16 length; - guint32 addr_ipv4; struct e_in6_addr addr_ipv6; proto_tree *ext_tree_gsn_addr; proto_item *te; @@ -5018,9 +5014,8 @@ decode_gtp_gsn_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_t switch (length) { case 4: proto_tree_add_item(ext_tree_gsn_addr, hf_gtp_gsn_address_length, tvb, offset + 1, 2, ENC_BIG_ENDIAN); - addr_ipv4 = tvb_get_ipv4(tvb, offset + 3); - proto_item_append_text(te, "%s", ip_to_str((guint8 *) & addr_ipv4)); - proto_tree_add_ipv4(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset + 3, 4, addr_ipv4); + proto_tree_add_item(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset + 3, 4, ENC_BIG_ENDIAN); + proto_item_append_text(te, "%s", tvb_ip_to_str(tvb, offset + 3)); break; case 5: proto_tree_add_item(ext_tree_gsn_addr, hf_gtp_gsn_address_information_element_length, tvb, offset + 1, 2, ENC_BIG_ENDIAN); @@ -5028,9 +5023,8 @@ decode_gtp_gsn_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_t proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_type, tvb, offset + 3, 1, addr_type); addr_len = tvb_get_guint8(tvb, offset + 3) & 0x3F; proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_len, tvb, offset + 3, 1, addr_len); - addr_ipv4 = tvb_get_ipv4(tvb, offset + 4); - proto_item_append_text(te, "%s", ip_to_str((guint8 *) & addr_ipv4)); - proto_tree_add_ipv4(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset + 4, 4, addr_ipv4); + proto_tree_add_item(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset + 4, 4, ENC_BIG_ENDIAN); + proto_item_append_text(te, "%s", tvb_ip_to_str(tvb, offset + 4)); break; case 16: proto_tree_add_item(ext_tree_gsn_addr, hf_gtp_gsn_address_length, tvb, offset + 1, 2, ENC_BIG_ENDIAN); @@ -5044,7 +5038,7 @@ decode_gtp_gsn_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_t proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_type, tvb, offset + 3, 1, addr_type); addr_len = tvb_get_guint8(tvb, offset + 3) & 0x3F; proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_len, tvb, offset + 3, 1, addr_len); - tvb_get_ipv6(tvb, offset + 4, &addr_ipv6); + tvb_get_ipv6(tvb, offset + 4, &addr_ipv6); proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr *) &addr_ipv6)); proto_tree_add_ipv6(ext_tree_gsn_addr, hf_gtp_gsn_ipv6, tvb, offset + 4, 16, (guint8 *) & addr_ipv6); break; @@ -5146,7 +5140,7 @@ decode_gtp_tft(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_tree * guint16 length, port1, port2, tos; guint8 tft_flags, tft_code, no_packet_filters, i, pf_eval, pf_len, pf_content_id, proto; guint pf_offset; - guint32 mask_ipv4, addr_ipv4, ipsec_id, label; + guint32 ipsec_id, label; struct e_in6_addr addr_ipv6, mask_ipv6; proto_tree *ext_tree_tft, *ext_tree_tft_pf, *ext_tree_tft_flags; proto_item *tee, *pf_item; @@ -5193,10 +5187,8 @@ decode_gtp_tft(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_tree * switch (pf_content_id) { /* address IPv4 and mask = 8 bytes */ case 0x10: - addr_ipv4 = tvb_get_ipv4(tvb, offset + pf_offset + 1); - mask_ipv4 = tvb_get_ipv4(tvb, offset + pf_offset + 5); - proto_item_set_text(pf_item, "ID 0x10: IPv4/mask: %s/%s", ip_to_str((guint8 *) & addr_ipv4), - ip_to_str((guint8 *) & mask_ipv4)); + proto_item_set_text(pf_item, "ID 0x10: IPv4/mask: %s/%s", tvb_ip_to_str(tvb, offset + pf_offset + 1), + tvb_ip_to_str(tvb, offset + pf_offset + 5)); proto_item_set_len(pf_item, 9); pf_offset += 9; break; @@ -5468,7 +5460,6 @@ decode_gtp_chrg_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ { guint16 length; - guint32 addr_ipv4; struct e_in6_addr addr_ipv6; proto_tree *ext_tree_chrg_addr; proto_item *te; @@ -5482,9 +5473,8 @@ decode_gtp_chrg_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ switch (length) { case 4: - addr_ipv4 = tvb_get_ipv4(tvb, offset + 3); - proto_item_append_text(te, "%s", ip_to_str((guint8 *) & addr_ipv4)); - proto_tree_add_ipv4(ext_tree_chrg_addr, hf_gtp_chrg_ipv4, tvb, offset + 3, 4, addr_ipv4); + proto_tree_add_item(ext_tree_chrg_addr, hf_gtp_chrg_ipv4, tvb, offset + 3, 4, ENC_BIG_ENDIAN); + proto_item_append_text(te, "%s", tvb_ip_to_str(tvb, offset + 3)); break; case 16: tvb_get_ipv6(tvb, offset + 3, &addr_ipv6); @@ -7794,7 +7784,6 @@ decode_gtp_node_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ { guint16 length; - guint32 addr_ipv4; struct e_in6_addr addr_ipv6; proto_tree *ext_tree_node_addr; proto_item *te; @@ -7808,9 +7797,8 @@ decode_gtp_node_addr(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_ switch (length) { case 4: - addr_ipv4 = tvb_get_ipv4(tvb, offset + 3); - proto_item_append_text(te, "%s", ip_to_str((guint8 *) & addr_ipv4)); - proto_tree_add_ipv4(ext_tree_node_addr, hf_gtp_node_ipv4, tvb, offset + 3, 4, addr_ipv4); + proto_tree_add_item(ext_tree_node_addr, hf_gtp_node_ipv4, tvb, offset + 3, 4, ENC_BIG_ENDIAN); + proto_item_append_text(te, "%s", tvb_ip_to_str(tvb, offset + 3)); break; case 16: tvb_get_ipv6(tvb, offset + 3, &addr_ipv6); diff --git a/epan/dissectors/packet-igmp.c b/epan/dissectors/packet-igmp.c index 8a16eb6a5e..3a53c2030e 100644 --- a/epan/dissectors/packet-igmp.c +++ b/epan/dissectors/packet-igmp.c @@ -593,7 +593,6 @@ dissect_igmp_v3_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree { proto_tree* tree; guint16 num; - guint32 maddr; int offset; unsigned char type; @@ -610,12 +609,11 @@ dissect_igmp_v3_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree /* group address */ proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN); - maddr = tvb_get_ipv4(tvb, offset); - if (! maddr) { + if (!tvb_get_ipv4(tvb, offset)) { col_append_str(pinfo->cinfo, COL_INFO, ", general"); } else { col_append_fstr(pinfo->cinfo, COL_INFO, ", specific for group %s", - ip_to_str((guint8*)&maddr)); + tvb_ip_to_str(tvb, offset)); } offset +=4; @@ -648,7 +646,6 @@ dissect_igmp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void { proto_tree* tree; guint8 tsecs; - guint32 maddr; int offset; unsigned char type; @@ -667,20 +664,19 @@ dissect_igmp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void /* group address */ proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN); - maddr = tvb_get_ipv4(tvb, offset); - if (! maddr) { + if (! tvb_get_ipv4(tvb, offset)) { col_append_str(pinfo->cinfo, COL_INFO, ", general"); } else { switch(type) { case IGMP_V2_LEAVE_GROUP: - col_append_fstr(pinfo->cinfo, COL_INFO, " %s", ip_to_str((guint8*)&maddr)); + col_append_fstr(pinfo->cinfo, COL_INFO, " %s", tvb_ip_to_str(tvb, offset)); break; case IGMP_V1_HOST_MEMBERSHIP_QUERY: - col_append_fstr(pinfo->cinfo, COL_INFO, ", specific for group %s", ip_to_str((guint8*)&maddr)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", specific for group %s", tvb_ip_to_str(tvb, offset)); break; default: /* IGMP_V2_MEMBERSHIP_REPORT is the only case left */ - col_append_fstr(pinfo->cinfo, COL_INFO, " group %s", ip_to_str((guint8*)&maddr)); + col_append_fstr(pinfo->cinfo, COL_INFO, " group %s", tvb_ip_to_str(tvb, offset)); break; } } diff --git a/epan/dissectors/packet-igrp.c b/epan/dissectors/packet-igrp.c index 11e6a64b0d..28429f450d 100644 --- a/epan/dissectors/packet-igrp.c +++ b/epan/dissectors/packet-igrp.c @@ -157,6 +157,7 @@ static void dissect_igrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) static void dissect_vektor_igrp (tvbuff_t *tvb, proto_tree *igrp_vektor_tree, guint8 network) { guint8 *ptr_addr,addr[5]; + address ip_addr; addr[0]=network; addr[1]=tvb_get_guint8(tvb,0); @@ -167,8 +168,9 @@ static void dissect_vektor_igrp (tvbuff_t *tvb, proto_tree *igrp_vektor_tree, gu ptr_addr=addr; if (network==0) ptr_addr=&addr[1]; + SET_ADDRESS(&ip_addr, AT_IPv4, 4, ptr_addr); igrp_vektor_tree = proto_tree_add_subtree_format(igrp_vektor_tree, tvb, 0 ,14, - ett_igrp_net, NULL, "Entry for network %s", ip_to_str(ptr_addr)); + ett_igrp_net, NULL, "Entry for network %s", address_to_str(wmem_packet_scope(), &ip_addr)); proto_tree_add_ipv4(igrp_vektor_tree, hf_igrp_network, tvb, 0, 3, *((guint32*)ptr_addr)); proto_tree_add_item(igrp_vektor_tree, hf_igrp_delay, tvb, 3, 3, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_bandwidth, tvb, 6, 3, ENC_BIG_ENDIAN); diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index d53290306b..93bfbe6ea8 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -548,8 +548,8 @@ static gchar* ip_build_color_filter(packet_info *pinfo) { return g_strdup_printf("ip.addr eq %s and ip.addr eq %s", - ip_to_str( (const guint8 *)pinfo->net_src.data), - ip_to_str( (const guint8 *)pinfo->net_dst.data)); + address_to_str(wmem_packet_scope(), &pinfo->net_src), + address_to_str(wmem_packet_scope(), &pinfo->net_dst)); } /* @@ -1167,7 +1167,7 @@ dissect_option_route(proto_tree *tree, tvbuff_t *tvb, int offset, int hf, if (next) proto_tree_add_ipv4_format_value(tree, hf, tvb, offset, 4, route, "%s <- (next)", - ip_to_str((gchar *)&route)); + tvb_ip_to_str(tvb, offset)); else proto_tree_add_ipv4(tree, hf, tvb, offset, 4, route); ti = proto_tree_add_string(tree, hf_host, tvb, offset, 4, get_hostname(route)); @@ -2234,7 +2234,7 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) src_host = get_hostname(addr); if (ip_summary_in_tree) { proto_item_append_text(ti, ", Src: %s (%s)", src_host, - ip_to_str((const guint8 *)iph->ip_src.data)); + address_to_str(wmem_packet_scope(), &iph->ip_src)); } proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, addr); item = proto_tree_add_ipv4(ip_tree, hf_ip_addr, tvb, offset + 12, 4, addr); @@ -2302,10 +2302,10 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) cur_rt = tvb_get_ipv4(tvb, offset + 16); if (ip_summary_in_tree) { proto_item_append_text(ti, ", Dst: %s (%s)", dst_host, - ip_to_str((const guint8 *)iph->ip_dst.data)); + address_to_str(wmem_packet_scope(), &iph->ip_dst)); if (dst_off) proto_item_append_text(ti, ", Via: %s (%s)", get_hostname(cur_rt), - ip_to_str((gchar *)&cur_rt)); + tvb_ip_to_str(tvb, offset + 16)); } if (dst_off) { diff --git a/epan/dissectors/packet-isis-lsp.c b/epan/dissectors/packet-isis-lsp.c index 7f9cfdda6e..f16c1ab5b7 100644 --- a/epan/dissectors/packet-isis-lsp.c +++ b/epan/dissectors/packet-isis-lsp.c @@ -487,10 +487,10 @@ dissect_lsp_ip_reachability_clv(tvbuff_t *tvb, packet_info* pinfo, proto_tree *t if(found_mask) { ti = proto_tree_add_ipv4_format_value( tree, hf_isis_lsp_ip_reachability_ipv4_prefix, tvb, offset, 12, - src, "%s/%d", ip_to_str((guint8*)&src), prefix_len ); + src, "%s/%d", tvb_ip_to_str(tvb, offset+4), prefix_len ); } else { ti = proto_tree_add_ipv4_format_value( tree, hf_isis_lsp_ip_reachability_ipv4_prefix, tvb, offset, 12, - src, "%s mask %s", ip_to_str((guint8*)&src), tvb_ip_to_str(tvb, offset+8)); + src, "%s mask %s", tvb_ip_to_str(tvb, offset+4), tvb_ip_to_str(tvb, offset+8)); }; ntree = proto_item_add_subtree(ti, ett_isis_lsp_clv_ip_reachability); @@ -592,12 +592,11 @@ dissect_lsp_ext_ip_reachability_clv(tvbuff_t *tvb, packet_info* pinfo, proto_tre guint bit_length; int byte_length; guint8 prefix [4]; + address prefix_addr; guint len,i; guint subclvs_len; guint clv_code, clv_len; - if (!tree) return; - while (length > 0) { ctrl_info = tvb_get_guint8(tvb, offset+4); bit_length = ctrl_info & 0x3f; @@ -615,8 +614,9 @@ dissect_lsp_ext_ip_reachability_clv(tvbuff_t *tvb, packet_info* pinfo, proto_tre subtree = proto_tree_add_subtree(tree, tvb, offset, 5+byte_length+subclvs_len, ett_isis_lsp_part_of_clv_ext_ip_reachability, NULL, "Ext. IP Reachability"); + SET_ADDRESS(&prefix_addr, AT_IPv4, 4, prefix); proto_tree_add_ipv4_format_value(subtree, hf_isis_lsp_ext_ip_reachability_ipv4_prefix, tvb, offset+5, byte_length, - tvb_get_ntohl(tvb, offset+5), "%s/%u", ip_to_str (prefix), bit_length); + tvb_get_ntohl(tvb, offset+5), "%s/%u", address_to_str(wmem_packet_scope(), &prefix_addr), bit_length); proto_tree_add_item(subtree, hf_isis_lsp_ext_ip_reachability_metric, tvb, offset, 4, ENC_BIG_ENDIAN); proto_tree_add_item(subtree, hf_isis_lsp_ext_ip_reachability_distribution, tvb, offset+4, 1, ENC_NA); diff --git a/epan/dissectors/packet-ldp.c b/epan/dissectors/packet-ldp.c index b492ceb106..e2fb81fbd5 100644 --- a/epan/dissectors/packet-ldp.c +++ b/epan/dissectors/packet-ldp.c @@ -897,18 +897,6 @@ static const true_false_string tlv_upstr_sbit_vals = { #define PW_PSN_PW_INGRESS_RECV_FAULT 0x8 #define PW_PSN_PW_EGRESS_TRANS_FAULT 0x10 -/* Define storage class for a string handler function - * with a const guint8 * argument, and returning a const gchar * - */ -typedef const gchar *(string_handler_func)(const guint8 *); - -/* Default handler for address to string conversion */ -static const gchar * -default_str_handler(const guint8 * bytes _U_) -{ - return ""; -} - static void dissect_subtlv_interface_parameters(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem, int *interface_parameters_hf[]); @@ -968,9 +956,10 @@ dissect_tlv_fec(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tre guint16 op_length = tvb_get_bits16(tvb, ((offset+8)*8), 16, ENC_BIG_ENDIAN); guint8 addr_size=0, *addr, implemented, prefix_len_octets, prefix_len, host_len, vc_len; guint8 intparam_len, aai_type = 0; - string_handler_func *str_handler = default_str_handler; const char *str; guint8 gen_fec_id_len = 0; + address_type addr_type; + address addr_str; val_tree=proto_tree_add_subtree(tree, tvb, offset, rem, ett_ldp_tlv_val, NULL, "FEC Elements"); @@ -998,11 +987,11 @@ dissect_tlv_fec(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tre switch(family) { case AFNUM_INET: /*IPv4*/ addr_size=4; - str_handler=ip_to_str; + addr_type = AT_IPv4; break; case AFNUM_INET6: /*IPv6*/ addr_size=16; - str_handler = (string_handler_func *) ip6_to_str; + addr_type = AT_IPv6; break; default: implemented=0; @@ -1053,7 +1042,8 @@ dissect_tlv_fec(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tre if ( prefix_len % 8 ) addr[ax-1] = addr[ax-1]&(0xFF<<(8-prefix_len%8)); - str = str_handler((const guint8 *)addr); + SET_ADDRESS(&addr_str, addr_type, addr_size, addr); + str = address_to_str(wmem_packet_scope(), &addr_str); proto_tree_add_string_format(fec_tree, hf_ldp_tlv_fec_pfval, tvb, offset, prefix_len_octets, str, "Prefix: %s", str); @@ -1073,11 +1063,11 @@ dissect_tlv_fec(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tre switch(family) { case AFNUM_INET: /*IPv4*/ addr_size=4; - str_handler=ip_to_str; + addr_type = AT_IPv4; break; case AFNUM_INET6: /*IPv6*/ addr_size=16; - str_handler = (string_handler_func *) ip6_to_str; + addr_type = AT_IPv6; break; default: implemented=0; @@ -1125,7 +1115,8 @@ dissect_tlv_fec(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tree *tre for(ax=0; ax+1 <= host_len; ax++) addr[ax]=tvb_get_guint8(tvb, offset+ax); - str = str_handler((const guint8 *)addr); + SET_ADDRESS(&addr_str, addr_type, addr_size, addr); + str = address_to_str(wmem_packet_scope(), &addr_str); proto_tree_add_string_format(fec_tree, hf_ldp_tlv_fec_hoval, tvb, offset, host_len, str, "Address: %s", str); @@ -1373,8 +1364,9 @@ dissect_tlv_address_list(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_ proto_tree *val_tree; guint16 family, ix; guint8 addr_size, *addr; - string_handler_func *str_handler = default_str_handler; const char *str; + address_type addr_type; + address addr_str; if ( rem < 2 ) { proto_tree_add_expert_format(tree, pinfo, &ei_ldp_tlv_fec_len, tvb, offset, rem, @@ -1389,11 +1381,11 @@ dissect_tlv_address_list(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_ switch(family) { case AFNUM_INET: /*IPv4*/ addr_size=4; - str_handler=ip_to_str; + addr_type = AT_IPv4; break; case AFNUM_INET6: /*IPv6*/ addr_size=16; - str_handler = (string_handler_func *) ip6_to_str; + addr_type = AT_IPv6; break; default: proto_tree_add_expert(tree, pinfo, &ei_ldp_address_family_not_implemented, tvb, offset+2, rem-2); @@ -1411,7 +1403,8 @@ dissect_tlv_address_list(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_ == NULL) break; - str = str_handler((const guint8 *)addr); + SET_ADDRESS(&addr_str, addr_type, addr_size, addr); + str = address_to_str(wmem_packet_scope(), &addr_str); proto_tree_add_string_format(val_tree, hf_ldp_tlv_addrl_addr, tvb, offset, addr_size, str, "Address %u: %s", ix, str); @@ -1436,7 +1429,7 @@ dissect_tlv_path_vector(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_t proto_tree_add_ipv4_format(val_tree, hf_ldp_tlv_pv_lsrid, tvb, offset, 4, addr, "LSR Id %u: %s", ix, - ip_to_str((guint8 *)&addr)); + tvb_ip_to_str(tvb, offset)); } if (rem) proto_tree_add_expert_format(tree, pinfo, &ei_ldp_tlv_fec_len, tvb, offset, rem, "Error processing TLV: Extra data at end of path vector"); diff --git a/epan/dissectors/packet-lisp.c b/epan/dissectors/packet-lisp.c index 189dc7aaa7..7f68a35b3e 100644 --- a/epan/dissectors/packet-lisp.c +++ b/epan/dissectors/packet-lisp.c @@ -515,7 +515,6 @@ get_addr_str(tvbuff_t *tvb, gint offset, guint16 afi, guint16 *addr_len) { const gchar *notset_str = "not set"; const gchar *addr_str; - guint32 locator_v4; struct e_in6_addr locator_v6; guint8 lcaf_type; guint32 iid, asn; @@ -526,9 +525,8 @@ get_addr_str(tvbuff_t *tvb, gint offset, guint16 afi, guint16 *addr_len) *addr_len = 0; return notset_str; case AFNUM_INET: - locator_v4 = tvb_get_ipv4(tvb, offset); *addr_len = INET_ADDRLEN; - addr_str = ip_to_str((guint8 *)&locator_v4); + addr_str = tvb_ip_to_str(tvb, offset); return addr_str; case AFNUM_INET6: tvb_get_ipv6(tvb, offset, &locator_v6); diff --git a/epan/dissectors/packet-lldp.c b/epan/dissectors/packet-lldp.c index 3bd0ca3c0f..6efcf1c5d6 100644 --- a/epan/dissectors/packet-lldp.c +++ b/epan/dissectors/packet-lldp.c @@ -1104,7 +1104,6 @@ dissect_lldp_chassis_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gui guint16 tempShort; guint32 dataLen = 0; const char *strPtr=NULL; - guint32 ip_addr = 0; struct e_in6_addr ip6_addr; guint8 addr_family = 0; @@ -1177,15 +1176,14 @@ dissect_lldp_chassis_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gui switch(addr_family){ case AFNUM_INET: if (dataLen == 6){ - ip_addr = tvb_get_ipv4(tvb, offset); - strPtr = ip_to_str((guint8 *)&ip_addr); + strPtr = tvb_ip_to_str(tvb, offset); }else{ expert_add_info_format(pinfo, lf, &ei_lldp_bad_length, "Invalid Chassis ID Length (%u) for Type (%s, %s), expected (6)", dataLen, val_to_str_const(tlvsubType, chassis_id_subtypes, ""), val_to_str_const(addr_family, afn_vals, "")); return -1; } - proto_tree_add_ipv4(chassis_tree, hf_chassis_id_ip4, tvb, offset, 4, ip_addr); + proto_tree_add_item(chassis_tree, hf_chassis_id_ip4, tvb, offset, 4, ENC_BIG_ENDIAN); break; case AFNUM_INET6: @@ -1264,7 +1262,6 @@ dissect_lldp_port_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint3 guint16 tempShort; guint32 dataLen = 0; const char *strPtr=NULL; - guint32 ip_addr = 0; struct e_in6_addr ip6_addr; guint8 addr_family = 0; @@ -1333,15 +1330,14 @@ dissect_lldp_port_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint3 switch(addr_family){ case AFNUM_INET: if (dataLen == 6){ - ip_addr = tvb_get_ipv4(tvb, offset); - strPtr = ip_to_str((guint8 *)&ip_addr); + strPtr = tvb_ip_to_str(tvb, offset); }else{ expert_add_info_format(pinfo, lf, &ei_lldp_bad_length, "Invalid Port ID Length (%u) for Type (%s, %s), expected (6)", dataLen, val_to_str_const(tlvsubType, port_id_subtypes, ""), val_to_str_const(addr_family, afn_vals, "")); return -1; } - proto_tree_add_ipv4(port_tree, hf_port_id_ip4, tvb, offset, 4, ip_addr); + proto_tree_add_item(port_tree, hf_port_id_ip4, tvb, offset, 4, ENC_BIG_ENDIAN); break; case AFNUM_INET6: diff --git a/epan/dissectors/packet-mount.c b/epan/dissectors/packet-mount.c index 6d09e5908c..dacb2195b4 100644 --- a/epan/dissectors/packet-mount.c +++ b/epan/dissectors/packet-mount.c @@ -166,7 +166,7 @@ dissect_mount_dirpath_call(tvbuff_t *tvb, int offset, packet_info *pinfo, guint32 len; unsigned char *ptr; - host=ip_to_str((const guint8 *)pinfo->dst.data); + host=address_to_str(wmem_packet_scope(), &pinfo->dst); len=tvb_get_ntohl(tvb, offset); if (len >= ITEM_LABEL_LENGTH) THROW(ReportedBoundsError); diff --git a/epan/dissectors/packet-msnip.c b/epan/dissectors/packet-msnip.c index 5b90526b9a..330ceceacb 100644 --- a/epan/dissectors/packet-msnip.c +++ b/epan/dissectors/packet-msnip.c @@ -96,7 +96,6 @@ dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, in proto_tree *tree; proto_item *item; guint8 rec_type; - guint32 maddr; int old_offset = offset; item = proto_tree_add_item(parent_tree, hf_groups, @@ -112,14 +111,12 @@ dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, in offset += 3; /* multicast group */ - maddr = tvb_get_ipv4(tvb, offset); - proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4, - maddr); + proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4; if (item) { proto_item_set_text(item,"Group: %s %s", - ip_to_str((guint8 *)&maddr), + tvb_ip_to_str(tvb, offset-4), val_to_str(rec_type, msnip_rec_types, "Unknown Type:0x%02x")); @@ -174,7 +171,6 @@ dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int while (count--) { proto_tree *tree; proto_item *item; - guint32 maddr; guint8 masklen; int old_offset = offset; @@ -183,9 +179,7 @@ dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int tree = proto_item_add_subtree(item, ett_groups); /* multicast group */ - maddr = tvb_get_ipv4(tvb, offset); - proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4, - maddr); + proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4; /* mask length */ @@ -199,7 +193,7 @@ dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int if (item) { proto_item_set_text(item,"Group: %s/%d", - ip_to_str((guint8 *)&maddr), masklen); + tvb_ip_to_str(tvb, offset - 8), masklen); proto_item_set_len(item, offset-old_offset); } diff --git a/epan/dissectors/packet-netflow.c b/epan/dissectors/packet-netflow.c index 023ed23926..eb8dae1682 100644 --- a/epan/dissectors/packet-netflow.c +++ b/epan/dissectors/packet-netflow.c @@ -6226,10 +6226,12 @@ static const gchar * getprefix(const guint32 *addr, int prefix) { guint32 gprefix; + address prefix_addr; gprefix = *addr & g_htonl((0xffffffff << (32 - prefix))); - return (ip_to_str((const guint8 *)&gprefix)); + SET_ADDRESS(&prefix_addr, AT_IPv4, 4, &gprefix); + return address_to_str(wmem_packet_scope(), &prefix_addr); } /* Called whenever a new capture is loaded, a complete redissection is done, a pref is changed, & etc */ diff --git a/epan/dissectors/packet-nsip.c b/epan/dissectors/packet-nsip.c index 697e0cb9c6..e08b819e7a 100644 --- a/epan/dissectors/packet-nsip.c +++ b/epan/dissectors/packet-nsip.c @@ -383,7 +383,6 @@ decode_iei_bvci(nsip_ie_t *ie, build_info_t *bi, int ie_start_offset) { static proto_item * decode_ip_element(nsip_ip_element_info_t *element, build_info_t *bi, proto_tree * element_tree) { guint16 udp_port; - guint32 ip4_addr; struct e_in6_addr ip6_addr; proto_item *tf; proto_tree *field_tree; @@ -395,12 +394,11 @@ decode_ip_element(nsip_ip_element_info_t *element, build_info_t *bi, proto_tree /* IP address */ switch (element->version) { case NSIP_IP_VERSION_4: - ip4_addr = tvb_get_ipv4(bi->tvb, bi->offset); proto_tree_add_item(field_tree, hf_nsip_ip_address_ipv4, bi->tvb, bi->offset, element->address_length, ENC_BIG_ENDIAN); proto_item_append_text(tf, ": IP address: %s", - ip_to_str((guint8 *)&ip4_addr)); + tvb_ip_to_str(bi->tvb, bi->offset)); break; case NSIP_IP_VERSION_6: diff --git a/epan/dissectors/packet-nt-tpcp.c b/epan/dissectors/packet-nt-tpcp.c index 9fbbd1a293..a3b9af761c 100644 --- a/epan/dissectors/packet-nt-tpcp.c +++ b/epan/dissectors/packet-nt-tpcp.c @@ -106,7 +106,6 @@ dissect_tpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ proto_item *ti; guint8 version, type; guint16 id, cport; - guint32 caddr, saddr; static const int * tpcp_flags[] = { &hf_tpcp_flags_tcp, @@ -144,10 +143,7 @@ dissect_tpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ proto_tree_add_uint_format_value(tpcp_tree, hf_tpcp_cport, tvb, 6, 2, cport, "%s", ep_udp_port_to_display(cport)); - caddr = tvb_get_ntohl(tvb, 8); proto_tree_add_item(tpcp_tree, hf_tpcp_caddr, tvb, 8, 4, ENC_BIG_ENDIAN); - - saddr = tvb_get_ntohl(tvb, 12); proto_tree_add_item(tpcp_tree, hf_tpcp_saddr, tvb, 12, 4, ENC_BIG_ENDIAN); if (version == TPCP_VER_2) { @@ -160,8 +156,8 @@ dissect_tpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ val_to_str_const(type, type_vals, "Unknown"), id, ep_udp_port_to_display(cport), - ip_to_str((guint8 *)&caddr), - ip_to_str((guint8 *)&saddr)); + tvb_ip_to_str(tvb, 8), + tvb_ip_to_str(tvb, 12)); if (version == TPCP_VER_1) return TPCP_VER_1_LENGTH; diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c index 157972242a..954b6800be 100644 --- a/epan/dissectors/packet-ospf.c +++ b/epan/dissectors/packet-ospf.c @@ -2247,7 +2247,7 @@ static void dissect_ospf_lsa_grace_tlv (tvbuff_t *tvb, int offset, proto_tree_add_item(tlv_tree, hf_ospf_v2_grace_ip, tvb, offset + 4, tlv_length, ENC_BIG_ENDIAN); proto_item_set_text(tree_item, "Restart IP: %s (%s)", - get_hostname(restart_ip), ip_to_str((guint8 *)&restart_ip)); + get_hostname(restart_ip), tvb_ip_to_str(tvb, offset + 4)); break; default: proto_item_set_text(tree_item, "Unknown grace-LSA TLV"); diff --git a/epan/dissectors/packet-pcep.c b/epan/dissectors/packet-pcep.c index f6dff8dbf0..5b1f418562 100644 --- a/epan/dissectors/packet-pcep.c +++ b/epan/dissectors/packet-pcep.c @@ -1221,7 +1221,6 @@ dissect_subobj_unnumb_interfaceID(proto_tree *pcep_subobj_tree, packet_info *pin { proto_tree *pcep_subobj_unnumb_interfaceID; proto_item *ti; - guint32 router_ID; guint32 interface_ID; ti = proto_tree_add_item(pcep_subobj_tree, hf_PCEPF_SUBOBJ_UNNUM_INTERFACEID, tvb, offset, length, ENC_NA); @@ -1233,9 +1232,8 @@ dissect_subobj_unnumb_interfaceID(proto_tree *pcep_subobj_tree, packet_info *pin return; } - router_ID = tvb_get_ipv4(tvb, offset+4); interface_ID = tvb_get_ntohl(tvb, offset+8); - proto_item_append_text(ti, ": %s:%u", ip_to_str ((guint8 *) &router_ID), + proto_item_append_text(ti, ": %s:%u", tvb_ip_to_str (tvb, offset+4), interface_ID); switch (obj_class) { diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c index 6d78b8928d..c1a12fbf5c 100644 --- a/epan/dissectors/packet-radius.c +++ b/epan/dissectors/packet-radius.c @@ -366,7 +366,7 @@ static const gchar *dissect_framed_ip_address(proto_tree* tree, tvbuff_t* tvb, p proto_tree_add_ipv4_format_value(tree, hf_radius_framed_ip_address, tvb, 0, len, ip, "%s", str); } else { - str = ip_to_str((guint8 *)&ip); + str = tvb_ip_to_str(tvb, 0); proto_tree_add_ipv4_format_value(tree, hf_radius_framed_ip_address, tvb, 0, len, ip, "%s (%s)", get_hostname(ip), str); @@ -397,7 +397,7 @@ static const gchar *dissect_login_ip_host(proto_tree* tree, tvbuff_t* tvb, packe proto_tree_add_ipv4_format_value(tree, hf_radius_login_ip_host, tvb, 0, len, ip, "%s", str); } else { - str = ip_to_str((guint8 *)&ip); + str = tvb_ip_to_str(tvb, 0); proto_tree_add_ipv4_format_value(tree, hf_radius_login_ip_host, tvb, 0, len, ip, "%s (%s)", get_hostname(ip), str); @@ -447,7 +447,7 @@ static const gchar *dissect_ascend_data_filter(proto_tree* tree, tvbuff_t* tvb, srcportq=tvb_get_guint8(tvb, 20); if (srcip || srclen || srcportq) { - wmem_strbuf_append_printf(filterstr, " srcip %s/%d", ip_to_str((guint8 *) &srcip), srclen); + wmem_strbuf_append_printf(filterstr, " srcip %s/%d", tvb_ip_to_str(tvb, 4), srclen); if (srcportq) wmem_strbuf_append_printf(filterstr, " srcport %s %d", val_to_str(srcportq, ascenddf_portq, "%u"), srcport); @@ -459,7 +459,7 @@ static const gchar *dissect_ascend_data_filter(proto_tree* tree, tvbuff_t* tvb, dstportq=tvb_get_guint8(tvb, 21); if (dstip || dstlen || dstportq) { - wmem_strbuf_append_printf(filterstr, " dstip %s/%d", ip_to_str((guint8 *) &dstip), dstlen); + wmem_strbuf_append_printf(filterstr, " dstip %s/%d", tvb_ip_to_str(tvb, 8), dstlen); if (dstportq) wmem_strbuf_append_printf(filterstr, " dstport %s %d", val_to_str(dstportq, ascenddf_portq, "%u"), dstport); diff --git a/epan/dissectors/packet-sflow.c b/epan/dissectors/packet-sflow.c index 4c89a65704..7fe4fba112 100644 --- a/epan/dissectors/packet-sflow.c +++ b/epan/dissectors/packet-sflow.c @@ -321,13 +321,6 @@ struct sflow_address_type { int hf_addr_v6; }; -struct sflow_address_details { - int addr_type; /* ADDR_TYPE_IPV4 | ADDR_TYPE_IPV6 */ - union { - guint8 v4[4]; - guint8 v6[16]; - } agent_address; -}; /* Initialize the protocol and registered fields */ static int proto_sflow = -1; @@ -725,7 +718,7 @@ static gint dissect_sflow_245_address_type(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, struct sflow_address_type *hf_type, - struct sflow_address_details *addr_detail) { + address *addr) { guint32 addr_type; int len; @@ -755,14 +748,13 @@ dissect_sflow_245_address_type(tvbuff_t *tvb, packet_info *pinfo, offset - 4, 4, "Unknown address type (%u)", addr_type); } - if (addr_detail) { - addr_detail->addr_type = addr_type; + if (addr) { switch (len) { case 4: - tvb_memcpy(tvb, addr_detail->agent_address.v4, offset, len); + TVB_SET_ADDRESS(addr, AT_IPv4, tvb, offset, len); break; case 16: - tvb_memcpy(tvb, addr_detail->agent_address.v6, offset, len); + TVB_SET_ADDRESS(addr, AT_IPv6, tvb, offset, len); break; } } @@ -2250,7 +2242,8 @@ dissect_sflow_245(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat proto_item *ti; proto_tree *sflow_245_tree; guint32 version, sub_agent_id, seqnum; - struct sflow_address_details addr_details; + address addr_details; + int sflow_addr_type; struct sflow_address_type addr_type; guint32 numsamples; @@ -2273,11 +2266,16 @@ dissect_sflow_245(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat /* Unknown version; assume it's not an sFlow packet. */ return 0; } - addr_details.addr_type = tvb_get_ntohl(tvb, offset + 4); - switch (addr_details.addr_type) { + sflow_addr_type = tvb_get_ntohl(tvb, offset + 4); + switch (sflow_addr_type) { case ADDR_TYPE_UNKNOWN: + addr_details.type = AT_NONE; + break; case ADDR_TYPE_IPV4: + addr_details.type = AT_IPv4; + break; case ADDR_TYPE_IPV6: + addr_details.type = AT_IPv6; break; default: @@ -2302,15 +2300,12 @@ dissect_sflow_245(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat offset = dissect_sflow_245_address_type(tvb, pinfo, sflow_245_tree, offset, &addr_type, &addr_details); - switch (addr_details.addr_type) { + switch (sflow_addr_type) { case ADDR_TYPE_UNKNOWN: break; case ADDR_TYPE_IPV4: - col_append_fstr(pinfo->cinfo, COL_INFO, ", agent %s", ip_to_str(addr_details.agent_address.v4)); - break; case ADDR_TYPE_IPV6: - col_append_fstr(pinfo->cinfo, COL_INFO, ", agent %s", - ip6_to_str((struct e_in6_addr *) addr_details.agent_address.v6)); + col_append_fstr(pinfo->cinfo, COL_INFO, ", agent %s", address_to_str(wmem_packet_scope(), &addr_details)); break; } diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c index 09f1b2a30f..3a98e40766 100644 --- a/epan/dissectors/packet-smb.c +++ b/epan/dissectors/packet-smb.c @@ -987,9 +987,9 @@ const gchar *tree_ip_str(packet_info *pinfo, guint16 cmd) { if ( cmd == SMB_COM_READ_ANDX || cmd == SMB_COM_READ || cmd == SMB2_COM_READ) { - buf = ip_to_str((const guint8 *)pinfo->src.data); + buf = address_to_str(wmem_packet_scope(), &pinfo->src); } else { - buf = ip_to_str((const guint8 *)pinfo->dst.data); + buf = address_to_str(wmem_packet_scope(), &pinfo->dst); } } else { if ( cmd == SMB_COM_READ_ANDX || diff --git a/epan/dissectors/packet-stun.c b/epan/dissectors/packet-stun.c index 406f7cbe91..92359779e5 100644 --- a/epan/dissectors/packet-stun.c +++ b/epan/dissectors/packet-stun.c @@ -1001,10 +1001,12 @@ dissect_stun_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboole { const gchar *ipstr; + address addr; guint32 ip; guint16 port; ip = tvb_get_ipv4(tvb, offset+4) ^ g_htonl(magic_cookie_first_word); - ipstr = ip_to_str((guint8*)&ip); + SET_ADDRESS(&addr, AT_IPv4, 4, &ip); + ipstr = address_to_str(wmem_packet_scope(), &addr); port = tvb_get_ntohs(tvb, offset+2) ^ (magic_cookie_first_word >> 16); proto_item_append_text(att_tree, ": %s:%d", ipstr, port); col_append_fstr( diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index 115ac78b9e..3bbbe190b5 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -643,8 +643,8 @@ tcp_build_color_filter(packet_info *pinfo) if( pinfo->net_src.type == AT_IPv4 && pinfo->net_dst.type == AT_IPv4 ) { /* TCP over IPv4 */ return g_strdup_printf("(ip.addr eq %s and ip.addr eq %s) and (tcp.port eq %d and tcp.port eq %d)", - ip_to_str( (const guint8 *)pinfo->net_src.data), - ip_to_str( (const guint8 *)pinfo->net_dst.data), + address_to_str(wmem_packet_scope(), &pinfo->net_src), + address_to_str(wmem_packet_scope(), &pinfo->net_dst), pinfo->srcport, pinfo->destport ); } @@ -3505,9 +3505,9 @@ rvbd_probe_decode_version_type(const guint8 vt, guint8 *ver, guint8 *type) } static void -rvbd_probe_resp_add_info(proto_item *pitem, packet_info *pinfo, guint32 ip, guint16 port) +rvbd_probe_resp_add_info(proto_item *pitem, packet_info *pinfo, tvbuff_t *tvb, int ip_offset, guint16 port) { - proto_item_append_text(pitem, ", Server Steelhead: %s:%u", ip_to_str((guint8 *)&ip), port); + proto_item_append_text(pitem, ", Server Steelhead: %s:%u", tvb_ip_to_str(tvb, ip_offset), port); col_prepend_fstr(pinfo->cinfo, COL_INFO, "SA+, "); } @@ -3568,7 +3568,7 @@ dissect_tcpopt_rvbd_probe(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, int offset, offset + PROBE_V1_APPLI_VERSION_OFFSET, 2, ENC_BIG_ENDIAN); - proto_item_append_text(pitem, ", CSH IP: %s", ip_to_str((guint8 *)&ip)); + proto_item_append_text(pitem, ", CSH IP: %s", tvb_ip_to_str(tvb, offset + PROBE_V1_PROBER_OFFSET)); { /* Small look-ahead hack to distinguish S+ from S+* */ @@ -3589,7 +3589,6 @@ dissect_tcpopt_rvbd_probe(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, int offset, break; case PROBE_RESPONSE: - ip = tvb_get_ipv4(tvb, offset + PROBE_V1_PROXY_ADDR_OFFSET); proto_tree_add_item(field_tree, hf_tcp_option_rvbd_probe_proxy, tvb, offset + PROBE_V1_PROXY_ADDR_OFFSET, 4, ENC_BIG_ENDIAN); @@ -3597,7 +3596,7 @@ dissect_tcpopt_rvbd_probe(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, int offset, proto_tree_add_item(field_tree, hf_tcp_option_rvbd_probe_proxy_port, tvb, offset + PROBE_V1_PROXY_PORT_OFFSET, 2, ENC_BIG_ENDIAN); - rvbd_probe_resp_add_info(pitem, pinfo, ip, port); + rvbd_probe_resp_add_info(pitem, pinfo, tvb, offset + PROBE_V1_PROXY_ADDR_OFFSET, port); break; case PROBE_RESPONSE_SH: @@ -3606,7 +3605,6 @@ dissect_tcpopt_rvbd_probe(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, int offset, offset + PROBE_V1_SH_CLIENT_ADDR_OFFSET, 4, ENC_BIG_ENDIAN); - ip = tvb_get_ipv4(tvb, offset + PROBE_V1_SH_PROXY_ADDR_OFFSET); proto_tree_add_item(field_tree, hf_tcp_option_rvbd_probe_proxy, tvb, offset + PROBE_V1_SH_PROXY_ADDR_OFFSET, 4, ENC_BIG_ENDIAN); @@ -3614,7 +3612,7 @@ dissect_tcpopt_rvbd_probe(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, int offset, proto_tree_add_item(field_tree, hf_tcp_option_rvbd_probe_proxy_port, tvb, offset + PROBE_V1_SH_PROXY_PORT_OFFSET, 2, ENC_BIG_ENDIAN); - rvbd_probe_resp_add_info(pitem, pinfo, ip, port); + rvbd_probe_resp_add_info(pitem, pinfo, tvb, offset + PROBE_V1_SH_PROXY_ADDR_OFFSET, port); break; } } @@ -3786,8 +3784,8 @@ dissect_tcpopt_rvbd_trpy(const ip_tcp_opt *optp _U_, tvbuff_t *tvb, tvb, offset + TRPY_DST_PORT_OFFSET, 2, ENC_BIG_ENDIAN); proto_item_append_text(pitem, "%s:%u -> %s:%u", - ip_to_str((guint8 *)&src), sport, - ip_to_str((guint8 *)&dst), dport); + tvb_ip_to_str(tvb, offset + TRPY_SRC_ADDR_OFFSET), sport, + tvb_ip_to_str(tvb, offset + TRPY_DST_ADDR_OFFSET), dport); /* Client port only set on SYN: optlen == 18 */ if ((flags & RVBD_FLAGS_TRPY_OOB) && (optlen > TCPOLEN_RVBD_TRPY_MIN)) diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c index e6e81561f9..c606cafaf4 100644 --- a/epan/dissectors/packet-udp.c +++ b/epan/dissectors/packet-udp.c @@ -389,8 +389,8 @@ udp_build_color_filter(packet_info *pinfo) if( pinfo->net_src.type == AT_IPv4 && pinfo->net_dst.type == AT_IPv4 ) { /* UDP over IPv4 */ return g_strdup_printf("(ip.addr eq %s and ip.addr eq %s) and (udp.port eq %d and udp.port eq %d)", - ip_to_str( (const guint8 *)pinfo->net_src.data), - ip_to_str( (const guint8 *)pinfo->net_dst.data), + address_to_str(wmem_packet_scope(), &pinfo->net_src), + address_to_str(wmem_packet_scope(), &pinfo->net_dst), pinfo->srcport, pinfo->destport ); } diff --git a/epan/dissectors/packet-vxi11.c b/epan/dissectors/packet-vxi11.c index 4597a74165..1a5f867c85 100644 --- a/epan/dissectors/packet-vxi11.c +++ b/epan/dissectors/packet-vxi11.c @@ -606,11 +606,10 @@ dissect_device_remote_func(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) { - guint32 addr, port; + guint32 port; const gchar *addrstr; - addr = tvb_get_ipv4(tvb, offset); - addrstr = ip_to_str((guint8 *)&addr); + addrstr = tvb_ip_to_str(tvb, offset); offset = dissect_rpc_uint32(tvb, tree, hf_vxi11_core_host_addr, offset); port = tvb_get_ntohl(tvb, offset); diff --git a/epan/dissectors/packet-wccp.c b/epan/dissectors/packet-wccp.c index 6b19bd42bf..9c37e72b3a 100644 --- a/epan/dissectors/packet-wccp.c +++ b/epan/dissectors/packet-wccp.c @@ -752,7 +752,7 @@ dissect_wccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_ hf_cache_ip, tvb, offset, 4, ipaddr, "Web Cache %d IP Address: %s", i, - ip_to_str((guint8 *)&ipaddr)); + tvb_ip_to_str(tvb, offset)); offset += 4; } for (i = 0; i < 256; i += 4) { diff --git a/epan/dissectors/packet-winsrepl.c b/epan/dissectors/packet-winsrepl.c index 291943de32..d4ce7af214 100644 --- a/epan/dissectors/packet-winsrepl.c +++ b/epan/dissectors/packet-winsrepl.c @@ -323,7 +323,7 @@ dissect_winsrepl_wins_ip(tvbuff_t *winsrepl_tvb, _U_ packet_info *pinfo, /* IP */ *addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset); proto_tree_add_ipv4(ip_tree, hf_winsrepl_ip_ip, winsrepl_tvb, winsrepl_offset, 4, *addr); - proto_item_append_text(ip_item, ": %s", ip_to_str((guint8 *)addr)); + proto_item_append_text(ip_item, ": %s", tvb_ip_to_str(winsrepl_tvb, winsrepl_offset)); winsrepl_offset += 4; return winsrepl_offset; @@ -340,6 +340,8 @@ dissect_winsrepl_wins_address_list(tvbuff_t *winsrepl_tvb, packet_info *pinfo, guint32 num_ips; guint32 ip; guint32 i; + address addr; + gchar* addr_str; addr_list_tree = proto_tree_add_subtree(winsrepl_tree, winsrepl_tvb, winsrepl_offset, -1, ett_winsrepl_addr_list, &addr_list_item, "WINS Address List"); @@ -353,12 +355,14 @@ dissect_winsrepl_wins_address_list(tvbuff_t *winsrepl_tvb, packet_info *pinfo, winsrepl_offset = dissect_winsrepl_wins_ip(winsrepl_tvb, pinfo, winsrepl_offset, addr_list_tree, &ip, addr_list_tree, i); + SET_ADDRESS(&addr, AT_IPv4, 4, &ip); + addr_str = address_to_str(wmem_packet_scope(), &addr); if (i == 0) { - proto_item_append_text(parent_item, ": %s", ip_to_str((guint8 *)&ip)); - proto_item_append_text(addr_list_item, ": %s", ip_to_str((guint8 *)&ip)); + proto_item_append_text(parent_item, ": %s", addr_str); + proto_item_append_text(addr_list_item, ": %s", addr_str); } else { - proto_item_append_text(parent_item, ", %s", ip_to_str((guint8 *)&ip)); - proto_item_append_text(addr_list_item, ", %s", ip_to_str((guint8 *)&ip)); + proto_item_append_text(parent_item, ", %s", addr_str); + proto_item_append_text(addr_list_item, ", %s", addr_str); } } @@ -380,7 +384,6 @@ dissect_winsrepl_wins_name(tvbuff_t *winsrepl_tvb, packet_info *pinfo, char name_str[(NETBIOS_NAME_LEN - 1)*4 + 1]; int name_type; guint32 flags; - guint32 addr; static const int * name_flags[] = { &hf_winsrepl_name_flags_rectype, &hf_winsrepl_name_flags_recstate, @@ -452,9 +455,8 @@ dissect_winsrepl_wins_name(tvbuff_t *winsrepl_tvb, packet_info *pinfo, case WREPL_NAME_TYPE_UNIQUE: case WREPL_NAME_TYPE_NORMAL_GROUP: /* Single address */ - addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset); - proto_tree_add_ipv4(name_tree, hf_winsrepl_ip_ip, winsrepl_tvb, winsrepl_offset, 4, addr); - proto_item_append_text(name_item, ": %s", ip_to_str((guint8 *)&addr)); + proto_tree_add_item(name_tree, hf_winsrepl_ip_ip, winsrepl_tvb, winsrepl_offset, 4, ENC_BIG_ENDIAN); + proto_item_append_text(name_item, ": %s", tvb_ip_to_str(winsrepl_tvb, winsrepl_offset)); winsrepl_offset += 4; break; diff --git a/epan/dissectors/packet-xmcp.c b/epan/dissectors/packet-xmcp.c index 2c737723ff..66b0f1dc8d 100644 --- a/epan/dissectors/packet-xmcp.c +++ b/epan/dissectors/packet-xmcp.c @@ -637,11 +637,9 @@ decode_xmcp_attr_value (proto_tree *attr_tree, guint16 attr_type, if (attr_length != 8) { expert_add_info_format(pinfo, attr_tree, &ei_xmcp_attr_length_bad, "Malformed IPv4 address"); } else { - guint32 ip; proto_tree_add_item(attr_tree, xmcp_attr_servtrans_ipv4, tvb, (offset+4), 4, ENC_BIG_ENDIAN); - ip = tvb_get_ipv4(tvb, (offset+4)); - proto_item_append_text(attr_tree, ": %s:%u", ip_to_str((guint8 *)&ip), + proto_item_append_text(attr_tree, ": %s:%u", tvb_ip_to_str(tvb, offset+4), tvb_get_ntohs(tvb, (offset+2))); } break; diff --git a/epan/follow.c b/epan/follow.c index cd58b71116..f48edf4342 100644 --- a/epan/follow.c +++ b/epan/follow.c @@ -135,8 +135,8 @@ build_follow_conv_filter( packet_info *pi ) { /* UDP over IPv4 */ buf = g_strdup_printf( "(ip.addr eq %s and ip.addr eq %s) and (udp.port eq %d and udp.port eq %d)", - ip_to_str((const guint8 *)pi->net_src.data), - ip_to_str((const guint8 *)pi->net_dst.data), + address_to_str(pi->pool, &pi->net_src), + address_to_str(pi->pool, &pi->net_dst), pi->srcport, pi->destport ); len = 4; is_ipv6 = FALSE; diff --git a/epan/proto.c b/epan/proto.c index 9e17ea7330..6f3bc6aae7 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -4352,9 +4352,9 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence, case FT_IPv4: ipv4 = (ipv4_addr *)fvalue_get(&finfo->value); n_addr = ipv4_get_net_order_addr(ipv4); - offset_r += protoo_strlcpy(result+offset_r, - ip_to_str((guint8 *)&n_addr), - size-offset_r); + SET_ADDRESS (&addr, AT_IPv4, 4, &n_addr); + address_to_str_buf(&addr, result+offset_r, size-offset_r); + offset_r = (int)strlen(result); break; case FT_IPv6: @@ -6063,9 +6063,14 @@ proto_item_fill_label(field_info *fi, gchar *label_str) case FT_IPv4: ipv4 = (ipv4_addr *)fvalue_get(&fi->value); n_addr = ipv4_get_net_order_addr(ipv4); + + addr.type = AT_IPv4; + addr.len = 4; + addr.data = &n_addr; + label_fill_descr(label_str, 0, hfinfo, get_hostname(n_addr), - ip_to_str((guint8*)&n_addr)); + ep_address_to_str(&addr )); break; case FT_IPv6: diff --git a/epan/to_str.h b/epan/to_str.h index a4582826c1..f40b0d3e88 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -54,7 +54,6 @@ WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr WS_DLL_PUBLIC gchar* ep_address_to_str(const address *); WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len); WS_DLL_PUBLIC const gchar* tvb_ether_to_str(tvbuff_t *tvb, const gint offset); -WS_DLL_PUBLIC const gchar* ip_to_str(const guint8 *); WS_DLL_PUBLIC const gchar* tvb_ip_to_str(tvbuff_t *tvb, const gint offset); void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len); extern gchar* fcwwn_to_str (const guint8 *); -- cgit v1.2.3