Include C++ header file in plugin function

Hi there,

I want to write a function as a plugin to convert a 4 byte hex string like “405f612f” to float/double (3.49031 in this case).

An easy way to do so in C++ is this:

#include <sstream>

union ulf
{
    unsigned long ul;
    float f;
};

int main()
{
    ulf u;
    string str = "405f612f";
    stringstream ss(str);
    ss >> hex >> u.ul;
    float f = u.f;
    cout << f << endl;
}

Unfortunatly, to use “stringstream” I will have to include the header file. Is this possible to do in plugin functions?

Thanks.

Dane

Unfortunatly, to use "stringstream" I will have to include the <sstream> header file. Is this possible to do in plugin functions?

Sure, plugins include libraries/other headers/etc. all the time.

Johanna

Hi Johanna,

I should've asked the question differently - If it is possible AND how I can do it. Sorry! :slight_smile:

But after a little bit of looking through the bro source code I found it.

%%{
#include <sstream>
%%}

Greetings

Dane