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 bd9ceaebef)
This commit is contained in:
Guy Harris 2021-06-15 23:24:01 -07:00
parent 9ea88b3ee2
commit 18e13337ea
1 changed files with 14 additions and 4 deletions

View File

@ -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 }
};