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
/* 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;
/* 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;
/* 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));
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));
/* 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;
#endif
#include "pint.h"
+#include "ipv6-utils.h"
#include "tvbuff.h"
#include "strutil.h"
#include "emem.h"
#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.
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