[Bro-Dev] #372: bifcl cannot pass specific enum types
Bro Tracker
bro at tracker.icir.org
Fri Feb 4 16:04:19 PST 2011
#372: bifcl cannot pass specific enum types
----------------------+---------------------
Reporter: robin | Owner:
Type: Problem | Status: new
Priority: Normal | Milestone: Bro1.6
Component: Bro | Version:
Resolution: | Keywords: logging
----------------------+---------------------
Comment (by gregor):
{{{
#!rst
How use enums in C++, bif, and .bro
-----------------------------------
That's actually pretty straight forward. The functionality has been in Bro
for quite a while but it has been scarcely used.
In ``const.bif`` you can define enums. These are then available in the
policy layer as well
as in the C++/bif layer. E.g.,::
enum foobar %{
foo,
bar
%}
Will make the enum ``foobar`` available in the policy layer.
For the C++ layer the bif will automatically the following code that is
included in ``NetVar.h`` (and also the necessary initialization code)::
extern EnumType* enum_foobar;
namespace BroEnum { enum foobar {
foo,
bar
};}
Some code snippets showing how you can make use of those in C++ and bif::
BroEnum::foobar x;
x = BroEnum::foo;
if (x == BroEnum::bar)
do_something();
....
EnumVal *y = new EnumVal(x, enum_foobar);
EnumVal *z = new EnumVal(BroEnum::bar, enum_foobar);
// y and z can now be passed to an event or returned from a bif.
// In the policy script the type would be foobar.
}}}
--
Ticket URL: <http://tracker.icir.org/bro/ticket/372#comment:3>
Bro Tracker <http://tracker.icir.org/bro>
Bro Issue Tracker
More information about the bro-dev
mailing list