mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
Iteration over vectors.
This commit is contained in:
parent
7d583b6b78
commit
c453c228cb
3 changed files with 27 additions and 4 deletions
|
@ -196,8 +196,6 @@ The table below shows the common data types used in Bro, of which, the first fou
|
||||||
| pattern | regular expression |
|
| pattern | regular expression |
|
||||||
+-----------+-------------------------------------+
|
+-----------+-------------------------------------+
|
||||||
|
|
||||||
Data Structures
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Vectors
|
Vectors
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -209,13 +207,23 @@ The format for the declaration of a Vector follows the pattern of other declarat
|
||||||
.. literalinclude:: ../../../../testing/btest/doc/manual/data_struct_vector_declaration.bro
|
.. literalinclude:: ../../../../testing/btest/doc/manual/data_struct_vector_declaration.bro
|
||||||
:language: bro
|
:language: bro
|
||||||
:linenos:
|
:linenos:
|
||||||
:lines: 6,7
|
:lines: 4-16
|
||||||
|
|
||||||
.. btest:: data_type_const.bro
|
.. btest:: data_type_const.bro
|
||||||
|
|
||||||
@TEST-EXEC: btest-rst-cmd bro -b ${TESTBASE}/doc/manual/data_struct_vector_declaration.bro
|
@TEST-EXEC: btest-rst-cmd bro -b ${TESTBASE}/doc/manual/data_struct_vector_declaration.bro
|
||||||
|
|
||||||
In a lot of cases, storing elements in a vector is simply a precursor to then iterating over them.
|
In a lot of cases, storing elements in a vector is simply a precursor to then iterating over them. Iterating over a vector is easy with the for keyword. The sample below iterates over a vector of IP addresses and for each IP address, masks that address with 18 bits.
|
||||||
|
|
||||||
|
.. literalinclude:: ../../../../testing/btest/doc/manual/data_struct_vector_iter.bro
|
||||||
|
:language: bro
|
||||||
|
:linenos:
|
||||||
|
:lines: 4-12
|
||||||
|
|
||||||
|
.. btest:: data_type_const.bro
|
||||||
|
|
||||||
|
@TEST-EXEC: btest-rst-cmd bro -b ${TESTBASE}/doc/manual/data_struct_vector_iter.bro
|
||||||
|
|
||||||
|
|
||||||
Sets
|
Sets
|
||||||
~~~~
|
~~~~
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
1.2.0.0/18
|
||||||
|
2.3.0.0/18
|
||||||
|
3.4.0.0/18
|
12
testing/btest/doc/manual/data_struct_vector_iter.bro
Normal file
12
testing/btest/doc/manual/data_struct_vector_iter.bro
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# @TEST-EXEC: bro %INPUT
|
||||||
|
# @TEST-EXEC: btest-diff .stdout
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
local addr_vector: vector of addr = vector( 1.2.3.4, 2.3.4.5, 3.4.5.6);
|
||||||
|
|
||||||
|
for (i in addr_vector)
|
||||||
|
{
|
||||||
|
print mask_addr(addr_vector[i], 18);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue