Change in ...osmocom-bb[master]: trx_toolkit/trx_sniff.py: add support for reading from PCAP file

fixeria gerrit-no-reply at lists.osmocom.org
Tue Jul 23 20:02:01 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/14914


Change subject: trx_toolkit/trx_sniff.py: add support for reading from PCAP file
......................................................................

trx_toolkit/trx_sniff.py: add support for reading from PCAP file

Change-Id: I8a3481fbea5f6c917ae5684d0b5b806f4a76ff78
---
M src/target/trx_toolkit/trx_sniff.py
1 file changed, 23 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/14/14914/1

diff --git a/src/target/trx_toolkit/trx_sniff.py b/src/target/trx_toolkit/trx_sniff.py
index 6592455..45a5cf4 100755
--- a/src/target/trx_toolkit/trx_sniff.py
+++ b/src/target/trx_toolkit/trx_sniff.py
@@ -61,18 +61,29 @@
 		pkt_filter = "udp and (port %d or port %d)" \
 			% (self.argv.base_port + 2, self.argv.base_port + 102)
 
-		log.info("Listening on interface '%s'..." % self.argv.sniff_if)
+		# Arguments to be passed to scapy.all.sniff()
+		sniff_args = {
+			"prn" : self.pkt_handler,
+			"filter" : pkt_filter,
+			"store" : 0,
+		}
+
+		if self.argv.cap_file is not None:
+			log.info("Reading packets from '%s'..." % self.argv.cap_file)
+			sniff_args["offline"] = self.argv.cap_file
+		else:
+			log.info("Listening on interface '%s'..." % self.argv.sniff_if)
+			sniff_args["iface"] = self.argv.sniff_if
 
 		# Start sniffing...
-		scapy.all.sniff(iface = self.argv.sniff_if, store = 0,
-			filter = pkt_filter, prn = self.pkt_handler)
+		scapy.all.sniff(**sniff_args)
 
 		# Scapy registers its own signal handler
 		self.shutdown()
 
 	def pkt_handler(self, ether):
 		# Prevent loopback packet duplication
-		if self.argv.sniff_if == "lo":
+		if self.argv.sniff_if == "lo" and self.argv.cap_file is None:
 			self.lo_trigger = not self.lo_trigger
 			if not self.lo_trigger:
 				return
@@ -197,9 +208,6 @@
 		self.app_reg_logging_options(parser)
 
 		trx_group = parser.add_argument_group("TRX interface")
-		trx_group.add_argument("-i", "--sniff-interface",
-			dest = "sniff_if", type = str, default = "lo", metavar = "IF",
-			help = "Set network interface (default '%(default)s')")
 		trx_group.add_argument("-p", "--base-port",
 			dest = "base_port", type = int, default = 6700,
 			help = "Set base port number (default %(default)s)")
@@ -207,6 +215,14 @@
 			dest = "output_file", type = str,
 			help = "Write bursts to a capture file")
 
+		input_group = trx_group.add_mutually_exclusive_group()
+		input_group.add_argument("-i", "--sniff-interface",
+			dest = "sniff_if", type = str, default = "lo", metavar = "IF",
+			help = "Set network interface (default '%(default)s')")
+		input_group.add_argument("-r", "--capture-file",
+			dest = "cap_file", type = str, metavar = "FILE",
+			help = "Read packets from a PCAP file")
+
 		cnt_group = parser.add_argument_group("Count limitations (optional)")
 		cnt_group.add_argument("--frame-count", metavar = "N",
 			dest = "frame_count", type = int,

-- 
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/14914
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I8a3481fbea5f6c917ae5684d0b5b806f4a76ff78
Gerrit-Change-Number: 14914
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190723/b0bf874a/attachment.html>


More information about the gerrit-log mailing list