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   
