aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-09-13 00:50:43 +0000
committerGuy Harris <guy@alum.mit.edu>2005-09-13 00:50:43 +0000
commit973920e91da3dd479611c3a2e2d0b344bfae5a32 (patch)
tree24a54bbab51a5df486ba5b70c24385d471e92549
parent9e5a98abae465ef7ab5618738813574e9400e239 (diff)
Convert some more "tvb_memcpy()"s fetching IPv4 and IPv6 addresses to
calls to "tvb_get_ipv4()" and "tvb_get_ipv6()". Fix a call in the BGP dissector to properly fetch an IEEE floating-point number. Update some I-D info. svn path=/trunk/; revision=15774
-rw-r--r--epan/dissectors/packet-bgp.c67
-rw-r--r--epan/dissectors/packet-bgp.h4
-rw-r--r--epan/dissectors/packet-bootp.c15
-rw-r--r--epan/dissectors/packet-icmpv6.c11
-rw-r--r--epan/dissectors/packet-radius.c13
5 files changed, 56 insertions, 54 deletions
diff --git a/epan/dissectors/packet-bgp.c b/epan/dissectors/packet-bgp.c
index 2b7bd4fbf6..36315b8500 100644
--- a/epan/dissectors/packet-bgp.c
+++ b/epan/dissectors/packet-bgp.c
@@ -510,7 +510,7 @@ static int
mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf, int buf_len)
{
int length; /* length of the address in byte */
- guint8 ip4addr[4],ip4addr2[4]; /* IPv4 address */
+ guint32 ip4addr,ip4addr2; /* IPv4 address */
guint16 rd_type; /* Route Distinguisher type */
struct e_in6_addr ip6addr; /* IPv6 address */
char *strptr;
@@ -528,8 +528,8 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf,
case SAFNUM_MPLS_LABEL:
case SAFNUM_TUNNEL:
length = 4 ;
- tvb_memcpy(tvb, ip4addr, offset, sizeof(ip4addr));
- strptr += g_snprintf(strptr, buf_len-(strptr-buf), "%s", ip_to_str(ip4addr));
+ ip4addr = tvb_get_ipv4(tvb, offset);
+ strptr += g_snprintf(strptr, buf_len-(strptr-buf), "%s", ip_to_str((guint8 *)&ip4addr));
break;
case SAFNUM_LAB_VPNUNICAST:
case SAFNUM_LAB_VPNMULCAST:
@@ -538,20 +538,20 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf,
switch (rd_type) {
case FORMAT_AS2_LOC:
length = 8 + sizeof(ip4addr);
- tvb_memcpy(tvb, ip4addr, offset + 8, sizeof(ip4addr)); /* Next Hop */
+ ip4addr = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
strptr += g_snprintf(strptr, buf_len-(strptr-buf), "Empty Label Stack RD=%u:%u IPv4=%s",
tvb_get_ntohs(tvb, offset + 2),
tvb_get_ntohl(tvb, offset + 4),
- ip_to_str(ip4addr));
+ ip_to_str((guint8 *)&ip4addr));
break;
case FORMAT_IP_LOC:
length = 8 + sizeof(ip4addr);
- tvb_memcpy(tvb, ip4addr, offset + 2, sizeof(ip4addr)); /* IP part of the RD */
- tvb_memcpy(tvb, ip4addr2, offset + 8, sizeof(ip4addr)); /* Next Hop */
+ ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
+ ip4addr2 = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
strptr += g_snprintf(strptr, buf_len-(strptr-buf), "Empty Label Stack RD=%s:%u IPv4=%s",
- ip_to_str(ip4addr),
+ ip_to_str((guint8 *)&ip4addr),
tvb_get_ntohs(tvb, offset + 6),
- ip_to_str(ip4addr2));
+ ip_to_str((guint8 *)&ip4addr2));
break ;
default:
length = 0 ;
@@ -591,10 +591,10 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf,
break;
case FORMAT_IP_LOC:
length = 8 + 16;
- tvb_memcpy(tvb, ip4addr, offset + 2, sizeof(ip4addr)); /* IP part of the RD */
+ ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */
strptr += g_snprintf(strptr, buf_len-(strptr-buf), "Empty Label Stack RD=%s:%u IPv6=%s",
- ip_to_str(ip4addr),
+ ip_to_str((guint8 *)&ip4addr),
tvb_get_ntohs(tvb, offset + 6),
ip6_to_str(&ip6addr));
break ;
@@ -616,9 +616,9 @@ mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf,
case SAFNUM_LAB_VPNMULCAST:
case SAFNUM_LAB_VPNUNIMULC:
length = 4; /* the next-hop is simply an ipv4 addr */
- tvb_memcpy(tvb, ip4addr, offset + 0, 4);
+ ip4addr = tvb_get_ipv4(tvb, offset + 0);
strptr += g_snprintf(strptr, buf_len-(strptr-buf), "IPv4=%s",
- ip_to_str(ip4addr));
+ ip_to_str((guint8 *)&ip4addr));
break;
default:
length = 0 ;
@@ -1448,11 +1448,12 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
static GString *communities_gstr = NULL; /* COMMUNITIES GString */
static GString *cluster_list_gstr = NULL; /* CLUSTER_LIST GString */
char *junk_gbuf, *junk_gbuf_ptr; /* tmp */
- guint8 ipaddr[4]; /* IPv4 address */
+ guint32 ipaddr; /* IPv4 address */
guint32 aggregator_as;
guint16 ssa_type; /* SSA T + Type */
guint16 ssa_len; /* SSA TLV Length */
guint8 ssa_v3_len; /* SSA L2TPv3 Cookie Length */
+ gfloat linkband; /* Link bandwidth */
hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
o = BGP_HEADER_SIZE;
@@ -1617,12 +1618,12 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
case BGPTYPE_NEXT_HOP:
if (tlen != 4)
goto default_attribute_top;
- tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ip_to_str(ipaddr), tlen + aoff, (tlen + aoff == 1)
- ? "byte" : "bytes");
+ ip_to_str((guint8 *)&ipaddr),
+ tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_MULTI_EXIT_DISC:
if (tlen != 4)
@@ -1657,14 +1658,14 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
if (bgpa.bgpa_type == BGPTYPE_NEW_AGGREGATOR && tlen != 8)
goto default_attribute_top;
asn_len = tlen - 4;
- tvb_memcpy(tvb, ipaddr, o + i + aoff + asn_len, 4);
+ ipaddr = tvb_get_ipv4(tvb, o + i + aoff + asn_len);
ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
"%s: AS: %u origin: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
(asn_len == 2) ? tvb_get_ntohs(tvb, o + i + aoff) :
tvb_get_ntohl(tvb, o + i + aoff),
- ip_to_str(ipaddr), tlen + aoff,
- (tlen + aoff == 1) ? "byte" : "bytes");
+ ip_to_str((guint8 *)&ipaddr),
+ tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_COMMUNITIES:
if (tlen % 4 != 0)
@@ -1711,12 +1712,12 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
case BGPTYPE_ORIGINATOR_ID:
if (tlen != 4)
goto default_attribute_top;
- tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ip_to_str(ipaddr), tlen + aoff, (tlen + aoff == 1)
- ? "byte" : "bytes");
+ ip_to_str((guint8 *)&ipaddr),
+ tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_CLUSTER_LIST:
if (tlen % 4 != 0)
@@ -1736,9 +1737,9 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
g_string_truncate(cluster_list_gstr, 0);
/* snarf each cluster list */
- tvb_memcpy(tvb, ipaddr, q, 4);
while (q < end) {
- g_string_sprintfa(cluster_list_gstr, "%s ", ip_to_str(ipaddr));
+ ipaddr = tvb_get_ipv4(tvb, q);
+ g_string_sprintfa(cluster_list_gstr, "%s ", ip_to_str((guint8 *)&ipaddr));
q += 4;
}
/* cleanup end of string */
@@ -2232,20 +2233,20 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
break ;
case BGP_EXT_COM_RT_1:
case BGP_EXT_COM_RO_1:
- tvb_memcpy(tvb,ipaddr,q+2,4);
+ ipaddr = tvb_get_ipv4(tvb,q+2);
junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %s%s%u",
- ip_to_str(ipaddr),":",tvb_get_ntohs(tvb,q+6));
+ ip_to_str((guint8 *)&ipaddr),":",tvb_get_ntohs(tvb,q+6));
proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
break;
case BGP_EXT_COM_VPN_ORIGIN:
case BGP_EXT_COM_OSPF_RID:
- tvb_memcpy(tvb,ipaddr,q+2,4);
- junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %s", ip_to_str(ipaddr));
+ ipaddr = tvb_get_ipv4(tvb,q+2);
+ junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %s", ip_to_str((guint8 *)&ipaddr));
proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
break;
case BGP_EXT_COM_OSPF_RTYPE:
- tvb_memcpy(tvb,ipaddr,q+2,4);
- junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": Area: %s, Type: %s", ip_to_str(ipaddr),
+ ipaddr = tvb_get_ipv4(tvb,q+2);
+ junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": Area: %s, Type: %s", ip_to_str((guint8 *)&ipaddr),
val_to_str(tvb_get_guint8(tvb,q+6),bgpext_ospf_rtype,"Unknown"));
/* print OSPF Metric type if selected */
/* always print E2 even if not external route -- receiving router should ignore */
@@ -2259,9 +2260,9 @@ dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
break;
case BGP_EXT_COM_LINKBAND:
- tvb_memcpy(tvb,ipaddr,q+2,4); /* need to check on IEEE format on all platforms */
+ linkband = tvb_get_ntohieee_float(tvb,q+2);
junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %.3f Mbps",
- ((double)*ipaddr)*8/1000000);
+ linkband*8/1000000);
proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
break;
case BGP_EXT_COM_L2INFO:
diff --git a/epan/dissectors/packet-bgp.h b/epan/dissectors/packet-bgp.h
index 6084f939bb..4c9a037b38 100644
--- a/epan/dissectors/packet-bgp.h
+++ b/epan/dissectors/packet-bgp.h
@@ -165,7 +165,7 @@ struct bgp_attr {
#define BGPTYPE_SAFI_SPECIFIC_ATTR 19 /* draft-kapoor-nalawade-idr-bgp-ssa-00.txt */
/* Extended community type */
- /* draft-ramachandra-bgp-ext-communities */
+ /* draft-ietf-idr-bgp-ext-communities */
#define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
#define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
#define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AS(2bytes):AN(4bytes) */
@@ -173,7 +173,7 @@ struct bgp_attr {
#define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
#define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AS(2bytes):AN(4bytes) */
#define BGP_EXT_COM_LINKBAND 0x0004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
- /* rfc2547 bgp-mpls-vpns */
+ /* -2 version of the draft */
#define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domin ID / VPN of Origin */
/* draft-rosen-vpns-ospf-bgp-mpls */
#define BGP_EXT_COM_OSPF_RTYPE 0X8000 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c
index a839da93e9..c2ed87f28e 100644
--- a/epan/dissectors/packet-bootp.c
+++ b/epan/dissectors/packet-bootp.c
@@ -2488,7 +2488,8 @@ dissect_packetcable_ietf_ccc(proto_tree *v_tree, tvbuff_t *tvb, int optoff,
int optend, int revision)
{
int suboptoff = optoff;
- guint8 subopt, subopt_len, ipv4_addr[4];
+ guint8 subopt, subopt_len;
+ guint32 ipv4_addr;
guint8 prov_type, fetch_tgt, timer_val;
guint16 sec_tcm;
proto_tree *pkt_s_tree;
@@ -2520,9 +2521,9 @@ dissect_packetcable_ietf_ccc(proto_tree *v_tree, tvbuff_t *tvb, int optoff,
"no room left in option for suboption value");
return (optend);
}
- tvb_memcpy(tvb, ipv4_addr, suboptoff, 4);
- proto_item_append_text(vti, "%u.%u.%u.%u (%u byte%s%s)",
- ipv4_addr[0], ipv4_addr[1], ipv4_addr[2], ipv4_addr[3],
+ ipv4_addr = tvb_get_ipv4(tvb, suboptoff);
+ proto_item_append_text(vti, "%s (%u byte%s%s)",
+ ip_to_str((guint8 *)&ipv4_addr),
subopt_len,
plurality(subopt_len, "", "s"),
subopt_len != 4 ? " [Invalid]" : "");
@@ -2551,9 +2552,9 @@ dissect_packetcable_ietf_ccc(proto_tree *v_tree, tvbuff_t *tvb, int optoff,
"no room left in option for suboption value");
return (optend);
}
- tvb_memcpy(tvb, ipv4_addr, suboptoff, 4);
- proto_item_append_text(vti, "%u.%u.%u.%u (%u byte%s%s)",
- ipv4_addr[0], ipv4_addr[1], ipv4_addr[2], ipv4_addr[3],
+ ipv4_addr = tvb_get_ipv4(tvb, suboptoff);
+ proto_item_append_text(vti, "%s (%u byte%s%s)",
+ ip_to_str((guint8 *)&ipv4_addr),
subopt_len,
plurality(subopt_len, "", "s"),
subopt_len != 5 ? " [Invalid]" : "");
diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c
index b68a747dcb..a3fb9af4c7 100644
--- a/epan/dissectors/packet-icmpv6.c
+++ b/epan/dissectors/packet-icmpv6.c
@@ -513,7 +513,7 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
int i, n, l, p;
guint16 flags;
char dname[MAXDNAME];
- guint8 ipaddr[4];
+ guint32 ipaddr;
ni = &icmp6_nodeinfo;
tvb_memcpy(tvb, (guint8 *)ni, offset, sizeof *ni);
@@ -643,9 +643,9 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
field_tree = proto_item_add_subtree(tf, ett_nodeinfo_subject4);
p = offset + sizeof *ni;
for (i = 0; i < n; i++) {
- tvb_memcpy(tvb, ipaddr, p, 4);
+ ipaddr = tvb_get_ipv4(tvb, p);
proto_tree_add_text(field_tree, tvb,
- p, sizeof(guint32), "%s", ip_to_str(ipaddr));
+ p, sizeof(guint32), "%s", ip_to_str((guint8 *)&ipaddr));
p += sizeof(guint32);
}
off = tvb_length_remaining(tvb, offset);
@@ -744,9 +744,10 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
field_tree = proto_item_add_subtree(tf, ett_nodeinfo_node4);
p = offset + sizeof *ni;
for (i = 0; i < n; i++) {
- tvb_memcpy(tvb, ipaddr, sizeof(gint32) + p, 4);
+ ipaddr = tvb_get_ipv4(tvb, sizeof(gint32) + p);
proto_tree_add_text(field_tree, tvb,
- p, sizeof(guint32), "%s (TTL %d)", ip_to_str(ipaddr), tvb_get_ntohl(tvb, p));
+ p, sizeof(guint32), "%s (TTL %d)",
+ ip_to_str((guint8 *)&ipaddr), tvb_get_ntohl(tvb, p));
p += sizeof(gint32) + sizeof(guint32);
}
off = tvb_length_remaining(tvb, offset);
diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c
index 1c076e83bc..3ea1befd5b 100644
--- a/epan/dissectors/packet-radius.c
+++ b/epan/dissectors/packet-radius.c
@@ -286,7 +286,7 @@ void radius_octets(radius_attr_info_t* a, proto_tree* tree, packet_info *pinfo _
}
void radius_ipaddr(radius_attr_info_t* a, proto_tree* tree, packet_info *pinfo _U_, tvbuff_t* tvb, int offset, int len, proto_item* avp_item) {
- guint8 ip[4];
+ guint32 ip;
gchar buf[16];
if (len != 4) {
@@ -294,19 +294,18 @@ void radius_ipaddr(radius_attr_info_t* a, proto_tree* tree, packet_info *pinfo _
return;
}
- tvb_memcpy(tvb,ip,offset,4);
+ ip=tvb_get_ipv4(tvb,offset);
proto_tree_add_item(tree, a->hf, tvb, offset, len, FALSE);
- ip_to_str_buf(ip, buf);
+ ip_to_str_buf((guint8 *)&ip, buf);
proto_item_append_text(avp_item, "%s", buf);
}
void radius_ipv6addr(radius_attr_info_t* a, proto_tree* tree, packet_info *pinfo _U_, tvbuff_t* tvb, int offset, int len, proto_item* avp_item) {
- guint8 ipv6_buff[64];
+ struct e_in6_addr ipv6_buff;
gchar txtbuf[256];
- /* XXX ??? */
if (len != 16) {
proto_item_append_text(avp_item, "[wrong length for IPv6 address]");
return;
@@ -314,8 +313,8 @@ void radius_ipv6addr(radius_attr_info_t* a, proto_tree* tree, packet_info *pinfo
proto_tree_add_item(tree, a->hf, tvb, offset, len, FALSE);
- tvb_memcpy(tvb, ipv6_buff, offset, len);
- ip6_to_str_buf((struct e_in6_addr *)ipv6_buff, txtbuf);
+ tvb_get_ipv6(tvb, offset, &ipv6_buff);
+ ip6_to_str_buf(&ipv6_buff, txtbuf);
proto_item_append_text(avp_item, "%s", txtbuf);
}