# Record problem...

**URL:** <https://community.zeek.org/t/record-problem/1523>\
**Category:** Zeek\
**Created:** [August 1, 2009, 1:37pm UTC](https://community.zeek.org/t/record-problem/1523 "2009-08-01T13:37:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navdeep\_Singh1](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Navdeep\_Singh1](https://community.zeek.org/u/Navdeep_Singh1)\
**Post date:** [August 1, 2009, 1:37pm UTC](https://community.zeek.org/t/record-problem/1523/1 "2009-08-01T13:37:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [August 3, 2009, 4:02pm UTC](https://community.zeek.org/t/record-problem/1523/2 "2009-08-03T16:02:42Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Navdeep\_Singh1](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@Navdeep\_Singh1](https://community.zeek.org/u/Navdeep_Singh1)\
**Post date:** [August 4, 2009, 6:14am UTC](https://community.zeek.org/t/record-problem/1523/3 "2009-08-04T06:14:02Z")

</div>

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](http://www.bro-ids.org/wiki/index.php/Reference_Manual:_Statements_and_Expressions#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

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [August 4, 2009, 6:50pm UTC](https://community.zeek.org/t/record-problem/1523/4 "2009-08-04T18:50:58Z")

</div>

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

Thanks for pointing it out.

Robin

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:38pm UTC](https://community.zeek.org/t/record-problem/1523/5 "2022-05-06T15:38:55Z")

</div>


