
    iJ              
      B   S r SSKJ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	r	SSK
JrJr  SSKJrJrJr  SSKrSSKJr  SSKJrJrJrJr  \R2                   " S	 S
\R4                  5      5       r\\\\\\\\\\4   \4   4      \4   r\R2                   " S S\R4                  5      5       r \R2                   " S S\R4                  5      5       r!S$S jr"S%S jr#S&S jr$S'S jr%S(S jr&S)S jr'S*S jr(S+S jr)    S,S jr*\!RV                  4     S-S jjr,S.S jr-S.S jr.      S/S jr/\\!RV                  S4         S0S jjr0      S1S jr1  S2       S3S jjr2\Rf                  S\!RV                  S4         S4S  jjr4S5S! jr5S6S" jr6S7S# jr7g)8a  Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
    )annotationsN)IterableSequence)AnyUnioncast   )log)_IPPROTO_IPV6
_MDNS_ADDR_MDNS_ADDR6
_MDNS_PORTc                      \ rS rSrSrSrSrg)InterfaceChoice)      r	    N)__name__
__module____qualname____firstlineno__DefaultAll__static_attributes__r       J/home/sebas/venvs/catt/lib/python3.13/site-packages/zeroconf/_utils/net.pyr   r   )   s    G
Cr   r   c                       \ rS rSrSrSrSrSrg)ServiceStateChange2   r   r	      r   N)r   r   r   r   AddedRemovedUpdatedr   r   r   r   r   r   2   s    EGGr   r   c                       \ rS rSrSrSrSrSrg)	IPVersion9   r   r	   r    r   N)r   r   r   r   V4OnlyV6Onlyr   r   r   r   r   r%   r%   9   s    FF
Cr   r%   c                    [        U 5      S:H  $ )N   )len)addrs    r   _is_v6_addressr-   C   s    t9?r   c                    SU ;   nU(       a  [         R                  O[         R                  n[         R                  " X 5      $ )N:)socketAF_INET6AF_INET	inet_pton)addressis_ipv6address_familys      r   _encode_addressr7   G   s-    WnG(/V__V^^NN44r   c                    [        U  VVs1 s H4  oR                    H!  o"R                  (       d  M  UR                  iM#     M6     snn5      $ s  snnf N)listipsis_IPv4ipadaptersifacer,   s      r   get_all_addresses_ipv4rA   M   s3    hUhU9949hUVVUs
   #A
A
c           	         [        U  VVs1 s H@  oR                    H-  o"R                  (       d  M  UR                  UR                  4iM/     MB     snn5      $ s  snnf r9   )r:   r;   is_IPv6r=   indexr>   s      r   get_all_addresses_ipv6rE   Q   sE     -5\XE))$||	$''5;;	)	X\ \s
   #A
 A
c                 r    [         R                  " S[        SS9  [        [        R
                  " 5       5      $ )Nzget_all_addresses is deprecated, and will be removed in a future version. Use ifaddrdirectly instead to get a list of adapters.r	   
stacklevel)warningswarnDeprecationWarningrA   ifaddrget_adaptersr   r   r   get_all_addressesrN   Y   /    MM	6	 "&"5"5"788r   c                 r    [         R                  " S[        SS9  [        [        R
                  " 5       5      $ )Nzget_all_addresses_v6 is deprecated, and will be removed in a future version. Use ifaddrdirectly instead to get a list of adapters.r	   rG   )rI   rJ   rK   rE   rL   rM   r   r   r   get_all_addresses_v6rQ   c   rO   r   c                   SU;   a  US UR                  S5       n[        R                  " U5      nU  H  nUR                   Hv  nUR                   c  M  [	        UR
                  [        5      (       d  M3  [        R                  " UR
                  S   5      U:X  d  M\  UR
                  UR                   4s  s  $    M     [        SU 35      e)N%r   z No adapter found for IP address )rD   	ipaddress
ip_addressr;   
isinstancer=   tupleRuntimeError)r?   r=   ipaddradapter
adapter_ips        r   ip6_to_address_and_indexr\   m   s    
by"((3- !!"%F!++J )z}}e44((q)9:fD"w}}55 &  9">
??r   c                    U  HW  nUR                   U:X  d  M  UR                   H2  n[        UR                  [        5      (       d  M$  UR                  s  s  $    MY     [        SU 35      e)NzNo adapter found for index )rD   r;   rV   r=   rW   rX   )r?   rD   rZ   r[   s       r   interface_index_to_ip6_addressr^   ~   sV    ==E!%kk
jmmU33%==( *  4UG<
==r   c                Z   / n[         R                  " 5       nU  H  n[        U[        5      (       a  UR	                  [        X#5      U45        M6  [        U[        5      (       d  MM  [        R                  " U5      R                  S:X  d  Ms  UR	                  [        X#5      5        M     U$ )zConvert IPv6 interface addresses to interface indexes.

IPv4 addresses are ignored.

:param interfaces: List of IP addresses and indexes.
:returns: List of indexes.
   )rL   rM   rV   intappendr^   strrT   rU   versionr\   )
interfacesresultr?   r@   s       r   ip6_addresses_to_indexesrg      s     F""$HeS!!MM9(JERSs##	(<(<U(C(K(Kq(PMM28CD	  Mr   c                p   / nU [         R                  L a~  U[        R                  :w  aC  Sn[        R
                  " U5        [        R                  " U[        SS9  UR                  S5        U[        R                  :w  a  UR                  S5        U$ U [         R                  L a  [        R                  " 5       nU[        R                  :w  a  UR                  [        U5      5        U[        R                  :w  a  UR                  [!        U5      5        U(       d  [#        SU 35      e U$ [%        U [&        5      (       a_  U  Vs/ s HB  n[%        U[(        5      (       d  M  [*        R,                  " U5      R.                  S:X  d  M@  UPMD     nnU[1        U 5      -  nU$ [3        SU < 35      es  snf )	a  Convert the interfaces choice into internal representation.

:param choice: `InterfaceChoice` or list of interface addresses or indexes (IPv6 only).
:param ip_address: IP version to use (ignored if `choice` is a list).
:returns: List of IP addresses (for IPv4) and indexes (for IPv6).
zIPv6 multicast requests can't be sent using default interface. Use V4Only, InterfaceChoice.All or an explicit list of interfaces.r	   rG   ))z::r   r   r   z0.0.0.0zFNo interfaces to listen on, check that any interfaces have IP version    z.choice must be a list or InterfaceChoice, got )r   r   r%   r'   r
   errorrI   rJ   rK   rb   r(   r   rL   rM   extendrE   rA   rX   rV   r:   rc   rT   rU   rd   rg   	TypeError)choice
ip_versionrf   messager?   is         r   normalize_interface_choicerq      s}    <>F((()))U  IIgMM'#5!DMM+,)))MM)$$ M# 
?&&	&&&()))MM0:;)))MM0:;XYcXde   M 
FD	!	!#cVz!S'9!i>R>RST>U>]>]ab>b!Vc*622 M H
STT	 ds   	F3&"F3F3c                     U R                  [        [        R                  S5        g! [         a    [
        R                  " S5        e f = f)z?Make V6 sockets work for both V4 and V6 (required for Windows).FzOSupport for dual V4-V6 sockets is not present, use IPVersion.V4 or IPVersion.V6N)
setsockoptr   r0   IPV6_V6ONLYOSErrorr
   rj   )ss    r   disable_ipv6_only_or_raiserw      s<    	]F$6$6> 		cds	   %( "A
c                    [        [        S5      (       d  g U R                  [        R                  [        R                  S5        g! [
         a)  nUR                  [        R                  :w  a  e  SnAgSnAff = f)z*Set SO_REUSEADDR on a socket if available.SO_REUSEPORTNr   )hasattrr0   rs   
SOL_SOCKETry   ru   errnoENOPROTOOPT)rv   errs     r   set_so_reuseport_if_availabler      s_     6>**	V&&(;(;Q? 99))) *s   /A 
A;A66A;c                   U[         R                  :X  a  [        R                  " SS5      n[        R                  " SS5      nU R	                  [
        R                  [
        R                  U5        U R	                  [
        R                  [
        R                  U5        gU[         R                  :X  aK  U R	                  [        [
        R                  S5        U R	                  [        [
        R                  S5        g[        S5      e)z.Set ttl/hops and loop for mDNS respond socket.   B   r   Tz)Dual-stack responder socket not supportedN)r%   r'   structpackrs   r0   
IPPROTO_IPIP_MULTICAST_TTLIP_MULTICAST_LOOPr(   r   IPV6_MULTICAST_HOPSIPV6_MULTICAST_LOOPrX   )rv   rn   ttlloops       r   $set_respond_socket_multicast_optionsr      s    
 Y%%% kk$${{4#	V&&(?(?E	V&&(@(@$G	y''	'	]F$>$>D	]F$>$>E FGGr   Fc                   [         R                  " SUUUU 5        U[        R                  :X  a  [        R
                  O[        R                  n[        R                  " U[        R                  5      nU[        R                  :X  a  [        U5        UR                  [        R                  [        R                  S5        [        U5        U(       a!  UR                  [        R                  SS5        U S   U/U SS  Q7n UR                  U5        [         R                  " S
U5        U$ ! [         a  nUR                   [         R"                  :X  a  [         R$                  " SU5         S nAg UR                   [         R&                  :X  aw  [(        R*                  R-                  S5      (       d$  [(        R*                  R-                  S5      (       a  [         R.                  " SU5        e [         R.                  " S	U5        e S nAff = f)NzNCreating new socket with port %s, ip_version %s, apple_p2p %s and bind_addr %rr   i  r   zRAddress not available when binding to %s, it is expected to happen on some systemsdarwinfreebsdzAddress in use when binding to %s; On BSD based systems sharing the same port with another stack may require processes to run with the same UID; When using avahi, make sure disallow-other-stacks is set to no in avahi-daemon.confzvAddress in use when binding to %s; When using avahi, make sure disallow-other-stacks is set to no in avahi-daemon.confzCreated socket %s)r
   debugr%   r'   r0   r2   r1   
SOCK_DGRAMr   rw   rs   r{   SO_REUSEADDRr   bindru   r|   EADDRNOTAVAILwarning
EADDRINUSEsysplatform
startswithrj   )	bind_addrportrn   	apple_p2psocket_familyrv   bind_tupexs           r   
new_socketr     s    IIX '1I4D4D&DFNN&//MmV%6%67AY]]""1%LL""F$7$7;!!$ 	
V&&2 !d3Yqr]3H	x8 II!1%H9  88u***KKd 88u'''||&&x00CLL4K4KI4V4V		2
 " 	 		2 	 	5s   D- -
H75H1BHHc                $   [        U[        5      n[        R                  1n[        R
                  S:X  a"  U[        [        [        5      R                  1-  n[        R                  " SXR                  5       5         U(       a|   [        R                  " [        R                  [        5      n[$        R&                  " S[        [(        US   5      5      nXE-   nU R+                  [,        [        R.                  U5        g[        R0                  " [2        5      [        R0                  " [        [4        U5      5      -   nU R+                  [        R6                  [        R8                  U5         g! [          a    [        R"                  " SU5         gf = f! [          Gal  n[;        U5      nU[        R<                  :X  a  [        R"                  " SU5         S nAgU[        R>                  :X  a_  U(       d<  [        R
                  RA                  S5      (       a  [        RB                  " S	U5        O[        RB                  " S
U5         S nAgU[        RD                  :X  a  [        R"                  " SU5         S nAgX;   a  [        R"                  " SU5         S nAgU[        RF                  :X  a  [        R"                  " SU5         S nAgU(       a0  U[        RH                  :X  a  [        R"                  " SU5         S nAge S nAff = f)Nwin32z(Adding %r (socket %d) to multicast groupzuUnable to translate IPv6 address when adding %s to multicast group, this can happen if IPv6 is disabled on the systemF@Ir   zZAddress in use when adding %s to multicast group, it is expected to happen on some systemslinuxzNo buffer space available when adding %s to multicast group, try increasing `net.ipv4.igmp_max_memberships` to `1024` in sysctl.confz<No buffer space available when adding %s to multicast group.zaAddress not available when adding %s to multicast group, it is expected to happen on some systemszAInterface of %s does not support multicast, it is expected in WSLzdFailed to set socket option on %s, this can happen if the network adapter is in a disconnected statezmAddress in use when adding %s to multicast group, it is expected to happen when the device does not have ipv6T)%rV   rW   r|   EINVALr   r   r   r   	WSAEINVALr
   r   filenor0   r3   r1   r   ru   infor   r   ra   rs   r   IPV6_JOIN_GROUP	inet_atonr   rc   r   IP_ADD_MEMBERSHIP	get_errnor   ENOBUFSr   r   r   r}   ENODEV)	listen_socket	interfaceis_v6
err_einvalmdns_addr6_bytes	iface_bin_valuee_errnos	            r   add_multicast_memberr   C  se   
 y%(E,,J
||wtC'1122
II8)EYEYE[\B#)#3#3FOO[#Q  D$sIaL*ABI%1F$$]F4J4JFSl i %%j1F4D4DT#yEY4ZZF$$V%6%68P8PRXYf   H
   11U%%%HHl U]]"S\\44W==^ R U(((HHB
 HHS U&&&HHA
 Vu||+HHN
 c1si   >F )E1 /AF A.F 1!FF FF L#6L
A.L
+L
L
"+L
2L
	L

Lc           
     :   [        U [        5      n[        U(       a2  [        [        [        [        [
        [
        4   [
        4   U 5      S   O[        [        U 5      4U(       a  SO[        U(       a  [        R                  O[        R                  US9nU(       a  U$ U(       d  g[        R                  " SX@5        U(       aN  [        R                  " S[        [
        U S   5      5      nUR                  [        [         R"                  U5        OQUR                  [         R$                  [         R&                  [         R(                  " [        [        U 5      5      5        [+        XC(       a  [        R                  5        U$ [        R                  5        U$ )zECreate interface specific socket for responding to multicast queries.r   )r   r   rn   r   Nz1Configuring socket %s with multicast interface %sr   r   )rV   rW   r   r   rc   ra   r   r%   r(   r'   r
   r   r   r   rs   r   r0   IPV6_MULTICAST_IFr   IP_MULTICAST_IFr   r   )r   r   unicastr   respond_socketr   s         r   new_respond_socketr     s)    y%(E  JO$uU3S=1367CAFVZ[^`iVjUlQz(-I$$93C3C	N IIA>]KKd3	!&=>	!!-1I1I9U!!""T#y12	

 )U9I9Ii YbXhXhir   c                8   U(       a  S nO
[        SX#S9n[        X5      nU(       d  U [        R                  L a  U[        R
                  :w  an  U H'  n[        [        [        R                  U5      U5        M)     [        [        [        R                  U5      U5        U[        [        R                  U5      /4$ / nU HU  nU(       d+  [        [        [        R                  U5      U5      (       d  M5  [        XcUS9nUc  MD  UR                  U5        MW     XG4$ )N) )r   rn   r   )r   r   )r   rq   r   r   r%   r   r   r   r0   r   r   rb   )	re   r   rn   r   r   normalized_interfacesr   respond_socketsr   s	            r   create_socketsr     s     "Uz_6zN z_%<%<<y}}A\.I fmm]!CYO / 	-T&---OQ[\tFMM=ABBBO*	3D4VXabb+IT[\%"">2 + ))r   c                <    [        [        U R                  S   5      $ )Nr   )r   ra   args)r   s    r   r   r     s    QVVAYr   c                $    U (       a  SU;   $ SU;  $ )zCheck if the address type matches the socket type.

This function does not validate if the address is a valid
ipv6 or ipv4 address.
r/   r   )ipv6_socketr4   s     r   can_send_tor     s     )3'>@c.@@r   c                    [        U [        5      (       aY  [        S U  5       5      n[        S U  5       5      nU(       a  U(       a  [        R                  $ U(       a  [        R
                  $ [        R                  $ )z3Auto detect the IP version when it is not provided.c              3     #    U  HV  n[        U[        5      =(       d:    [        U[        5      =(       a#    [        R                  " U5      R
                  S :H  v   MX     g7f)r`   N)rV   ra   rc   rT   rU   rd   .0rp   s     r   	<genexpr>(autodetect_ip_version.<locals>.<genexpr>  sI      
 q#_:a#5#^):N:Nq:Q:Y:Y]^:^_s   AA c              3     #    U  H?  n[        U[        5      =(       a#    [        R                  " U5      R                  S :H  v   MA     g7f)ri   N)rV   rc   rT   rU   rd   r   s     r   r   r     s8     eZdUVZ3'PI,@,@,C,K,Kq,PPZds   AA	)rV   r:   anyr%   r   r(   r'   )re   has_v6has_v4s      r   autodetect_ip_versionr     sc    *d## 

 
 eZdeef== ###r   )r,   bytesreturnbool)r4   rc   r   r   )r?   Iterable[ifaddr.Adapter]r   	list[str])r?   r   r   &list[tuple[tuple[str, int, int], int]])r   r   )r   r   )r?   r   r=   rc   r   z tuple[tuple[str, int, int], int])r?   r   rD   ra   r   ztuple[str, int, int])re   z6Sequence[str | int | tuple[tuple[str, int, int], int]]r   r   )rm   InterfacesTypern   r%   r   z,list[str | tuple[tuple[str, int, int], int]])rv   socket.socketr   None)rv   r   rn   r%   r   r   )
r   z!tuple[str] | tuple[str, int, int]r   ra   rn   r%   r   r   r   socket.socket | None)r   r   r   &str | tuple[tuple[str, int, int], int]r   r   )FF)r   r   r   r   r   r   r   r   )
re   r   r   r   rn   r%   r   r   r   z0tuple[socket.socket | None, list[socket.socket]])r   ru   r   ra   )r   r   r4   rc   r   r   )re   r   r   r%   )8__doc__
__future__r   enumr|   rT   r0   r   r   rI   collections.abcr   r   typingr   r   r   rL   _loggerr
   constr   r   r   r   uniqueEnumr   rc   ra   rW   r   r   r%   r-   r7   rA   rE   rN   rQ   r\   r^   rg   r'   rq   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      sh  , #      
  . # #   F F dii  
 xc3eCcM6JC6O0P&P QRTccd    		  5W99@">F+. 5>4D4D**(1*1*Z&HHH 
H> %,,	;0;
; ; 	;
 ;|N N5N 
Nf #5## # 	#N "1!4!4%,,	"*"*"* "* 	"*
 6"*J Ar   