Skip to content

Commit 4cbc278

Browse files
committed
Print basic RTP/STUN packet info
1 parent 79c507e commit 4cbc278

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

xcloud/scripts/pcap_reader.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,35 @@
22
PCAP Parser for XCloud network traffic
33
"""
44
import argparse
5+
import logging
56

67
import dpkt
8+
from aiortc import rtp
9+
from aioice import stun
710
from construct.lib import containers
811

12+
from ..protocol import packets
913

14+
15+
logging.basicConfig(level=logging.DEBUG)
1016
containers.setGlobalPrintFullStrings(True)
17+
LOG = logging.getLogger(__name__)
18+
19+
def print_stun(stun: stun.Message) -> None:
20+
print(f'STUN: {stun}')
21+
22+
def print_rtp(rtp: rtp.RtpPacket) -> None:
23+
try:
24+
payload_name = packets.PayloadType(rtp.payload_type)
25+
except:
26+
payload_name = '<UNKNOWN>'
1127

28+
print(f'RTP: {payload_name.name} {rtp}')
29+
30+
PACKET_TYPES = [
31+
(stun.parse_message, print_stun),
32+
(rtp.RtpPacket.parse, print_rtp)
33+
]
1234

1335
def packet_filter(filepath):
1436
with open(filepath, 'rb') as fh:
@@ -28,8 +50,14 @@ def packet_filter(filepath):
2850

2951
def parse_file(pcap_filepath: str) -> None:
3052
for packet, timestamp in packet_filter(pcap_filepath):
31-
print(packet, timestamp)
32-
53+
packet = bytes(packet.data)
54+
for cls, print_func in PACKET_TYPES:
55+
try:
56+
instance = cls(packet)
57+
print_func(instance)
58+
except:
59+
pass
60+
3361

3462
def main():
3563
parser = argparse.ArgumentParser(

0 commit comments

Comments
 (0)