Record problem...

Hi
I am new to bro but really interested working in bro. I have already started the work. I am encountering a problem now.
It is about records. Let me explain wid the help of example:

type con: record
{
orig_h: addr;
orig_p: port;
resp_h: addr;
resp_p: port;
};

type con2: record
{

orig_h: addr;
orig_p: port;
resp_h: addr;
resp_p: port;
num_notices: count &optional;
};

function fun()
{
local id: con;
local id2: con2;
id2 = id;
}

This is giving segmentation fault , the statement id2=id. But in documentation of bro , they have said this is absolutely right. Please explain this.

Regards
Navdeep

local id: con;
local id2: con2;
id2 = id;

No, this assignment doesn't work because the two records have
different types; that's not defined. Bro shouldn't crash however but
better report an error at parse time. Could you file a bug report
with the Bro tracker for that? Thanks.

documentation of bro , they have said this is absolutely right. Please

That surprises me. Can you point to the location where the docs say
such an assignment is ok?

Robin

Hi Robin

Thanks for your help. I have got my mistake and what I wanted to do is done but now I come to you point that

local id: con;
local id2: con2;
id2 = id;

is not right but it is “WORKING”. Actaully read the following line is documentaion in reference manual under Record Assignment:

In order to produce a deep copy, use the clone operator copy(). For more details, see Expressions.

You can also assign to a record another record that has fields with the same names and types, even if they come in a different order.

So I have noticed that even if record types are different but the filed names and types inside these records are same then also we can assign them to each other.

copy paste the following and see the output:

type con: record
{
orig_h: addr;
};

type con2: record
{
orig_h: addr;
};

function fun()
{
local id: con;
local id2: con2;

id=id2;

}

fun();

Regards
Navdeep

Wow! In all my years with Bro, I have totally missed this little
gem. :slight_smile:

Thanks for pointing it out.

Robin