Key Pages: [ Rope Home Page | Basics (tutorial) | Language Reference | Download ]
"expect_one" is used to apply a number of alternative tests to the packet, and verify that one of them is passed.
The "expect_one" action takes any number of blocks (and therefore must be called with AnchorBrackets). It executes each block in turn until a block returns with a yes status. When a block returns yes, expect_one stops processing and returns the portion of the $packet that was spanned by the block.
Moreover, when expect_one starts it's execution, it takes an internal note of the value of $offset, and then resets it to it's original value at the start of each block.
If none of the blocks return yes, the expect_one returns no to IpTables.
All of which means ... you can use expect_one to check whether the packet matches one of a number of alternatives.
For example, the following script checks that the packet contains either a set of uppercase letters, or a set of four or more digits. If either of these patterns matches the packet, then that portion of it is printed. If neither pattern matches then the script terminates with a no status.
expect_one(
{
# Check for one or more letters
expect_while( {isupper} )
yes
} {
# Check for four or more digits
expect_while( {isdigit} )
strlen 4 ge assert
yes
}
)
println
Note that..
Lowth.com: [ Home | Rope | P2PWall | LinWiz | cutter | Protector - Free Antivirus software | TapeIO ]