From bmorin at supelec-rennes.fr Mon Sep 18 07:29:55 2000 From: bmorin at supelec-rennes.fr (bmorin at supelec-rennes.fr) Date: Mon, 18 Sep 2000 16:29:55 +0200 Subject: add function problem Message-ID: <200009181431.QAA27778@hydromail.supelec-rennes.fr> Hello, could someone tell me why this peace of bro-code makes a segmentation fault? ------------------------------------------------- global sessions : set[conn_id]; event ftp_request(c:connection, command: string, arg:string) { add sessions[c$id]; } -------------------------------------------------- Thanks Benjamin Morin From bmorin at supelec-rennes.fr Tue Sep 19 05:50:42 2000 From: bmorin at supelec-rennes.fr (bmorin at supelec-rennes.fr) Date: Tue, 19 Sep 2000 14:50:42 +0200 Subject: No subject Message-ID: <200009191252.OAA22608@hydromail.supelec-rennes.fr> Hello, How can I add an element to a table, since I get a "run-time error" if I try to index a table with a value which is not in the table (as it is specified in the bro language)? Benjamin Morin From vern at ee.lbl.gov Wed Sep 20 02:27:49 2000 From: vern at ee.lbl.gov (Vern Paxson) Date: Wed, 20 Sep 2000 02:27:49 PDT Subject: add function problem In-Reply-To: Your message of Mon, 18 Sep 2000 16:29:55 PDT. Message-ID: <200009200927.e8K9Rnv15846@daffy.ee.lbl.gov> > could someone tell me why this peace of bro-code makes a segmentation fault? > > ------------------------------------------------- > > global sessions : set[conn_id]; > > event ftp_request(c:connection, command: string, arg:string) > { > add sessions[c$id]; > } > > -------------------------------------------------- Ouch, I don't know why that's happening, but I've added it to the to-fix list. But the more basic problem is that "add" is not currently supported. You need to instead use: global sessions: table[conn_id] of bool; event ftp_request(c:connection, command: string, arg:string) { sessions[c$id] = T; } - Vern From vern at ee.lbl.gov Wed Sep 20 02:30:22 2000 From: vern at ee.lbl.gov (Vern Paxson) Date: Wed, 20 Sep 2000 02:30:22 PDT Subject: adding elements to tables In-Reply-To: Your message of Tue, 19 Sep 2000 14:50:42 PDT. Message-ID: <200009200930.e8K9UMD15853@daffy.ee.lbl.gov> > How can I add an element to a table, since I get a "run-time error" if I try > to index a table with a value which is not in the table (as it is specified in > the bro language)? It's not clear to me what you're asking. If the problem is "how do I add a value to a table element if the table element might not be present yet", the answer is to test with the "in" operator: if ( foo in my_table ) my_table[foo] += additional_value; else my_table[foo] = additional_value; With the 0.7 release, you'll be able to specify default values for table entries, so this will look like: global my_table: table[foo_type] of count &default = 0; and then you can add to it using simply my_table[foo] += additional_value; Or are you asking about something different? Vern