aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_tvb.c
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2007-04-12 22:45:22 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2007-04-12 22:45:22 +0000
commit5f5f6561084a292b10f2712236aed087799167f2 (patch)
tree606371a38e1b71f295f6ea062002cdfc5ef37468 /epan/wslua/wslua_tvb.c
parentbbf2ad0977d6a37cf5da23719bc6b4951068d089 (diff)
From: Balint Reczey
I would like to handle the rare situation of Little Endian encoded IP addresses, so i added a function which reads the address with tvb_get_ipv4(), then swaps the bytes before SET_ADDRESS(). svn path=/trunk/; revision=21397
Diffstat (limited to 'epan/wslua/wslua_tvb.c')
-rw-r--r--epan/wslua/wslua_tvb.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index b31eb1860e..bf605f1668 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -702,6 +702,30 @@ WSLUA_METHOD TvbRange_get_ipv4(lua_State* L) {
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_ipv4(tvbr->tvb,tvbr->offset);
+ *((guint32 *)ip_addr) = GUINT32_SWAP_LE_BE(*((guint32 *)ip_addr));
+
+ 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 +793,7 @@ static const luaL_reg TvbRange_methods[] = {
{"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},