aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2023-10-23 00:34:16 +0100
committerJoão Valverde <j@v6e.pt>2023-10-23 10:39:28 +0000
commitc86a85022d73216bf478318797df45e5ced9e76b (patch)
treef1d94b977ab35293d967b086007ef82cfe3480f1
parent1ee70cf25f0ffaca749cde65add29b74a5f6c0bf (diff)
dfilter: Add "bitand" as an alternative operator keyword
It's more compact than "bitwise_and" and inspired by C.
-rw-r--r--doc/release-notes.adoc2
-rw-r--r--doc/wireshark-filter.adoc2
-rw-r--r--docbook/wsug_src/wsug_work.adoc18
-rw-r--r--epan/dfilter/scanner.l1
-rw-r--r--epan/proto.c1
-rw-r--r--test/suite_dfilter/group_syntax.py12
6 files changed, 26 insertions, 10 deletions
diff --git a/doc/release-notes.adoc b/doc/release-notes.adoc
index ab510e4a8d..3b6546e6bc 100644
--- a/doc/release-notes.adoc
+++ b/doc/release-notes.adoc
@@ -49,6 +49,8 @@ The following features are new (or have been significantly updated) since versio
the multiplier/divisor must be an integer or float and appear on the right-hand
side of the operator.
+ ** The keyword "bitand" can be used as an alternative syntax for the bitwise-and operator.
+
//=== Removed Features and Support
// === Removed Dissectors
diff --git a/doc/wireshark-filter.adoc b/doc/wireshark-filter.adoc
index f8d8de168b..cfe5027179 100644
--- a/doc/wireshark-filter.adoc
+++ b/doc/wireshark-filter.adoc
@@ -488,7 +488,7 @@ can be convenient:
It is also possible to define tests with bitwise operations. Currently the
following bitwise operator is supported:
- bitwise_and, & Bitwise AND
+ bitand, bitwise_and, & Bitwise AND
The bitwise AND operation allows masking bits and testing to see if one or
more bits are set. Bitwise AND operates on integer protocol fields and slices.
diff --git a/docbook/wsug_src/wsug_work.adoc b/docbook/wsug_src/wsug_work.adoc
index deff08bd92..0e55c097fd 100644
--- a/docbook/wsug_src/wsug_work.adoc
+++ b/docbook/wsug_src/wsug_work.adoc
@@ -830,16 +830,16 @@ You can perform the arithmetic operations on numeric fields shown in <<Arithmeti
[#ArithmeticOps]
.Display Filter Arithmetic Operations
-[options="header",cols="1,1,4"]
+[options="header",cols="1,1,1,4"]
|===
-|Name |Syntax | Description
-|Unary minus |-A | Negation of A
-|Addition |A + B | Add B to A
-|Subtraction |A - B | Subtract B from A
-|Multiplication |A * B | Multiply A times B
-|Division |A / B | Divide A by B
-|Modulo |A % B | Remainder of A divided by B
-|Bitwise AND |A & B | Bitwise AND of A and B
+|Name |Syntax | Alternative | Description
+|Unary minus |-A | | Negation of A
+|Addition |A + B | | Add B to A
+|Subtraction |A - B | | Subtract B from A
+|Multiplication |A * B | | Multiply A times B
+|Division |A / B | | Divide A by B
+|Modulo |A % B | | Remainder of A divided by B
+|Bitwise AND |A & B | A bitand B | Bitwise AND of A and B
|===
Arithmetic expressions can be grouped using curly braces.
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index 49fc4ce68c..2eca6cff2e 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -206,6 +206,7 @@ HexExponent ([pP][+-]?[[:digit:]]+)
"/" return math(TOKEN_RSLASH);
"%" return math(TOKEN_PERCENT);
"&" return math(TOKEN_BITWISE_AND);
+"bitand" return math(TOKEN_BITWISE_AND);
"bitwise_and" return math(TOKEN_BITWISE_AND);
"#" {
diff --git a/epan/proto.c b/epan/proto.c
index 4b2a223378..e3285d68c1 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -484,6 +484,7 @@ static const char *reserved_filter_names[] = {
"ge",
"lt",
"le",
+ "bitand",
"bitwise_and",
"contains",
"matches",
diff --git a/test/suite_dfilter/group_syntax.py b/test/suite_dfilter/group_syntax.py
index 699e516771..c118e498f3 100644
--- a/test/suite_dfilter/group_syntax.py
+++ b/test/suite_dfilter/group_syntax.py
@@ -218,6 +218,10 @@ class TestDfilterBitwise:
checkDFilterCount(dfilter, 1)
def test_exists_2(self, checkDFilterCount):
+ dfilter = "tcp.flags bitand 0x8"
+ checkDFilterCount(dfilter, 1)
+
+ def test_exists_3(self, checkDFilterCount):
dfilter = "eth[0] & 1"
checkDFilterCount(dfilter, 0)
@@ -229,6 +233,14 @@ class TestDfilterBitwise:
dfilter = "tcp.srcport != tcp.dstport & 0x0F"
checkDFilterCount(dfilter, 1)
+ def test_equal_3(self, checkDFilterCount):
+ dfilter = "tcp.srcport != tcp.dstport bitand 0x0F"
+ checkDFilterCount(dfilter, 1)
+
+ def test_equal_4(self, checkDFilterCount):
+ dfilter = "tcp.srcport != tcp.dstport bitwise_and 0x0F"
+ checkDFilterCount(dfilter, 1)
+
class TestDfilterUnaryMinus:
trace_file = "http.pcap"