Baby Bro, Part 1: Functions Etc.
[Note: Blogger seems to have done something nasty to my new blog template, so it's back to the old one at least temporarily]
Here's my first "Baby Bro" post. Before getting into using Bro scripting for its intended use of network traffic analysis, I wanted to figure out how to accomplish basic tasks common to most programming languages:
I'm not sure if I'll get through all of them in this series, but here's a start: a main dish of functions, with a side of string formatting and concatenation.
I think this is fairly self explanatory, given the comments. We have two functions:
We can run this from the CLI with no PCAP ingestion just to get the standard output:
jswan@so12a:~/bro$ bro test.bro
3 + 1 = 4
first second
Here's my first "Baby Bro" post. Before getting into using Bro scripting for its intended use of network traffic analysis, I wanted to figure out how to accomplish basic tasks common to most programming languages:
- Functions
- Common types and variable definitions
- Loops
- Conditionals
- Iteration of container types
- Basic string and arithmetic operations
I'm not sure if I'll get through all of them in this series, but here's a start: a main dish of functions, with a side of string formatting and concatenation.
1 | 1 # "add one" is the function name |
I think this is fairly self explanatory, given the comments. We have two functions:
- add_one: adds one to whatever integer is passed into the function, and returns the resulting integer.
- concat: concatenates two strings, separated by a space, and returns the result. There is a built-in string function for this, but I wanted to show that you can also do it with "+".
We can run this from the CLI with no PCAP ingestion just to get the standard output:
jswan@so12a:~/bro$ bro test.bro
3 + 1 = 4
first second