本文整理汇总了C++中checkTvbRange函数的典型用法代码示例。如果您正苦于以下问题:C++ checkTvbRange函数的具体用法?C++ checkTvbRange怎么用?C++ checkTvbRange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkTvbRange函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: TvbRange__eq
WSLUA_METAMETHOD TvbRange__eq(lua_State* L) {
/* Checks whether the two `TvbRange` contents are equal.
@since 1.99.8
*/
TvbRange tvb_l = checkTvbRange(L,1);
TvbRange tvb_r = checkTvbRange(L,2);
/* it is not an error if their ds_tvb are different... they're just not equal */
if (tvb_l->len == tvb_r->len &&
tvb_l->len <= tvb_captured_length_remaining(tvb_l->tvb->ws_tvb, tvb_l->offset) &&
tvb_r->len <= tvb_captured_length_remaining(tvb_r->tvb->ws_tvb, tvb_r->offset))
{
const gchar* lp = tvb_get_ptr(tvb_l->tvb->ws_tvb, tvb_l->offset, tvb_l->len);
const gchar* rp = tvb_get_ptr(tvb_r->tvb->ws_tvb, tvb_r->offset, tvb_r->len);
int i = 0;
for (; i < tvb_r->len; ++i) {
if (lp[i] != rp[i]) {
lua_pushboolean(L,0);
return 1;
}
}
lua_pushboolean(L,1);
} else {
lua_pushboolean(L,0);
}
return 1;
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:30,代码来源:wslua_tvb.c
示例2: TvbRange_uncompress
WSLUA_METHOD TvbRange_uncompress(lua_State* L) {
/* Obtain an uncompressed TvbRange from a TvbRange */
#define WSLUA_ARG_TvbRange_uncompress_NAME 2 /* The name to be given to the new data-source. */
TvbRange tvbr = checkTvbRange(L,1);
#ifdef HAVE_ZLIB
const gchar* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_NAME,"Uncompressed");
tvbuff_t *uncompr_tvb;
#endif
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
#ifdef HAVE_ZLIB
uncompr_tvb = tvb_child_uncompress(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len);
if (uncompr_tvb) {
add_new_data_source (lua_pinfo, uncompr_tvb, name);
if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) {
WSLUA_RETURN(1); /* The TvbRange */
}
}
#else
luaL_error(L,"Missing support for ZLIB");
#endif
return 0;
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:30,代码来源:wslua_tvb.c
示例3: TvbRange_range
WSLUA_METHOD TvbRange_range(lua_State* L) {
/* Creates a sub-`TvbRange` from this `TvbRange`. */
#define WSLUA_OPTARG_TvbRange_range_OFFSET 2 /* The offset (in octets) from the beginning of the `TvbRange`. Defaults to 0. */
#define WSLUA_OPTARG_TvbRange_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the `TvbRange`. */
TvbRange tvbr = checkTvbRange(L,1);
int offset = (int)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_range_OFFSET,0);
int len;
if (!(tvbr && tvbr->tvb)) return 0;
len = (int)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_range_LENGTH,tvbr->len-offset);
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (offset >= tvbr->len || (len + offset) > tvbr->len) {
luaL_error(L,"Range is out of bounds");
return 0;
}
if (push_TvbRange(L,tvbr->tvb->ws_tvb,tvbr->offset+offset,len)) {
WSLUA_RETURN(1); /* The TvbRange */
}
return 0;
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:29,代码来源:wslua_tvb.c
示例4: TvbRange_le_nstime
WSLUA_METHOD TvbRange_le_nstime(lua_State* L) {
/* Obtain a nstime from a TvbRange */
TvbRange tvbr = checkTvbRange(L,1);
NSTime nstime;
if ( !(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
nstime = g_new(nstime_t,1);
if (tvbr->len == 4) {
nstime->secs = tvb_get_letohl(tvbr->tvb->ws_tvb, tvbr->offset);
nstime->nsecs = 0;
} else if (tvbr->len == 8) {
nstime->secs = tvb_get_letohl(tvbr->tvb->ws_tvb, tvbr->offset);
nstime->nsecs = tvb_get_letohl(tvbr->tvb->ws_tvb, tvbr->offset + 4);
} else {
g_free(nstime);
WSLUA_ERROR(TvbRange_nstime,"The range must be 4 or 8 bytes long");
return 0;
}
pushNSTime(L, nstime);
WSLUA_RETURN(1); /* The NSTime */
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:29,代码来源:wslua_tvb.c
示例5: TvbRange_le_ipv4
WSLUA_METHOD TvbRange_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 && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (tvbr->len != 4)
WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
addr = (address *)g_malloc(sizeof(address));
ip_addr = (guint32 *)g_malloc(sizeof(guint32));
*ip_addr = tvb_get_ipv4(tvbr->tvb->ws_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 */
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:26,代码来源:wslua_tvb.c
示例6: TvbRange_tvb
WSLUA_CONSTRUCTOR TvbRange_tvb (lua_State *L) {
/* Creates a (sub)Tvb from using a TvbRange */
#define WSLUA_ARG_Tvb_new_subset_RANGE 1 /* The TvbRange from which to create the new Tvb. */
TvbRange tvbr = checkTvbRange(L,WSLUA_ARG_Tvb_new_subset_RANGE);
Tvb tvb;
if (! (tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (tvb_offset_exists(tvbr->tvb->ws_tvb, tvbr->offset + tvbr->len -1 )) {
tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb));
tvb->expired = FALSE;
tvb->need_free = FALSE;
tvb->ws_tvb = tvb_new_subset(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len, tvbr->len);
PUSH_TVB(L, tvb);
return 1;
} else {
luaL_error(L,"Out Of Bounds");
return 0;
}
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:25,代码来源:wslua_tvb.c
示例7: TvbRange_uncompress
static int TvbRange_uncompress(lua_State* L) {
/* Obtain a uncompressed TvbRange from a TvbRange */
#define WSLUA_ARG_TvbRange_tvb_NAME 2 /* The name to be given to the new data-source. */
TvbRange tvbr = checkTvbRange(L,1);
const gchar* name = luaL_optstring(L,WSLUA_ARG_ByteArray_tvb_NAME,"Uncompressed");
tvbuff_t *uncompr_tvb;
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
#ifdef HAVE_LIBZ
uncompr_tvb = tvb_child_uncompress(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len);
if (uncompr_tvb) {
add_new_data_source (lua_pinfo, uncompr_tvb, name);
if ((tvbr = new_TvbRange(L,uncompr_tvb,0,tvb_length(uncompr_tvb)))) {
PUSH_TVBRANGE(L,tvbr);
WSLUA_RETURN(1); /* The TvbRange */
}
}
#else
luaL_error(L,"Missing support for ZLIB");
#endif
return 0;
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:29,代码来源:wslua_tvb.c
示例8: TvbRange_uint
/*
* get a Blefuscuoan unsigned integer from a tvb
*/
WSLUA_METHOD TvbRange_uint(lua_State* L) {
/* Get a Big Endian (network order) unsigned integer from a `TvbRange`.
The range must be 1, 2, 3 or 4 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
lua_pushnumber(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 2:
lua_pushnumber(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 3:
lua_pushnumber(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 4:
lua_pushnumber(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The unsigned integer value. */
default:
luaL_error(L,"TvbRange:uint() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:31,代码来源:wslua_tvb.c
示例9: TvbRange_int64
/*
* get a Blefuscuoan signed 64 bit integer from a tvb
*/
WSLUA_METHOD TvbRange_int64(lua_State* L) {
/* Get a Big Endian (network order) signed 64 bit integer from a TvbRange. The range must be 1-8 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8: {
pushInt64(L,(gint64)tvb_get_ntoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1);
}
default:
luaL_error(L,"TvbRange:int64() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:jelmer,项目名称:wireshark,代码行数:29,代码来源:wslua_tvb.c
示例10: TvbRange_ustringz_any
static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) {
/* Obtain a zero terminated string from a TvbRange */
gint count;
TvbRange tvbr = checkTvbRange(L,1);
gint offset;
gunichar2 uchar;
if ( !(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
offset = tvbr->offset;
do {
if (!tvb_bytes_exist (tvbr->tvb->ws_tvb, offset, 2)) {
luaL_error(L,"out of bounds");
return 0;
}
/* Endianness doesn't matter when looking for null */
uchar = tvb_get_ntohs (tvbr->tvb->ws_tvb, offset);
offset += 2;
} while (uchar != 0);
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,&count,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)) );
lua_pushinteger(L,count);
return 2; /* The zero terminated string, the length found in tvbr */
}
开发者ID:jelmer,项目名称:wireshark,代码行数:29,代码来源:wslua_tvb.c
示例11: TvbRange_raw
WSLUA_METHOD TvbRange_raw(lua_State* L) {
/* Obtain a Lua string of the binary bytes in a TvbRange. */
#define WSLUA_OPTARG_TvbRange_raw_OFFSET 2 /* The position of the first byte (default=0/first). */
#define WSLUA_OPTARG_TvbRange_raw_LENGTH 3 /* The length of the segment to get (default=all). */
TvbRange tvbr = checkTvbRange(L,1);
int offset = luaL_optint(L,WSLUA_OPTARG_TvbRange_raw_OFFSET,0);
int len = luaL_optint(L,WSLUA_OPTARG_TvbRange_raw_LENGTH,-1);
if (!tvbr || !tvbr->tvb) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if ((guint)offset > tvb_length(tvbr->tvb->ws_tvb)) {
WSLUA_OPTARG_ERROR(Tvb_raw,OFFSET,"offset beyond end of Tvb");
return 0;
}
if (len == -1) {
len = tvb_length_remaining(tvbr->tvb->ws_tvb,offset);
if (len < 0) {
luaL_error(L,"out of bounds");
return FALSE;
}
} else if ( (guint)(len + offset) > tvb_length(tvbr->tvb->ws_tvb)) {
luaL_error(L,"Range is out of bounds");
return FALSE;
}
lua_pushlstring(L, tvb_get_ptr(tvbr->tvb->ws_tvb, offset, len), len);
WSLUA_RETURN(1); /* A Lua string of the binary bytes in the TvbRange. */
}
开发者ID:jelmer,项目名称:wireshark,代码行数:34,代码来源:wslua_tvb.c
示例12: TvbRange_ether
WSLUA_METHOD TvbRange_ether(lua_State* L) {
/* Get an Ethernet Address from a TvbRange. */
TvbRange tvbr = checkTvbRange(L,1);
Address addr;
guint8* buff;
if ( !(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (tvbr->len != 6) {
WSLUA_ERROR(TvbRange_ether,"The range must be 6 bytes long");
return 0;
}
addr = g_new(address,1);
buff = (guint8 *)tvb_memdup(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len);
SET_ADDRESS(addr, AT_ETHER, 6, buff);
pushAddress(L,addr);
WSLUA_RETURN(1); /* The Ethernet Address */
}
开发者ID:jelmer,项目名称:wireshark,代码行数:26,代码来源:wslua_tvb.c
示例13: TvbRange_le_uint
/*
* get a Lilliputian unsigned integer from a tvb
*/
WSLUA_METHOD TvbRange_le_uint(lua_State* L) {
/* Get a Little Endian unsigned integer from a TvbRange. The range must be 1, 2, 3 or 4 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
/* XXX unsigned anyway */
lua_pushnumber(L,(lua_Number)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 2:
lua_pushnumber(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 3:
lua_pushnumber(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 4:
lua_pushnumber(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The unsigned integer value */
default:
luaL_error(L,"TvbRange:le_uint() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:31,代码来源:wslua_tvb.c
示例14: TvbRange_int
/*
* get a Blefuscuoan signed integer from a tvb
*/
WSLUA_METHOD TvbRange_int(lua_State* L) {
/* Get a Big Endian (network order) signed integer from a TvbRange. The range must be 1, 2 or 4 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
lua_pushnumber(L,(gchar)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 2:
lua_pushnumber(L,(gshort)tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 4:
lua_pushnumber(L,(gint)tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The signed integer value */
/*
* XXX:
* lua uses double so we have 52 bits to play with
* we are missing 5 and 6 byte integers within lua's range
* and 64 bit integers are not supported (there's a lib for
* lua that does).
*/
default:
luaL_error(L,"TvbRange:int() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:34,代码来源:wslua_tvb.c
示例15: TvbRange_le_int64
/*
* get a Lilliputian signed 64 bit integer from a tvb
*/
WSLUA_METHOD TvbRange_le_int64(lua_State* L) {
/* Get a Little Endian signed 64 bit integer from a TvbRange. The range must be 1-8 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8: {
Int64 num = (Int64)g_malloc(sizeof(gint64));
*num = (gint64)tvb_get_letoh64(tvbr->tvb->ws_tvb,tvbr->offset);
pushInt64(L,num);
WSLUA_RETURN(1);
}
default:
luaL_error(L,"TvbRange:le_int64() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:31,代码来源:wslua_tvb.c
示例16: TvbRange_le_int64
/*
* get a Lilliputian signed 64 bit integer from a tvb
*/
WSLUA_METHOD TvbRange_le_int64(lua_State* L) {
/* Get a Little Endian signed 64 bit integer from a `TvbRange`, as an `Int64` object.
The range must be 1, 2, 4 or 8 octets long. */
TvbRange tvbr = checkTvbRange(L,1);
if (!(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
switch (tvbr->len) {
case 1:
pushInt64(L,(gint8)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 2:
pushInt64(L,(gint16)tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 4:
pushInt64(L,(gint32)tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 8:
pushInt64(L,(gint64)tvb_get_letoh64(tvbr->tvb->ws_tvb,tvbr->offset));
WSLUA_RETURN(1); /* The `Int64` object. */
default:
luaL_error(L,"TvbRange:le_int64() does not handle %d byte integers",tvbr->len);
return 0;
}
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:31,代码来源:wslua_tvb.c
示例17: TvbRange_range
WSLUA_METHOD TvbRange_range(lua_State* L) {
/* Creates a sub-TvbRange from this TvbRange. This is used also as the TvbRange:__call() metamethod. */
#define WSLUA_OPTARG_TvbRange_range_OFFSET 2 /* The offset (in octets) from the beginning of the TvbRange. Defaults to 0. */
#define WSLUA_OPTARG_TvbRange_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the TvbRange. */
TvbRange tvbr = checkTvbRange(L,1);
int offset = luaL_optint(L,WSLUA_OPTARG_TvbRange_range_OFFSET,0);
int len;
if (!(tvbr && tvbr->tvb)) return 0;
len = luaL_optint(L,WSLUA_OPTARG_TvbRange_range_LENGTH,tvbr->len-offset);
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (offset >= tvbr->len || (len + offset) > tvbr->len) {
luaL_error(L,"Range is out of bounds");
return 0;
}
if ((tvbr = new_TvbRange(L,tvbr->tvb->ws_tvb,tvbr->offset+offset,len))) {
PUSH_TVBRANGE(L,tvbr);
WSLUA_RETURN(1); /* The TvbRange */
}
return 0;
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:30,代码来源:wslua_tvb.c
示例18: TvbRange_ipv4
WSLUA_METHOD TvbRange_ipv4(lua_State* L) {
/* Get an IPv4 Address from a `TvbRange`, as an `Address` object. */
TvbRange tvbr = checkTvbRange(L,1);
Address addr;
guint32* ip_addr;
if ( !(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (tvbr->len != 4) {
WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
return 0;
}
addr = (address *)g_malloc(sizeof(address));
ip_addr = (guint32 *)g_malloc(sizeof(guint32));
*ip_addr = tvb_get_ipv4(tvbr->tvb->ws_tvb,tvbr->offset);
set_address(addr, AT_IPv4, 4, ip_addr);
pushAddress(L,addr);
WSLUA_RETURN(1); /* The IPv4 `Address` object. */
}
开发者ID:linshimiao,项目名称:wireshark,代码行数:27,代码来源:wslua_tvb.c
示例19: TvbRange__gc
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
static int TvbRange__gc(lua_State* L) {
TvbRange tvbr = checkTvbRange(L,1);
free_TvbRange(tvbr);
return 0;
}
开发者ID:AndresVelasco,项目名称:wireshark,代码行数:9,代码来源:wslua_tvb.c
示例20: TvbRange_bytes
WSLUA_METHOD TvbRange_bytes(lua_State* L) {
/* Obtain a `ByteArray` from a `TvbRange`.
Starting in 1.11.4, this function also takes an optional `encoding` argument,
which can be set to `ENC_STR_HEX` to decode a hex-string from the `TvbRange`
into the returned `ByteArray`. The `encoding` can be bitwise-or'ed with one
or more separator encodings, such as `ENC_SEP_COLON`, to allow separators
to occur between each pair of hex characters.
The return value also now returns the number of bytes used as a second return value.
On failure or error, nil is returned for both return values.
@note The encoding type of the hex string should also be set, for example
`ENC_ASCII` or `ENC_UTF_8`, along with `ENC_STR_HEX`.
*/
#define WSLUA_OPTARG_TvbRange_bytes_ENCODING 2 /* An optional ENC_* encoding value to use */
TvbRange tvbr = checkTvbRange(L,1);
GByteArray* ba;
const guint encoding = (guint)luaL_optinteger(L, WSLUA_OPTARG_TvbRange_bytes_ENCODING, 0);
if ( !(tvbr && tvbr->tvb)) return 0;
if (tvbr->tvb->expired) {
luaL_error(L,"expired tvb");
return 0;
}
if (encoding == 0) {
ba = g_byte_array_new();
g_byte_array_append(ba,(const guint8 *)tvb_memdup(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len),tvbr->len);
pushByteArray(L,ba);
lua_pushinteger(L, tvbr->len);
}
else if ((encoding & ENC_STR_HEX) == 0) {
WSLUA_OPTARG_ERROR(TvbRange_nstime, ENCODING, "invalid encoding value");
}
else {
gint endoff = 0;
GByteArray* retval;
ba = g_byte_array_new();
retval = tvb_get_string_bytes(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len,
encoding, ba, &endoff);
if (!retval || endoff == 0) {
g_byte_array_free(ba, TRUE);
/* push nil nstime and offset */
lua_pushnil(L);
lua_pushnil(L);
}
else {
pushByteArray(L,ba);
lua_pushinteger(L, endoff);
}
}
WSLUA_RETURN(2); /* The `ByteArray` object or nil, and number of bytes consumed or nil. */
}
开发者ID:DHODoS,项目名称:wireshark,代码行数:57,代码来源:wslua_tvb.c
注:本文中的checkTvbRange函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论