o
    ¯b”  ã                   @   sp   d Z ddlZddlmZmZ ddlmZ ddlmZ G dd„ deƒZ	G dd	„ d	ƒZ
ee	ƒG d
d„ dejƒƒZdS )z1Support for working directly with ethernet framesé    N)Ú	InterfaceÚimplementer)Úprotocol)Úrawc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚIEthernetProtocolz6An interface for protocols that handle Ethernet framesc                 C   ó   dS )z"Add an IRawPacketProtocol protocolN© )ÚnumÚprotor   r   ú7/usr/lib/python3/dist-packages/twisted/pair/ethernet.pyÚaddProto   ó    zIEthernetProtocol.addProtoc                 C   r   )z#An Ethernet frame has been receivedNr   )ÚdataÚpartialr   r   r   ÚdatagramReceived   r   z"IEthernetProtocol.datagramReceivedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   c                   @   s   e Zd Zdd„ ZdS )ÚEthernetHeaderc                 C   s$   t  d|d d… ¡\| _| _| _d S )Nz!6s6sHé   )ÚstructÚunpackÚdestÚsourcer
   )Úselfr   r   r   r   Ú__init__   s   ÿzEthernetHeader.__init__N)r   r   r   r   r   r   r   r   r      s    r   c                   @   s&   e Zd Zdd„ Zdd„ Zd	dd„ZdS )
ÚEthernetProtocolc                 C   s
   i | _ d S )N)ÚetherProtos)r   r   r   r   r   &   s   
zEthernetProtocol.__init__c                 C   sR   t  |¡}|dk rtdƒ‚|dkrtdƒ‚|| jvrg | j|< | j|  |¡ d S )Nr   z'Added protocol must be positive or zeroi   z"Added protocol must fit in 16 bits)r   ÚIRawPacketProtocolÚ	TypeErrorr   Úappend)r   r	   r
   r   r   r   r   )   s   


zEthernetProtocol.addProtor   c                 C   sL   t |d d… ƒ}| j |jd¡D ]}|j|dd … ||j|j|jd� qd S )Nr   r   )r   r   r   r   r   )r   r   Úgetr
   r   r   r   )r   r   r   Úheaderr
   r   r   r   r   3   s   
ûÿz!EthernetProtocol.datagramReceivedN)r   )r   r   r   r   r   r   r   r   r   r   r   $   s    
r   )r   r   Úzope.interfacer   r   Útwisted.internetr   Útwisted.pairr   r   r   ÚAbstractDatagramProtocolr   r   r   r   r   Ú<module>   s   
