[Bro] deleting table entries

Dk Jack dnj0496 at gmail.com
Wed Dec 14 13:30:56 PST 2016


Hi,
Does bro scripting allow table entries to be deleted while iterating over
the entries of the table?
My test script below shows a weird behavior.

Is there a way to clear the entire contents of the table? I am collecting
sum-stats (epoch is 60s)
in a table during the epoch_result callback. Then in the epoch_finished
callback, I'd like to write
the summary results to a log. After that, I'd like to clear the table so
that its ready for the next
iteration. Iterating and deleting individual elements seems to have a
problem as shown in my
test script. Any help is appreciated. Thanks.

Dk.

global test_table: table[count] of count = table();

event bro_init()
{
  local c: count = 0;

  while (c < 100) {
    test_table[c] = c;
    c += 1;
  }

  print fmt("test_table size: %d", |test_table|);
}

event bro_done()
{
  while (|test_table| > 0) {
    print fmt("test_table size: %d", |test_table|);

    # this loop should walk all entries in one go. But it doesn't
    # because of the delete.
    for (c in test_table) {
      delete test_table[c];
    }
  }

  print fmt("test_table size: %d", |test_table|);
}

#test_table size: 100
#test_table size: 100
#test_table size: 43
#test_table size: 14
#test_table size: 1
#test_table size: 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/bro/attachments/20161214/669666b1/attachment.html 


More information about the Bro mailing list