
    \d                         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e          Z	 G d d	          Z
 ee	           G d
 dej                              ZdS )z1Support for working directly with ethernet frames    N)	Interfaceimplementer)protocol)rawc                       e Zd ZdZd Zd ZdS )IEthernetProtocolz6An interface for protocols that handle Ethernet framesc                     dS )z"Add an IRawPacketProtocol protocolN )numprotos     5lib/python3.11/site-packages/twisted/pair/ethernet.pyaddProtozIEthernetProtocol.addProto             c                     dS )z#An Ethernet frame has been receivedNr
   )datapartials     r   datagramReceivedz"IEthernetProtocol.datagramReceived   r   r   N)__name__
__module____qualname____doc__r   r   r
   r   r   r   r      s8        @@1 1 12 2 2 2 2r   r   c                       e Zd Zd ZdS )EthernetHeaderc                 f    t          j        d|d d                   \  | _        | _        | _        d S )Nz!6s6sH   )structunpackdestsourcer   )selfr   s     r   __init__zEthernetHeader.__init__   s2    /5}d;Y;'0
 0
,DKr   N)r   r   r   r"   r
   r   r   r   r      s#        
 
 
 
 
r   r   c                   "    e Zd Zd Zd ZddZdS )EthernetProtocolc                     i | _         d S )N)etherProtos)r!   s    r   r"   zEthernetProtocol.__init__&   s    r   c                     t          j        |          }|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   s      r   r   zEthernetProtocol.addProto)   s    &u--77EFFF'>>@AAAd&&&$&DS!$$U+++++r   r   c                     t          |d d                   }| j                            |j        d          D ]3}|                    |dd          ||j        |j        |j                   4d S )Nr   r
   )r   r   r   r    r   )r   r&   getr   r   r   r    )r!   r   r   headerr   s        r   r   z!EthernetProtocol.datagramReceived3   s    SbS	**%))&,;; 	 	E"""##Y[} #    	 	r   N)r   )r   r   r   r"   r   r   r
   r   r   r$   r$   $   sF          , , ,	 	 	 	 	 	r   r$   )r   r   zope.interfacer   r   twisted.internetr   twisted.pairr   r   r   AbstractDatagramProtocolr$   r
   r   r   <module>r2      s    8 7  1 1 1 1 1 1 1 1 % % % % % %      2 2 2 2 2	 2 2 2
 
 
 
 
 
 
 
     x8      r   