Broccoli: The Bro Client Communications Library | ||
---|---|---|
Prev |
Similarly to many other software packages, the Broccoli distribution provides a script that you can use to obtain details about your Broccoli setup. The script currently provides the following flags:
--build prints the name of the machine the build was made on, when, and whether debugging support was enabled or not.
--prefix prints the directory in the filesystem below which Broccoli was installed.
--version prints the version of the distribution you have installed.
--libs prints the flags to pass to the linker in order to link in the Broccoli library.
--cflags prints the flags to pass to the compiler in order to properly include Broccoli's header file.
--config prints the location of the system-wide config file your installation will use.
The --cflags and --libs flags are the suggested way of obtaining the necessary information for integrating Broccoli into your build environment. It is generally recommended to use broccoli-config for this purpose, rather than, say, develop new autoconf tests. If you use the autoconf/automake tools, we recommend something along the following lines for your configure script:
dnl ################################################## dnl # Check for Broccoli dnl ################################################## AC_ARG_WITH(broccoli-config, AC_HELP_STRING([--with-broccoli-config=FILE], [Use given broccoli-config]), [ brocfg="$withval" ], [ AC_PATH_GENERIC(broccoli,, brocfg="broccoli-config", AC_MSG_ERROR(Cannot find Broccoli: Is broccoli-config in path? Use more fertilizer?)) ]) broccoli_libs=`$brocfg --libs` broccoli_cflags=`$brocfg --cflags` AC_SUBST(broccoli_libs) AC_SUBST(broccoli_cflags) |
You can then use the compiler/linker flags in your Makefile.in/ams by substituting in the values accordingly, which might look as follows:
CFLAGS = -W -Wall -g -DFOOBAR @broccoli_cflags@ LDFLAGS = -L/usr/lib/foobar @broccoli_libs@ |
Often you will want to make existing applications Bro-aware,
that is, instrument them so that they can send and
receive Bro events at appropriate moments in the execution flow.
This will involve modifying an existing code tree, so care needs to
be taken to avoid unwanted side effects. By protecting the instrumented
code with
#ifdef
/#endif
statements you can still build the original application, using the
instrumented source tree. The broccoli-config script helps you in doing so because
it already adds -DBROCCOLI
to the compiler flags
reported when run with the --cflags option:
cpk25@localhost:/home/cpk25 > broccoli-config --cflags -I/usr/local/include -I/usr/local/include -DBROCCOLI |
So simply surround all inserted code with a preprocessor check
for BROCCOLI
and you will be able to
build the original application as soon as BROCCOLI
is not defined.
Time for some code. In the code snippets below we will introduce variables whenever context requires them and not necessarily when C requires them. The library does not require calling a global initialization function. In order to make the API known, include broccoli.h:
#ifdef BROCCOLI #include <broccoli.h> #endif |
![]() | A note on Broccoli's memory management philosophy: Broccoli generally does not release objects you allocate. The approach taken is "you clean up what you allocate." |
Broccoli requires global initialization before most of its other other functions can be used. Generally, the way to initialize Broccoli is as follows:
bro_init(NULL); |
The argument to
bro_init()
NULL
for normal use. If required, you may
allocate a BroCtx structure locally,
initialize it using
bro_ctx_init()
bro_init()
BroCtx ctx; bro_ctx_init(&ctx); /* Make adjustments to the context structure as required... */ bro_init(&ctx); |
![]() | The BroCtx structure currently contains a set of five different callback function pointers. These are required for thread-safe operation of OpenSSL (Broccoli itself is thread-safe). If you intend to use Broccoli in a multithreaded environment, you need to implement functions and register them via the BroCtx structure. The O'Reilly book "Network Security with OpenSSL" by Viega et al. shows how to implement these callbacks. |
![]() | You must call
|