aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-09-10 19:43:41 +0000
committerGuy Harris <guy@alum.mit.edu>2005-09-10 19:43:41 +0000
commit266e1a3491de1ff790c326bbffe0d4827af0f24b (patch)
tree0f7a094370b39116b39a12fcc5d0329738769398
parentc4b2c971fc559ff346c81b782364ff7985110c45 (diff)
Add "tvb_get_ipv4()" and "tvb_get_ipv6()" addresses, to fetch IPv4 and
IPv6 addresses. Use "tvb_get_ipv4()" in the WINS Replication dissector, so that it gets the right answer on little-endian *AND* big-endian machines. svn path=/trunk/; revision=15753
-rw-r--r--doc/README.developer7
-rw-r--r--epan/dissectors/packet-winsrepl.c12
-rw-r--r--epan/libethereal.def2
-rw-r--r--epan/proto.c2
-rw-r--r--epan/tvbuff.c25
-rw-r--r--epan/tvbuff.h9
6 files changed, 49 insertions, 8 deletions
diff --git a/doc/README.developer b/doc/README.developer
index b1f1fcf61f..c5a06a5689 100644
--- a/doc/README.developer
+++ b/doc/README.developer
@@ -878,8 +878,13 @@ double-precision IEEE floating-point numbers:
gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
+Accessors for IPv4 and IPv6 addresses:
+
+guint32 tvb_get_ipv4(tvbuff_t*, gint offset);
+void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
+
NOTE: IPv4 addresses are not to be converted to host byte order before
-being passed to "proto_tree_add_ipv4()". You should use "tvb_memcpy()"
+being passed to "proto_tree_add_ipv4()". You should use "tvb_get_ipv4()"
to fetch them, not "tvb_get_ntohl()" *OR* "tvb_get_letohl()" - don't,
for example, try to use "tvb_get_ntohl()", find that it gives you the
wrong answer on the PC on which you're doing development, and try
diff --git a/epan/dissectors/packet-winsrepl.c b/epan/dissectors/packet-winsrepl.c
index c320ef379b..6e908187d7 100644
--- a/epan/dissectors/packet-winsrepl.c
+++ b/epan/dissectors/packet-winsrepl.c
@@ -213,7 +213,7 @@ dissect_winsrepl_wins_owner(tvbuff_t *winsrepl_tvb, _U_ packet_info *pinfo,
/* ADDRESS */
addr_ptr = tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- addr = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&owner->address, AT_IPv4, 4, addr_ptr);
proto_tree_add_ipv4(owner_tree, hf_winsrepl_owner_address, winsrepl_tvb, winsrepl_offset, 4, addr);
winsrepl_offset += 4;
@@ -267,7 +267,7 @@ dissect_winsrepl_table_reply(tvbuff_t *winsrepl_tvb, packet_info *pinfo,
/* INITIATOR */
initiator_ptr= tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- initiator = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ initiator = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&table->initiator, AT_IPv4, 4, initiator_ptr);
proto_tree_add_ipv4(table_tree, hf_winsrepl_table_initiator, winsrepl_tvb, winsrepl_offset, 4, initiator);
winsrepl_offset += 4;
@@ -312,14 +312,14 @@ dissect_winsrepl_wins_ip(tvbuff_t *winsrepl_tvb, _U_ packet_info *pinfo,
/* OWNER */
addr_ptr= tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- addr = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&ip->owner, AT_IPv4, 4, addr_ptr);
proto_tree_add_ipv4(ip_tree, hf_winsrepl_ip_owner, winsrepl_tvb, winsrepl_offset, 4, addr);
winsrepl_offset += 4;
/* IP */
addr_ptr= tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- addr = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&ip->ip, AT_IPv4, 4, addr_ptr);
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(ip->ip.data));
@@ -428,7 +428,7 @@ dissect_winsrepl_wins_name(tvbuff_t *winsrepl_tvb, packet_info *pinfo,
case 0:
/* IP */
addr_ptr= tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- addr = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&name->addresses.ip, AT_IPv4, 4, addr_ptr);
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(name->addresses.ip.data));
@@ -444,7 +444,7 @@ dissect_winsrepl_wins_name(tvbuff_t *winsrepl_tvb, packet_info *pinfo,
/* UNKNOWN, little or big endian??? */
addr_ptr= tvb_get_ptr(winsrepl_tvb, winsrepl_offset, 4);
- addr = tvb_get_letohl(winsrepl_tvb, winsrepl_offset);
+ addr = tvb_get_ipv4(winsrepl_tvb, winsrepl_offset);
SET_ADDRESS(&name->unknown, AT_IPv4, 4, addr_ptr);
proto_tree_add_ipv4(name_tree, hf_winsrepl_name_unknown, winsrepl_tvb, winsrepl_offset, 4, addr);
winsrepl_offset += 4;
diff --git a/epan/libethereal.def b/epan/libethereal.def
index 71d1c1ad4c..91f676e935 100644
--- a/epan/libethereal.def
+++ b/epan/libethereal.def
@@ -579,6 +579,8 @@ tvb_find_line_end_unquoted
tvb_format_text
tvb_get_ephemeral_string
tvb_get_guint8
+tvb_get_ipv4
+tvb_get_ipv6
tvb_get_letoh24
tvb_get_letoh64
tvb_get_letohl
diff --git a/epan/proto.c b/epan/proto.c
index 3208f30941..5deb8f1b18 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -823,7 +823,7 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
case FT_IPv4:
DISSECTOR_ASSERT(length == 4);
- tvb_memcpy(tvb, (guint8 *)&value, start, 4);
+ value = tvb_get_ipv4(tvb, start);
proto_tree_set_ipv4(new_fi, little_endian ? GUINT32_SWAP_LE_BE(value) : value);
break;
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index f1e6bc6045..ae767e519c 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -46,6 +46,7 @@
#endif
#include "pint.h"
+#include "ipv6-utils.h"
#include "tvbuff.h"
#include "strutil.h"
#include "emem.h"
@@ -1386,6 +1387,30 @@ tvb_get_letohieee_double(tvbuff_t *tvb, int offset)
#endif
}
+/* Fetch an IPv4 address, in network byte order.
+ * We do *not* convert them to host byte order; we leave them in
+ * network byte order. */
+guint32
+tvb_get_ipv4(tvbuff_t *tvb, gint offset)
+{
+ const guint8* ptr;
+ guint32 addr;
+
+ ptr = ensure_contiguous(tvb, offset, sizeof(guint32));
+ memcpy(&addr, ptr, sizeof addr);
+ return addr;
+}
+
+/* Fetch an IPv6 address. */
+void
+tvb_get_ipv6(tvbuff_t *tvb, gint offset, struct e_in6_addr *addr)
+{
+ const guint8* ptr;
+
+ ptr = ensure_contiguous(tvb, offset, sizeof(*addr));
+ memcpy(addr, ptr, sizeof *addr);
+}
+
/* Find first occurence of needle in tvbuff, starting at offset. Searches
* at most maxlength number of bytes; if maxlength is -1, searches to
* end of tvbuff.
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index d7a64db654..f13a39ccd9 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -320,6 +320,15 @@ extern guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
extern gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
extern gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
+/**
+ * Fetch an IPv4 address, in network byte order.
+ * We do *not* convert it to host byte order; we leave it in
+ * network byte order, as that's what its callers expect. */
+extern guint32 tvb_get_ipv4(tvbuff_t*, gint offset);
+
+/* Fetch an IPv6 address. */
+extern void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
+
/** Returns target for convenience. Does not suffer from possible
* expense of tvb_get_ptr(), since this routine is smart enough
* to copy data in chunks if the request range actually exists in