Add "tvb_get_ipv4()" and "tvb_get_ipv6()" addresses, to fetch IPv4 and
authorGuy Harris <guy@alum.mit.edu>
Sat, 10 Sep 2005 19:43:41 +0000 (19:43 -0000)
committerGuy Harris <guy@alum.mit.edu>
Sat, 10 Sep 2005 19:43:41 +0000 (19:43 -0000)
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

doc/README.developer
epan/dissectors/packet-winsrepl.c
epan/libethereal.def
epan/proto.c
epan/tvbuff.c
epan/tvbuff.h

index b1f1fcf61f59e75066e6a3492725aa8e54f61c5a..c5a06a56899e0299ccb99af47109428035c74e11 100644 (file)
@@ -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
index c320ef379b716886b858d6323aa8ec04c9a8944e..6e908187d7e5259a4b45c13f62982965a6876a2e 100644 (file)
@@ -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;
index 71d1c1ad4caa96f85e68fce7183212c369052784..91f676e93540ba46379caef88bc9142d819ee228 100644 (file)
@@ -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
index 3208f309418ab74c65818b61dec2b1e66644e8cd..5deb8f1b18e7fc5801b5da8aae70228f31dc222d 100644 (file)
@@ -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;
 
index f1e6bc60456b6d03fb257d174720b3bbc716dff5..ae767e519cd570a4edc87c19cc7d4fb8d94ccbba 100644 (file)
@@ -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.
index d7a64db654d4b5725c6b3b8e7f99d0ed13842621..f13a39ccd9053d1fc6fd1a3ff67592b5ef82db4a 100644 (file)
@@ -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