"Fossies" - the Fresh Open Source Software Archive

Member "scapy-2.4.5/scapy/layers/rtp.py" (18 Apr 2021, 1896 Bytes) of package /linux/privat/scapy-2.4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "rtp.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.4.3_vs_2.4.4.

    1 # This file is part of Scapy
    2 # See http://www.secdev.org/projects/scapy for more information
    3 # Copyright (C) Philippe Biondi <phil@secdev.org>
    4 # This program is published under a GPLv2 license
    5 
    6 """
    7 RTP (Real-time Transport Protocol).
    8 
    9 Remember to use::
   10 
   11     bind_layers(UDP, RTP, dport=XXX)
   12 
   13 To register the port you are using
   14 """
   15 
   16 from scapy.packet import Packet, bind_layers
   17 from 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 
   36 class 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 
   43 class 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 
   57 bind_layers(RTP, RTPExtension, extension=1)