Wireshark-dev: [Wireshark-dev] [Patch] native little endian ipv4 decoding function for the lua
From: "Balint Reczey (IJ/ETH)" <[email protected]>
Date: Wed, 11 Apr 2007 15:03:59 +0200
Hi,

The attached patch adds ability of reading Little Endian encoded IPv4
addresses to the Lua plugin.
Could someone commit it to the svn repo?

Cheers,
Balint

Index: epan/wslua/wslua_tvb.c
===================================================================
--- epan/wslua/wslua_tvb.c	(revision 21381)
+++ epan/wslua/wslua_tvb.c	(working copy)
@@ -702,6 +702,29 @@
 	WSLUA_RETURN(1); /* the IPv4 Address */
 }
 
+WSLUA_METHOD TvbRange_get_le_ipv4(lua_State* L) {
+	/* get an Little Endian IPv4 Address from a TvbRange. */
+
+    TvbRange tvbr = checkTvbRange(L,1);
+    Address addr;
+    guint32* ip_addr;
+
+    if ( !tvbr ) return 0;
+
+	if (tvbr->len != 4)
+		WSLUA_ERROR(TvbRange_get_ipv4,"The range must be 4 octets long");
+
+    addr = g_malloc(sizeof(address));
+
+    ip_addr = g_malloc(sizeof(guint32));
+    *ip_addr = tvb_get_letohl(tvbr->tvb,tvbr->offset);
+
+    SET_ADDRESS(addr, AT_IPv4, 4, ip_addr);
+    pushAddress(L,addr);
+
+	WSLUA_RETURN(1); /* the IPv4 Address */
+}
+
 WSLUA_METHOD TvbRange_get_ether(lua_State* L) {
 	/* get an Ethernet Address from a TvbRange. */
     TvbRange tvbr = checkTvbRange(L,1);
@@ -769,6 +792,7 @@
     {"le_float", TvbRange_get_le_float},
     {"ether", TvbRange_get_ether},
     {"ipv4", TvbRange_get_ipv4},
+    {"le_ipv4", TvbRange_get_le_ipv4},
     {"string", TvbRange_get_string},
     {"bytes", TvbRange_get_bytes},
     {"tvb", Tvb_new_subset},