GH-700: add zeek_args() BIF

Provides access to all zeek command-line arguments ("argv").
This commit is contained in:
Jon Siwek 2019-11-28 10:24:48 -08:00
parent c4a086bdcc
commit 57c7cbdb92
3 changed files with 16 additions and 0 deletions

View file

@ -23,6 +23,7 @@
#include "file_analysis/Manager.h" #include "file_analysis/Manager.h"
#include "iosource/Manager.h" #include "iosource/Manager.h"
#include "iosource/Packet.h" #include "iosource/Packet.h"
#include "IntrusivePtr.h"
using namespace std; using namespace std;
@ -1877,6 +1878,18 @@ function type_name%(t: any%): string
return new StringVal(s); return new StringVal(s);
%} %}
## Returns: list of command-line arguments (``argv``) used to run Zeek.
function zeek_args%(%): string_vec
%{
auto sv = internal_type("string_vec")->AsVectorType();
auto rval = make_intrusive<VectorVal>(sv);
for ( auto i = 0; i < bro_argc; ++i )
rval->Assign(rval->Size(), new StringVal(bro_argv[i]));
return rval.detach();
%}
## Checks whether Zeek reads traffic from one or more network interfaces (as ## Checks whether Zeek reads traffic from one or more network interfaces (as
## opposed to from a network trace in a file). Note that this function returns ## opposed to from a network trace in a file). Note that this function returns
## true even after Zeek has stopped reading network traffic, for example due to ## true even after Zeek has stopped reading network traffic, for example due to

View file

@ -0,0 +1 @@
[zeek, -b, -r, /Users/jsiwek/pro/zeek/zeek/testing/btest/Traces/http/get.trace, -e, print zeek_args()]

View file

@ -0,0 +1,2 @@
# @TEST-EXEC: zeek -b -r $TRACES/http/get.trace -e 'print zeek_args()' >out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out