U
    
W[                     @   sp   d Z ddlZddlmZ ddlmZ ddlmZ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)protocol)raw)implementer	Interfacec                   @   s    e Zd ZdZdd Zdd ZdS )IEthernetProtocolz6An interface for protocols that handle Ethernet framesc                   C   s   dS )z"Add an IRawPacketProtocol protocolN r   r   r   7/usr/lib/python3/dist-packages/twisted/pair/ethernet.pyaddProto   s    zIEthernetProtocol.addProtoc                   C   s   dS )z#An Ethernet frame has been receivedNr   r   r   r   r   datagramReceived   s    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   )structZunpackdestsourceproto)selfdatar   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kr>g | j|< | j| | d S )Nr   z'Added protocol must be positive or zeroi   z"Added protocol must fit in 16 bits)r   ZIRawPacketProtocol	TypeErrorr   append)r   Znumr   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   partialr   r   r   )r   r   getr   r
   r   r   )r   r   r   headerr   r   r   r   r
   1   s    z!EthernetProtocol.datagramReceivedN)r   )r   r   r   r   r	   r
   r   r   r   r   r   "   s   
r   )r   r   Ztwisted.internetr   Ztwisted.pairr   Zzope.interfacer   r   r   r   ZAbstractDatagramProtocolr   r   r   r   r   <module>   s   