# Changing an internal variable from C code

**URL:** <https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080>\
**Category:** Zeek\
**Created:** [December 8, 2006, 10:25am UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080 "2006-12-08T10:25:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Verma](https://avatars.discourse-cdn.com/v4/letter/v/48db29/32.png) [@Vishal\_Verma](https://community.zeek.org/u/Vishal_Verma)\
**Post date:** [December 8, 2006, 10:25am UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080/1 "2006-12-08T10:25:17Z")

</div>

Hi,

I wanted to change an internal variable from the C code. I have defined  
a variable in a .bro file as  
global my\_count: count;

At some later point in the C code, I want to change it:  
Val \*my\_count = internal\_val("my\_count");  
// change the value of my\_count to something else

I am at loss on how to accomplish this. Can the Bro gurus help me out?

thanks  
-vish

---

<div class="post-metadata">

**Author:** ![Ruoming\_Pang](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Ruoming\_Pang](https://community.zeek.org/u/Ruoming_Pang)\
**Post date:** [December 8, 2006, 4:20pm UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080/2 "2006-12-08T16:20:06Z")

</div>

Hi,

Please take a look at NetVar.{h,cc} as a starting point. That's where  
"internal variables" are defined.

By the way, which is the variable you want to manipulate in C++ code?

Ruoming

---

<div class="post-metadata">

**Author:** ![Vishal\_Verma](https://avatars.discourse-cdn.com/v4/letter/v/48db29/32.png) [@Vishal\_Verma](https://community.zeek.org/u/Vishal_Verma)\
**Post date:** [December 8, 2006, 5:52pm UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080/3 "2006-12-08T17:52:27Z")

</div>

> Please take a look at NetVar.{h,cc} as a starting point. That's where  
> "internal variables" are defined.

Net.cc doesn't seem to modify anything. I wanted to know how can I  
modify variables that are defined in the .bro files.

> By the way, which is the variable you want to manipulate in C++ code?

It's my own variable - a variable defined by my .bro file which is  
loaded on startup. I want to modify it later in the C++ code.

thanks!  
-vish

---

<div class="post-metadata">

**Author:** ![Ruoming\_Pang](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Ruoming\_Pang](https://community.zeek.org/u/Ruoming_Pang)\
**Post date:** [December 8, 2006, 6:07pm UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080/4 "2006-12-08T18:07:24Z")

</div>

> \> Please take a look at NetVar.{h,cc} as a starting point. That's where  
> \> "internal variables" are defined.
> 
> Net.cc doesn't seem to modify anything. I wanted to know how can I  
> modify variables that are defined in the .bro files.

Well, first, it's not Net.cc, but NetVar.cc. Are you looking at the  
right file? Second, the way it works is that you define a variable in  
NetVar.{h,cc} and also in bro.init. Then you can access the variable  
from both C++ and bro scripts.

> \> By the way, which is the variable you want to manipulate in C++ code?
> 
> It's my own variable - a variable defined by my .bro file which is  
> loaded on startup. I want to modify it later in the C++ code.

What does the variable represent? I'm curious about why you need an  
additional internal variable because they are not needed for most  
cases---that's why there are only a limited number of them.

Ruoming

---

<div class="post-metadata">

**Author:** ![Vishal\_Verma](https://avatars.discourse-cdn.com/v4/letter/v/48db29/32.png) [@Vishal\_Verma](https://community.zeek.org/u/Vishal_Verma)\
**Post date:** [December 8, 2006, 6:27pm UTC](https://community.zeek.org/t/changing-an-internal-variable-from-c-code/1080/5 "2006-12-08T18:27:18Z")

</div>

> \> Net.cc doesn't seem to modify anything. I wanted to know how can I  
> \> modify variables that are defined in the .bro files.
> 
> Well, first, it's not Net.cc, but NetVar.cc. Are you looking at the  
> right file? Second, the way it works is that you define a variable in  
> NetVar.{h,cc} and also in bro.init. Then you can access the variable  
> from both C++ and bro scripts.

Sorry about the typo... I did mean NetVar.cc. Accessing is one thing.. I  
know how to do it. Can you point me to an example where C++ code  
modifies it? Or give a li'l sample code.

> \> \> By the way, which is the variable you want to manipulate in C++ code?  
> \>  
> \> It's my own variable - a variable defined by my .bro file which is  
> \> loaded on startup. I want to modify it later in the C++ code.
> 
> What does the variable represent? I'm curious about why you need an  
> additional internal variable because they are not needed for most  
> cases---that's why there are only a limited number of them.

Well... it's a variable defined and required by my .bro module. I want  
to be able to send a signal to Bro and change its value... in C++ code.  
I want to use it to change Bro behavior.

thanks!  
-yp

---

<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/changing-an-internal-variable-from-c-code/1080/6 "2022-05-06T15:38:05Z")

</div>


