aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-06-15 23:24:01 -0700
committerGuy Harris <gharris@sonic.net>2021-06-16 07:31:22 +0000
commit18e13337ea0dbeafd1b79d9b19631bd475e01077 (patch)
tree4878369a69a22436be6d076778f9f6e93909a8af
parent9ea88b3ee248c00dc30f8df3431176cb758b191c (diff)
wslua: a tvbuff doesn't have an "actual length".
It has a "reported length", which is the closes thing to an "actual length", as it represents the length the packet, or subset thereof, had on the network, and a "captured length", which is the amount of the packet that the capture process saved. In 99.999999999999999999999999999999% of all cases, a dissector should look at the "reported length", not at the "captured length". Rename the "len" method to "captured_len", leaving "len" around for backwards compatibility. Fix the documentation to reflect reality, to avoid issues such as #15655. (cherry picked from commit bd9ceaebef86a30f5f45a8887fd01883dd0d1993)
-rw-r--r--epan/wslua/wslua_tvb.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index 8d01ddc66e..3e5c817ecb 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -52,7 +52,7 @@ WSLUA_CLASS_DEFINE(Tvb,FAIL_ON_NULL_OR_EXPIRED("Tvb"));
and can be used to extract information (via <<lua_class_TvbRange,`TvbRange`>>) from the packet's data.
To create a <<lua_class_TvbRange,`TvbRange`>> the <<lua_class_Tvb,`Tvb`>> must be called with offset and length as optional arguments;
- the offset defaults to 0 and the length to `tvb:len()`.
+ the offset defaults to 0 and the length to `tvb:captured_len()`.
[WARNING]
====
@@ -132,15 +132,24 @@ static int Tvb__gc(lua_State* L) {
}
WSLUA_METHOD Tvb_reported_len(lua_State* L) {
- /* Obtain the reported (not captured) length of a <<lua_class_Tvb,`Tvb`>>. */
+ /* Obtain the reported length (length on the network) of a <<lua_class_Tvb,`Tvb`>>. */
Tvb tvb = checkTvb(L,1);
lua_pushnumber(L,tvb_reported_length(tvb->ws_tvb));
WSLUA_RETURN(1); /* The reported length of the <<lua_class_Tvb,`Tvb`>>. */
}
+WSLUA_METHOD Tvb_captured_len(lua_State* L) {
+ /* Obtain the captured length (amount saved in the capture process) of a <<lua_class_Tvb,`Tvb`>>. */
+ Tvb tvb = checkTvb(L,1);
+
+ lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb));
+ WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */
+}
+
WSLUA_METHOD Tvb_len(lua_State* L) {
- /* Obtain the actual (captured) length of a <<lua_class_Tvb,`Tvb`>>. */
+ /* Obtain the captured length (amount saved in the capture process) of a <<lua_class_Tvb,`Tvb`>>.
+ Same as captured_len; kept only for backwards compatibility */
Tvb tvb = checkTvb(L,1);
lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb));
@@ -299,10 +308,11 @@ WSLUA_METAMETHOD Tvb__eq(lua_State* L) {
WSLUA_METHODS Tvb_methods[] = {
WSLUA_CLASS_FNREG(Tvb,bytes),
WSLUA_CLASS_FNREG(Tvb,range),
- WSLUA_CLASS_FNREG(Tvb,len),
WSLUA_CLASS_FNREG(Tvb,offset),
WSLUA_CLASS_FNREG(Tvb,reported_len),
WSLUA_CLASS_FNREG(Tvb,reported_length_remaining),
+ WSLUA_CLASS_FNREG(Tvb,captured_len),
+ WSLUA_CLASS_FNREG(Tvb,len),
WSLUA_CLASS_FNREG(Tvb,raw),
{ NULL, NULL }
};