a
    kÄ#di  ã                	   @   s  d dl mZ d dlmZmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZeeed ddddd� eeedd� eeedd d� eeedd� dS )é    )Úprint_function)ÚPacketÚbind_layers)	ÚBitFieldÚByteEnumFieldÚ	ByteFieldÚFieldLenFieldÚFieldListFieldÚIPFieldÚPacketListFieldÚ
ShortFieldÚXShortField)Úorb)ÚIP)ÚIGMP)Úconfc                   @   s`   e Zd ZdZd ZddddddœZedd	eƒed
dƒeddƒgZ	dd„ Z
dd„ Zeddd„ƒZdS )ÚIGMPv3aœ  IGMP Message Class for v3.

    This class is derived from class Packet.
    The fields defined below are a
    direct interpretation of the v3 Membership Query Message.
    Fields 'type'  through 'qqic' are directly assignable.
    For 'numsrc', do not assign a value.
    Instead add to the 'srcaddrs' list to auto-set 'numsrc'. To
    assign values to 'srcaddrs', use the following methods::

      c = IGMPv3()
      c.srcaddrs = ['1.2.3.4', '5.6.7.8']
      c.srcaddrs += ['192.168.10.24']

    At this point, 'c.numsrc' is three (3)

    'chksum' is automagically calculated before the packet is sent.

    'mrcode' is also the Advertisement Interval field

    zMembership QueryzVersion 3 Membership ReportzMulticast Router AdvertisementzMulticast Router SolicitationzMulticast Router Termination)é   é"   é0   é1   é2   Útyper   Úmrcodeé   ÚchksumNc                 C   sj   | j }|dk r|}nL|dkr"d}n>d}|dL }|dkrH|d7 }|dL }q.|dK }d|B |d	@ B }|| _ d
S )a%  Encode and replace the mrcode value to its IGMPv3 encoded time value if needed,  # noqa: E501
        as specified in rfc3376#section-4.1.1.

        If value < 128, return the value specified. If >= 128, encode as a floating  # noqa: E501
        point value. Value can be 0 - 31744.
        é€   iÿ{  éÿ   r   é   é   é   é   é   N)r   )ÚselfÚvalueÚcodeÚexp© r'   úK/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/contrib/igmpv3.pyÚencode_maxrespcode@   s    
zIGMPv3.encode_maxrespcodec                 C   s&   t | jtƒr| j d¡S |  d¡S dS )z'Display a summary of the IGMPv3 object.z)IGMPv3: %IP.src% > %IP.dst% %IGMPv3.type%zIGMPv3 %IGMPv3.type%N)Ú
isinstanceZ
underlayerr   Úsprintf©r#   r'   r'   r(   Ú	mysummaryV   s    zIGMPv3.mysummaryc                 O   sH   |rDt |ƒdkrDt|d ƒdv r$tS t|d ƒdkrDt |ƒdk rDtS tS )Nr!   r   )é   é   é   r   é   )Úlenr   r   r   )ÚclsZ_pktÚargsZkargsr'   r'   r(   Údispatch_hook]   s    zIGMPv3.dispatch_hook)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameZigmpv3typesr   r   r   Úfields_descr)   r-   Úclassmethodr5   r'   r'   r'   r(   r      s    ü
þr   c                   @   sj   e Zd ZdZd Zeddƒedddƒedddƒed	dd
ƒeddƒedddd�e	ddeddƒdd„ d�gZ
dS )ÚIGMPv3mqz=IGMPv3 Membership Query.
    Payload of IGMPv3 when type=0x11Zgaddrú0.0.0.0Zresvr   r!   Úsr    Zqrvr   ZqqicÚnumsrcNÚsrcaddrs©Zcount_ofÚsac                 C   s   | j S ©N©r@   ©Úxr'   r'   r(   Ú<lambda>q   ó    zIGMPv3mq.<lambda>©Z
count_from)r6   r7   r8   r9   r:   r
   r   r   r   r	   r;   r'   r'   r'   r(   r=   g   s   


úr=   c                
   @   sx   e Zd ZdZd ZdddddddœZed	d
eƒeddƒedddd�e	ddƒe
dg e	ddƒdd„ d�gZdd„ Zdd„ ZdS )ÚIGMPv3grz®IGMP Group Record for IGMPv3 Membership Report

    This class is derived from class Packet and should be added in the records
    of an instantiation of class IGMPv3mr.
    zMode Is IncludezMode Is ExcludezChange To Include ModezChange To Exclude ModezAllow New SourceszBlock Old Sources)r    é   r   r!   é   é   Zrtyper    Zauxdlenr   r@   NrA   rB   Zmaddrr>   rC   c                 C   s   | j S rD   rE   rF   r'   r'   r(   rH   †   rI   zIGMPv3gr.<lambda>rJ   c                 C   s
   |   d¡S )z-Display a summary of the IGMPv3 group record.z4IGMPv3 Group Record %IGMPv3gr.type% %IGMPv3gr.maddr%)r+   r,   r'   r'   r(   r-   ˆ   s    zIGMPv3gr.mysummaryc                 C   s   t jS rD   )r   Zpadding_layer)r#   Úpayloadr'   r'   r(   Údefault_payload_classŒ   s    zIGMPv3gr.default_payload_class)r6   r7   r8   r9   r:   Zigmpv3grtypesr   r   r   r
   r	   r;   r-   rP   r'   r'   r'   r(   rK   t   s"   û
ürK   c                   @   s>   e Zd ZdZd Zeddƒedddd�edg edd	„ d
�gZ	dS )ÚIGMPv3mrzQIGMP Membership Report extension for IGMPv3.
    Payload of IGMPv3 when type=0x22Zres2r   ÚnumgrpNÚrecordsrB   c                 C   s   | j S rD   )rR   rF   r'   r'   r(   rH   –   rI   zIGMPv3mr.<lambda>rJ   )
r6   r7   r8   r9   r:   r   r   r   rK   r;   r'   r'   r'   r(   rQ   �   s   þrQ   c                   @   s(   e Zd ZdZd ZeddƒeddƒgZdS )Ú	IGMPv3mraz^IGMP Multicast Router Advertisement extension for IGMPv3.
    Payload of IGMPv3 when type=0x30ZqryIntvlr   ZrobustN)r6   r7   r8   r9   r:   r   r;   r'   r'   r'   r(   rT   ™   s
   ÿrT   rL   r    éÀ   z
224.0.0.22)ÚfragÚprotoÚttlZtosÚdstr   )r   r   )r   r   r   N)Ú
__future__r   Zscapy.packetr   r   Zscapy.fieldsr   r   r   r   r	   r
   r   r   r   Zscapy.compatr   Zscapy.layers.inetr   Zscapy.contrib.igmpr   Zscapy.configr   r   r=   rK   rQ   rT   r'   r'   r'   r(   Ú<module>   s(   ,H	ü