Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/scapy/layers/rtp.py: 92%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1# SPDX-License-Identifier: GPL-2.0-only 

2# This file is part of Scapy 

3# See https://scapy.net/ for more information 

4# Copyright (C) Philippe Biondi <phil@secdev.org> 

5 

6""" 

7RTP (Real-time Transport Protocol). 

8 

9Remember to use:: 

10 

11 bind_layers(UDP, RTP, dport=XXX) 

12 

13To register the port you are using 

14""" 

15 

16from scapy.packet import Packet, bind_layers 

17from scapy.fields import BitEnumField, BitField, BitFieldLenField, \ 

18 FieldLenField, FieldListField, IntField, ShortField 

19 

20_rtp_payload_types = { 

21 # http://www.iana.org/assignments/rtp-parameters 

22 0: 'G.711 PCMU', 3: 'GSM', 

23 4: 'G723', 5: 'DVI4', 

24 6: 'DVI4', 7: 'LPC', 

25 8: 'PCMA', 9: 'G722', 

26 10: 'L16', 11: 'L16', 

27 12: 'QCELP', 13: 'CN', 

28 14: 'MPA', 15: 'G728', 

29 16: 'DVI4', 17: 'DVI4', 

30 18: 'G729', 25: 'CelB', 

31 26: 'JPEG', 28: 'nv', 

32 31: 'H261', 32: 'MPV', 

33 33: 'MP2T', 34: 'H263'} 

34 

35 

36class RTPExtension(Packet): 

37 name = "RTP extension" 

38 fields_desc = [ShortField("header_id", 0), 

39 FieldLenField("header_len", None, count_of="header", fmt="H"), # noqa: E501 

40 FieldListField('header', [], IntField("hdr", 0), count_from=lambda pkt: pkt.header_len)] # noqa: E501 

41 

42 

43class RTP(Packet): 

44 name = "RTP" 

45 fields_desc = [BitField('version', 2, 2), 

46 BitField('padding', 0, 1), 

47 BitField('extension', 0, 1), 

48 BitFieldLenField('numsync', None, 4, count_of='sync'), 

49 BitField('marker', 0, 1), 

50 BitEnumField('payload_type', 0, 7, _rtp_payload_types), 

51 ShortField('sequence', 0), 

52 IntField('timestamp', 0), 

53 IntField('sourcesync', 0), 

54 FieldListField('sync', [], IntField("id", 0), count_from=lambda pkt:pkt.numsync)] # noqa: E501 

55 

56 

57bind_layers(RTP, RTPExtension, extension=1)