lua: add an SCPacketTimestamp function

The SCPacketTimestamp function returns packet timestamps as 2 real
numbers (seconds & microseconds).

Example:

  local sec, usec = SCPacketTimestamp()

Signed-off-by: Nicolas Thill <ntl@p1sec.com>
pull/2353/head
Nicolas Thill 10 years ago committed by Victor Julien
parent f4b165de94
commit e95e6ccded

@ -158,6 +158,21 @@ static int LuaCallbackPacketPayload(lua_State *luastate)
return LuaCallbackPacketPayloadPushToStackFromPacket(luastate, p); return LuaCallbackPacketPayloadPushToStackFromPacket(luastate, p);
} }
/** \internal
* \brief fill lua stack with packet timestamp
* \param luastate the lua state
* \param p packet
* \retval cnt number of data items placed on the stack
*
* Places: seconds (number), microseconds (number)
*/
static int LuaCallbackTimestampPushToStack(lua_State *luastate, const struct timeval *ts)
{
lua_pushnumber(luastate, (double)ts->tv_sec);
lua_pushnumber(luastate, (double)ts->tv_usec);
return 2;
}
/** \internal /** \internal
* \brief fill lua stack with header info * \brief fill lua stack with header info
* \param luastate the lua state * \param luastate the lua state
@ -174,6 +189,19 @@ static int LuaCallbackTimeStringPushToStackFromPacket(lua_State *luastate, const
return 1; return 1;
} }
/** \internal
* \brief Wrapper for getting packet timestamp (as numbers) into a lua script
* \retval cnt number of items placed on the stack
*/
static int LuaCallbackPacketTimestamp(lua_State *luastate)
{
const Packet *p = LuaStateGetPacket(luastate);
if (p == NULL)
return LuaCallbackError(luastate, "internal error: no packet");
return LuaCallbackTimestampPushToStack(luastate, &p->ts);
}
/** \internal /** \internal
* \brief Wrapper for getting tuple info into a lua script * \brief Wrapper for getting tuple info into a lua script
* \retval cnt number of items placed on the stack * \retval cnt number of items placed on the stack
@ -719,6 +747,8 @@ int LuaRegisterFunctions(lua_State *luastate)
/* registration of the callbacks */ /* registration of the callbacks */
lua_pushcfunction(luastate, LuaCallbackPacketPayload); lua_pushcfunction(luastate, LuaCallbackPacketPayload);
lua_setglobal(luastate, "SCPacketPayload"); lua_setglobal(luastate, "SCPacketPayload");
lua_pushcfunction(luastate, LuaCallbackPacketTimestamp);
lua_setglobal(luastate, "SCPacketTimestamp");
lua_pushcfunction(luastate, LuaCallbackPacketTimeString); lua_pushcfunction(luastate, LuaCallbackPacketTimeString);
lua_setglobal(luastate, "SCPacketTimeString"); lua_setglobal(luastate, "SCPacketTimeString");
lua_pushcfunction(luastate, LuaCallbackTuple); lua_pushcfunction(luastate, LuaCallbackTuple);

Loading…
Cancel
Save