ó
    Ö›‘hÕ1  ã                   óº  • S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJrJr  SSKJrJr  SSKJr  SSKJrJrJrJrJr  SS	KJrJr  SS
KJr  SSKJ r   SSK!J"r"  SSK#J$r$J%r%  / SQr&Sr'\RP                  " 5       S:X  dJ  \RP                  " 5       RS                  S5      (       d%  \RP                  " 5       RS                  S5      (       a  Sr*Sr+OSr*Sr+Sr, " S S\5      r-\" \R\                  5       " S S\%\$5      5       r/ " S S\" SS5      5      r0 " S S \5      r1 " S! S"5      r2\" \Rf                  5       " S# S$\Rh                  5      5       r5g)%zc
Support for Linux ethernet and IP tunnel devices.

@see: U{https://en.wikipedia.org/wiki/TUN/TAP}
é    N)Ú
namedtuple)ÚTuple)Ú	AttributeÚ	InterfaceÚimplementer)ÚFlagConstantÚFlags)ÚVersion)ÚabstractÚdeferÚerrorÚ
interfacesÚtask)ÚethernetÚraw)Úlog)Ú
deprecated)ÚfullyQualifiedName)ÚFancyEqMixinÚFancyStrMixin)ÚTunnelFlagsÚTunnelAddressÚ
TuntapPorté   ÚpariscÚppcÚsparcl   ÊT  iÒT@iÊT@l   ÒT  s   /dev/net/tunc                   óØ   • \ rS rSrSr\" S5      r\" S5      r\" S5      r\" S5      r	\" S5      r
\" S5      r\" S	5      r\" S
5      r\" S5      r\" S5      r\" S5      r\" S5      rSrg)r   é6   aV  
L{TunnelFlags} defines more flags which are used to configure the behavior
of a tunnel device.

@cvar IFF_TUN: This indicates a I{tun}-type device.  This type of tunnel
    carries IP datagrams.  This flag is mutually exclusive with C{IFF_TAP}.

@cvar IFF_TAP: This indicates a I{tap}-type device.  This type of tunnel
    carries ethernet frames.  This flag is mutually exclusive with C{IFF_TUN}.

@cvar IFF_NO_PI: This indicates the I{protocol information} header will
    B{not} be included in data read from the tunnel.

@see: U{https://www.kernel.org/doc/Documentation/networking/tuntap.txt}
é   é   r   é    é@   é€   é   i   i   é    i @  i €  © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚIFF_TUNÚIFF_TAPÚ
TUN_FASYNCÚTUN_NOCHECKSUMÚ	TUN_NO_PIÚTUN_ONE_QUEUEÚTUN_PERSISTÚTUN_VNET_HDRÚ	IFF_NO_PIÚIFF_ONE_QUEUEÚIFF_VNET_HDRÚIFF_TUN_EXCLÚ__static_attributes__r'   ó    ÚWC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/pair/tuntap.pyr   r   6   s�   † ññ  ˜6Ó"€GÙ˜6Ó"€Gá˜fÓ%€JÙ! &Ó)€NÙ˜VÓ$€IÙ  Ó(€MÙ˜vÓ&€KÙ Ó'€Lá˜VÓ$€IÙ  Ó(€MÙ Ó'€LÙ Ó'ƒLr:   r   c                   óF   • \ rS rSrSrSrSS 4S4r\S 5       rS r	S	 r
S
rg)r   éW   zM
A L{TunnelAddress} represents the tunnel to which a L{TuntapPort} is bound.
)Ú
_typeValueÚnameÚtypec                 ó   • U R                   $ ©N)r?   )Úflags    r;   Ú<lambda>ÚTunnelAddress.<lambda>^   s   € ¨D¯IªIr:   r?   c                 ó.   • U R                   R                  $ )zu
Return the integer value of the C{type} attribute.  Used to produce
correct results in the equality implementation.
)r@   Úvalue©Úselfs    r;   r>   ÚTunnelAddress._typeValue`   s   € ð �y‰y�‰Ðr:   c                 ó   • Xl         X l        g)z³
@param type: Either L{TunnelFlags.IFF_TUN} or L{TunnelFlags.IFF_TAP},
    representing the type of this tunnel.

@param name: The system name of the tunnel.
@type name: L{bytes}
N)r@   r?   )rI   r@   r?   s      r;   Ú__init__ÚTunnelAddress.__init__i   s   € ð Œ	Ø�	r:   c                 óX   • [         R                  " S[        SS9  SU R                  4U   $ )zC
Deprecated accessor for the tunnel name.  Use attributes instead.
zUTunnelAddress.__getitem__ is deprecated since Twisted 14.0.0  Use attributes instead.r!   )ÚcategoryÚ
stacklevelÚTUNTAP)ÚwarningsÚwarnÚDeprecationWarningr?   )rI   Úindexs     r;   Ú__getitem__ÚTunnelAddress.__getitem__t   s1   € ô 	�Šð&ä'Øò		
ð ˜$Ÿ)™)Ð$ UÑ+Ð+r:   )r?   r@   N)r(   r)   r*   r+   r,   ÚcompareAttributesÚshowAttributesÚpropertyr>   rL   rV   r9   r'   r:   r;   r   r   W   s;   † ñð /ÐØÑ5Ð6¸Ð?€Nàñó ðò	õ
,r:   r   c                   ó   • \ rS rSrSrSrg)Ú_TunnelDescriptioné�   zª
Describe an existing tunnel.

@ivar fileno: the file descriptor associated with the tunnel
@type fileno: L{int}

@ivar name: the name of the tunnel
@type name: L{bytes}
r'   N)r(   r)   r*   r+   r,   r9   r'   r:   r;   r\   r\   �   s   † ôr:   r\   zfileno namec                   óz   • \ rS rSrSr\" S5      r\" S5      r\" S5      rSS jr	SS jr
S	 rS
 rS rS rS rSrg)Ú_IInputOutputSystemé�   zŠ
An interface for performing some basic kinds of I/O (particularly that I/O
which might be useful for L{twisted.pair.tuntap}-using code).
z@see: L{os.O_RDWR}z@see: L{os.O_NONBLOCK}z@see: L{os.O_CLOEXEC}c                 ó   • g)z
@see: L{os.open}
Nr'   )ÚfilenamerC   Úmodes      r;   ÚopenÚ_IInputOutputSystem.open—   ó   � r:   Nc                 ó   • g)z
@see: L{fcntl.ioctl}
Nr'   )ÚfdÚoptÚargÚmutate_flags       r;   ÚioctlÚ_IInputOutputSystem.ioctlœ   rf   r:   c                 ó   • g)z
@see: L{os.read}
Nr'   )rh   Úlimits     r;   ÚreadÚ_IInputOutputSystem.read¡   rf   r:   c                 ó   • g)z
@see: L{os.write}
Nr'   )rh   Údatas     r;   ÚwriteÚ_IInputOutputSystem.write¦   rf   r:   c                 ó   • g)z
@see: L{os.close}
Nr'   )rh   s    r;   ÚcloseÚ_IInputOutputSystem.close«   rf   r:   c                 ó   • g)aL  
Send a datagram to a certain address.

@param datagram: The payload of a UDP datagram to send.
@type datagram: L{bytes}

@param address: The destination to which to send the datagram.
@type address: L{tuple} of (L{bytes}, L{int})

@return: The local address from which the datagram was sent.
@rtype: L{tuple} of (L{bytes}, L{int})
Nr'   )ÚdatagramÚaddresss     r;   ÚsendUDPÚ_IInputOutputSystem.sendUDP°   rf   r:   c                 ó   • g)aþ  
Return a socket which can be used to receive datagrams sent to the
given address.

@param fileno: A file descriptor representing a tunnel device which the
    datagram was either sent via or will be received via.
@type fileno: L{int}

@param host: The IPv4 address at which the datagram will be received.
@type host: L{bytes}

@param port: The UDP port number at which the datagram will be
    received.
@type port: L{int}

@return: A L{socket.socket} which can be used to receive the specified
    datagram.
Nr'   )ÚfilenoÚhostÚports      r;   Ú
receiveUDPÚ_IInputOutputSystem.receiveUDP¾   rf   r:   r'   )iÿ  )NN)r(   r)   r*   r+   r,   r   ÚO_RDWRÚ
O_NONBLOCKÚ	O_CLOEXECrd   rl   rp   rt   rw   r|   r‚   r9   r'   r:   r;   r_   r_   �   sM   † ññ
 Ð+Ó,€FÙÐ3Ó4€JÙÐ1Ó2€Iôô
ò
ò
ò
ò
õr:   r_   c                   ó  • \ rS rSrSr\" \R                  5      r\" \R                  5      r\" \R                  5      r	\" \R                  5      r
\" \R                  5      r\R                  r\R                  r\" \SS5      rSrg)Ú_RealSysteméÓ   z�
An interface to the parts of the operating system which L{TuntapPort}
relies on.  This is most of an implementation of L{_IInputOutputSystem}.
r†   i   r'   N)r(   r)   r*   r+   r,   ÚstaticmethodÚosrd   rp   rt   rw   Úfcntlrl   r„   r…   Úgetattrr†   r9   r'   r:   r;   rˆ   rˆ   Ó   sq   † ññ
 ˜Ÿ™Ó €DÙ˜Ÿ™Ó €DÙ˜Ÿ™Ó"€EÙ˜Ÿ™Ó"€EÙ˜Ÿ™Ó%€Eà�Y‰Y€FØ—‘€Jñ ˜˜K¨Ó3ƒIr:   rˆ   c                   óª   • \ rS rSrSrSrSS jrS\4S jrS r	S	 r
S
 rS rS rS rS rS r\" \" SSSS5      \5      S 5       rSS jrS rS rSrg)r   éæ   z@
A Port that reads and writes packets from/to a TUN/TAP-device.
i   Nc                 ó
  • [         R                  R                  U5      (       a  SU l         [        R                  U l        OBSU l         [        R                  U l        [        R                  R                  U5      (       d   eUc
  [        5       nXPl
        [        R                  R                  X5        Xl        X l        X0l        U R#                  U R                  5      nU SU R
                  R$                   S3U l        g )Nr    r   z (Ú))r   ÚIEthernetProtocolÚ
providedByr   r.   Ú_moder-   r   ÚIRawPacketProtocolrˆ   Ú_systemr   ÚFileDescriptorrL   Ú	interfaceÚprotocolÚmaxPacketSizeÚ_getLogPrefixr?   Úlogstr)rI   r˜   Úprotorš   ÚreactorÚsystemÚ	logPrefixs          r;   rL   ÚTuntapPort.__init__î   sÄ   € Ü×%Ñ%×0Ñ0°×7Ñ7ØˆDŒMÜ$×,Ñ,ˆD�JàˆDŒMÜ$×,Ñ,ˆDŒJÜ×)Ñ)×4Ñ4°U×;Ñ;Ð;Ð;à‰>Ü “]ˆFØŒä×Ñ×(Ñ(¨Ô7Ø"ŒØŒØ*Ôà×&Ñ& t§}¡}Ó5ˆ	Ø"˜ 2 d§j¡j§o¡oÐ%6°aÐ8ˆ�r:   Úreturnc                 óÌ   • [        U R                  R                  5      4nU R                  (       a  US-   nOUS-   nXR                  R
                  U R                  4-   nSU-  $ )N)Ú )znot z<%s %slistening on %s/%s>)r   r™   Ú	__class__Ú	connectedr”   r?   r˜   )rI   Úargss     r;   Ú__repr__ÚTuntapPort.__repr__  sW   € Ü!3°D·M±M×4KÑ4KÓ!LÐ NˆØ�>�>Ø˜%‘<‰Dà˜)Ñ#ˆDØ—z‘z—‘¨¯©Ð7Ñ7ˆØ*¨TÑ1Ð1r:   c                 óz   • U R                  5         U R                  R                  U 5        U R                  5         g)z�
Create and bind my socket, and begin listening on it.

This must be called after creating a server to begin listening on the
specified tunnel.
N)Ú_bindSocketr™   ÚmakeConnectionÚstartReadingrH   s    r;   ÚstartListeningÚTuntapPort.startListening  s.   € ð 	×ÑÔØ�‰×$Ñ$ TÔ*Ø×ÑÕr:   c                 ó   • U R                   R                  U R                   R                  -  U R                   R                  -  n[        R
                  " S[        4-  XR                  5      nU R                   R                  [        U5      nU R                   R                  U[        U5      n[        XVS[         R                  S5      5      $ )a.  
Open the named tunnel using the given mode.

@param name: The name of the tunnel to open.
@type name: L{bytes}

@param mode: Flags from L{TunnelFlags} with exactly one of
    L{TunnelFlags.IFF_TUN} or L{TunnelFlags.IFF_TAP} set.

@return: A L{_TunnelDescription} representing the newly opened tunnel.
z%dsHNó    )r–   r„   r†   r…   ÚstructÚpackÚ	_IFNAMSIZrG   rd   Ú_TUN_KO_PATHrl   Ú
_TUNSETIFFr\   Ústrip)rI   r?   rc   ÚflagsÚconfigr   Úresults          r;   Ú_openTunnelÚTuntapPort._openTunnel  s—   € ð —‘×#Ñ# d§l¡l×&<Ñ&<Ñ<¸t¿|¹|×?VÑ?VÑVˆÜ—’˜V¤y lÑ2°D¿*¹*ÓEˆØ—‘×"Ñ"¤<°Ó7ˆØ—‘×#Ñ# F¬J¸Ó?ˆÜ! &°´)Ð*<×*BÑ*BÀ7Ó*KÓLÐLr:   c                 ón  • [         R                  " SU R                  R                  U R                  S9   U R                  U R                  U R                  [        R                  -  5      u  pX l        Xl        SU l        g! [         a'  n[        R                  " SU R                  U5      eSnAff = f)z
Open the tunnel.
z&%(protocol)s starting on %(interface)s)Úformatr™   r˜   Nr    )r   Úmsgr™   r¥   r˜   r»   r”   r   r5   ÚOSErrorr   ÚCannotListenErrorÚ_filenor¦   )rI   r   r˜   Úes       r;   r«   ÚTuntapPort._bindSocket)  s˜   € ô 	�ŠØ;Ø—]‘]×,Ñ,Ø—n‘nò	
ð
	CØ $× 0Ñ 0Ø—‘ §
¡
¬[×-BÑ-BÑ Bó!ÑˆFð #ŒØŒàˆ�øô ó 	CÜ×)Ò)¨$°·±ÀÓBÐBûð	Cús   ¶9B Â
B4Â"B/Â/B4c                 ó   • U R                   $ rB   )rÂ   rH   s    r;   r   ÚTuntapPort.fileno>  s   € Ø�|‰|Ðr:   c                 óP  • SnXR                   :  al   U R                  R                  U R                  U R                  5      nU[        U5      -  n U R                  R                  USS9  XR                   :  a  Mk  gg! [
         aH  nUR                  [        R                  [        R                  [        R                  4;   a   SnAge SnAf[         a    e f = f! [         a=    [        U R                  R                  5      n[         R"                  " SSU S35         N¸f = f)z-
Called when my socket is ready for reading.
r   N)ÚpartialzUnhandled exception from z.datagramReceived)ÚmaxThroughputr–   rp   rÂ   rš   rÀ   ÚerrnoÚEWOULDBLOCKÚEAGAINÚEINTRÚBaseExceptionÚlenr™   ÚdatagramReceivedr   r¥   r   Úerr)rI   rp   rs   rÃ   Úclss        r;   ÚdoReadÚTuntapPort.doReadA  sø   € ð ˆØ×'Ñ'Ó'ðØ—|‘|×(Ñ(¨¯©°t×7IÑ7IÓJ�ð ”C˜“IÑˆDðRØ—‘×.Ñ.¨t¸QÐ.Ñ?ð ×'Ñ'×'øô ó Ø—7‘7œu×0Ñ0´%·,±,ÄÇÁÐLÓLÜàûÜ ó Øðûô !ó RÜ(¨¯©×)@Ñ)@ÓA�Ü—’˜Ð 9¸#¸Ð>OÐPÖQðRús0   “0A? ÁC Á?
CÂ	=CÃCÃCÃAD%Ä$D%c                 óÞ   •  U R                   R                  U R                  U5      $ ! [         a:  nUR                  [        R
                  :X  a  U R                  U5      s SnA$ e SnAff = f)z›
Write the given data as a single datagram.

@param datagram: The data that will make up the complete datagram to be
    written.
@type datagram: L{bytes}
N)r–   rt   rÂ   rÀ   rÊ   rÍ   )rI   rz   rÃ   s      r;   rt   ÚTuntapPort.writeX  sT   € ð	Ø—<‘<×%Ñ% d§l¡l°HÓ=Ð=øÜó 	Ø�w‰wœ%Ÿ+™+Ó%Ø—z‘z (Ó+Õ+Øûð	ús    ‚%( ¨
A,².A'Á A,Á&A'Á'A,c                 óD   • U R                  SR                  U5      5        g)zª
Write a datagram constructed from a L{list} of L{bytes}.

@param seq: The data that will make up the complete datagram to be
    written.
@type seq: L{list} of L{bytes}
r:   N)rt   Újoin)rI   Úseqs     r;   ÚwriteSequenceÚTuntapPort.writeSequenceg  s   € ð 	�
‰
�3—8‘8˜C“=Õ!r:   c                 ó2  • U R                  5         U R                  (       a  U R                  $ U R                  (       aD  [        R
                  " U R                  SU R                  5      U l        SU l        U R                  $ [        R                  " S5      $ )z¨
Stop accepting connections on this port.

This will shut down my socket and call self.connectionLost().

@return: A L{Deferred} that fires when this port has stopped.
r   TN)
ÚstopReadingÚdisconnectingÚ_stoppedDeferredr¦   r   Ú
deferLaterrž   ÚconnectionLostr   ÚsucceedrH   s    r;   ÚstopListeningÚTuntapPort.stopListeningq  ss   € ð 	×ÑÔØ××Ø×(Ñ(Ð(Ø�^�^Ü$(§O¢OØ—‘˜a ×!4Ñ!4ó%ˆDÔ!ð "&ˆDÔØ×(Ñ(Ð(ä—=’= Ó&Ð&r:   ÚTwistedé   r   c                 ó^   • U R                  5       R                  [        R                  5        g)z>
Close this tunnel.  Use L{TuntapPort.stopListening} instead.
N)rã   Ú
addErrbackr   rÑ   rH   s    r;   ÚloseConnectionÚTuntapPort.loseConnection…  s   € ð
 	×ÑÓ×'Ñ'¬¯©Õ0r:   c                 ó"  • [         R                  " SU R                  -  5        [        R                  R                  X5        U R                  R                  5         SU l        U R                  R                  U R                  5        SU l        g)zA
Cleans up my socket.

@param reason: Ignored.  Do not use this.
z(Tuntap %s Closed)r   éÿÿÿÿN)r   r¿   r˜   r   r—   rá   r™   ÚdoStopr¦   r–   rw   rÂ   )rI   Úreasons     r;   rá   ÚTuntapPort.connectionLostŒ  sb   € ô 	�ŠÐ$ t§~¡~Ñ5Ô6Ü×Ñ×.Ñ.¨tÔ<Ø�‰×ÑÔØˆŒØ�‰×Ñ˜4Ÿ<™<Ô(Øˆ�r:   c                 ó   • U R                   $ )z;
Returns the name of my class, to prefix log entries with.
)rœ   rH   s    r;   r    ÚTuntapPort.logPrefix™  s   € ð �{‰{Ðr:   c                 óB   • [        U R                  U R                  5      $ )z©
Get the local address of this L{TuntapPort}.

@return: A L{TunnelAddress} which describes the tunnel device to which
    this object is bound.
@rtype: L{TunnelAddress}
)r   r”   r˜   rH   s    r;   ÚgetHostÚTuntapPort.getHostŸ  s   € ô ˜TŸZ™Z¨¯©Ó8Ð8r:   )rÂ   r”   rß   r–   r¦   rÞ   r   r˜   rœ   rš   r™   )r&   NNrB   )r(   r)   r*   r+   r,   rÉ   rL   Ústrr¨   r®   r»   r«   r   rÓ   rt   rÚ   rã   r   r
   ré   rá   r    ró   r9   r'   r:   r;   r   r   æ   s~   † ñð €Mô9ð*2˜#ô 2ò	òMò$ò*òRò.ò"ò'ñ( ‘˜	 2 q¨!Ó,¨mÓ<ñ1ó =ð1ôòõ9r:   r   )6r,   rÊ   rŒ   r‹   Úplatformr²   rR   Úcollectionsr   Útypingr   Úzope.interfacer   r   r   Ú
constantlyr   r	   Úincrementalr
   Útwisted.internetr   r   r   r   r   Útwisted.pairr   r   Útwisted.pythonr   Útwisted.python.deprecater   Útwisted.python.reflectr   Útwisted.python.utilr   r   Ú__all__r´   ÚmachineÚ
startswithr¶   Ú
_TUNGETIFFrµ   r   ÚIAddressr   r\   r_   rˆ   ÚIListeningPortr—   r   r'   r:   r;   Ú<module>r     sE  ðñ
ó Û Û 	Û Û Û Ý "Ý ç <Ñ <ç *Ý ç EÕ Eß &Ý Ý /Ý 5ß ;ò€ð €	à×ÒÓ˜(Ó"Ø×ÒÓ×$Ñ$ U×+Ñ+Ø×ÒÓ×$Ñ$ W×-Ñ-ð €JØ�Jà€JØ€JØ€ô(�%ô (ñB ˆZ× Ñ Ó!ô&,�M <ó &,ó "ð&,ôR	™Ð$8¸-ÓHô 	ôC˜)ô C÷L4ñ 4ñ& ˆZ×&Ñ&Ó'ô@9�×(Ñ(ó @9ó (ñ@9r:   