
    Ϫf                         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y)z1Support for working directly with ethernet frames    N)	Interfaceimplementer)protocol)rawc                       e Zd ZdZd Zd Zy)IEthernetProtocolz6An interface for protocols that handle Ethernet framesc                      y)z"Add an IRawPacketProtocol protocolN )numprotos     7/usr/lib/python3/dist-packages/twisted/pair/ethernet.pyaddProtozIEthernetProtocol.addProto           c                      y)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      s    @12r   r   c                       e Zd Zd Zy)EthernetHeaderc                 \    t        j                  d|d d       \  | _        | _        | _        y )Nz!6s6sH   )structunpackdestsourcer   )selfr   s     r   __init__zEthernetHeader.__init__   s)    /5}}d;Y'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y)EthernetProtocolc                     i | _         y )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                  |   j	                  |       y )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(   so    &&u-7EFF%<@AAd&&&$&DS!$$U+r   c                     t        |d d       }| j                  j                  |j                  d      D ]9  }|j	                  |dd  ||j
                  |j                  |j                         ; y )Nr   r
   )r   r   r   r    r   )r   r&   getr   r   r   r    )r!   r   r   headerr   s        r   r   z!EthernetProtocol.datagramReceived2   sl    Sb	*%%))&,,; 	E"""#Y[[}} # 	r   N)r   )r   r   r   r"   r   r   r
   r   r   r$   r$   #   s    ,	r   r$   )r   r   zope.interfacer   r   twisted.internetr   twisted.pairr   r   r   AbstractDatagramProtocolr$   r
   r   r   <module>r2      sS    8  1 % 2	 2
 
 x88   r   