From b03ab7802e817bb29c127d3e153a4be4abb87c46 Mon Sep 17 00:00:00 2001
From: Martin Teichmann <martin.teichmann@gmail.com>
Date: Sun, 12 Feb 2023 10:48:40 +0000
Subject: [PATCH] ebpf can actually only do floor div

as Python makes a difference here, follow its logic and call
floor division as such.
---
 ebpfcat/ebpf.py      | 4 ++--
 ebpfcat/ebpf_test.py | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ebpfcat/ebpf.py b/ebpfcat/ebpf.py
index 7e5457d..84b6d41 100644
--- a/ebpfcat/ebpf.py
+++ b/ebpfcat/ebpf.py
@@ -439,8 +439,8 @@ class Expression:
     __sub__ = binary(Opcode.SUB)
     __rsub__ = rbinary(Opcode.SUB)
     __rmul__ = __mul__ = binary(Opcode.MUL)
-    __truediv__ = binary(Opcode.DIV)
-    __rtruediv__ = rbinary(Opcode.DIV)
+    __floordiv__ = binary(Opcode.DIV)
+    __rfloordiv__ = rbinary(Opcode.DIV)
     __ror__ = __or__ = binary(Opcode.OR)
     __lshift__ = binary(Opcode.LSH)
     __rlshift__ = rbinary(Opcode.LSH)
diff --git a/ebpfcat/ebpf_test.py b/ebpfcat/ebpf_test.py
index e39c6af..88928de 100644
--- a/ebpfcat/ebpf_test.py
+++ b/ebpfcat/ebpf_test.py
@@ -85,8 +85,8 @@ class Tests(TestCase):
         e.r4 -= e.r7
         e.r4 *= 3
         e.r4 *= e.r7
-        e.r4 /= 3
-        e.r4 /= e.r7
+        e.r4 //= 3
+        e.r4 //= e.r7
         e.r4 |= 3
         e.r4 |= e.r7
         e.r4 &= 3
@@ -554,7 +554,7 @@ class Tests(TestCase):
     def test_reverse_binary(self):
         e = EBPF()
         e.owners = {0, 1, 2, 3}
-        e.r3 = 7 / (e.r2 + 2)
+        e.r3 = 7 // (e.r2 + 2)
         e.r3 = 7 << e.r2
         e.r3 = 7 % (e.r2 + 3)
         e.r3 = 7 >> e.r2
-- 
GitLab