o
    b'                     @   s  U d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlmZ eedpMd	Zejd
sZejdkrmde
fde
fgZeeeef  e d< ndefgZeeeef  e d< G dd deZ!G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&ee&Z'de'fdefdefdee#fdee#fd ee#fd!efge&_(ej)Z)ee'ge)_*ee)_+ej,Z,e'ge,_*d"d# Z-d$d% Z.d&d' Z/dS )(z>
POSIX implementation of local network interface enumeration.
    N)CDLLPOINTER	Structurec_char_pc_intc_ubytec_uint8c_uint32c_ushortc_void_pcastpointer)find_library)AF_INETAF_INET6	inet_ntop)AnyListTuple)nativeStringc freebsddarwinsin_len
sin_family_sockaddrCommonc                   @   s   e Zd Zd ed fgZdS )in_addr   N__name__
__module____qualname__r   _fields_ r$   r$   D/usr/lib/python3/dist-packages/twisted/internet/test/_posixifaces.pyr   ,       
r   c                   @   s   e Zd Zded fgZdS )in6_addrr      Nr   r$   r$   r$   r%   r'   2   r&   r'   c                   @   s   e Zd Zedefg ZdS )sockaddrsin_portN)r    r!   r"   r   r
   r#   r$   r$   r$   r%   r)   8   s    
r)   c                   @   s    e Zd Zedefdefg ZdS )sockaddr_inr*   sin_addrN)r    r!   r"   r   r
   r   r#   r$   r$   r$   r%   r+   >   s
    
r+   c                   @   s&   e Zd Zedefdefdefg ZdS )sockaddr_in6r*   sin_flowinfor,   N)r    r!   r"   r   r
   r	   r'   r#   r$   r$   r$   r%   r-   E   s    
r-   c                   @   s   e Zd ZdS )ifaddrsN)r    r!   r"   r$   r$   r$   r%   r/   M   s    r/   ifa_nextifa_name	ifa_flagsifa_addrifa_netmaskifa_dstaddrifa_datac                 C   s<   t jdr|dd dkr|dd d |dd  S |S )a  
    On FreeBSD, kill the embedded interface indices in link-local scoped
    addresses.

    @param family: The address family of the packed address - one of the
        I{socket.AF_*} constants.

    @param packed: The packed representation of the address (ie, the bytes of a
        I{in_addr} field).
    @type packed: L{bytes}

    @return: The packed address with any FreeBSD-specific extra bits cleared.
    @rtype: L{bytes}

    @see: U{https://twistedmatrix.com/trac/ticket/6843}
    @see: U{http://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html#ipv6-scope-index}

    @note: Indications are that the need for this will be gone in FreeBSD >=10.
    r   N   s   s     r   )sysplatform
startswith)familypackedr$   r$   r%   _maybeCleanupScopeIndexd   s   r=   c                  C   s   t  } tt| dk rt g }ze| ro| d jra| d jd j}|tkr/t| d jtt	}n|t
kr>t| d jtt}nd}|rat|d jjdd }t||}|| d j|t||f | d j} | sW t|  |S W t|  |S t|  w )z
    Call C{getifaddrs(3)} and return a list of tuples of interface name, address
    family, and human-readable address representing its results.
    r   N)	ifaddrs_p
getifaddrsr   OSErrorr3   r   r   r   r   r+   r   r-   bytesr,   r   r=   appendr1   r   r0   freeifaddrs)r/   resultsr;   addrr<   r$   r$   r%   _interfaces}   s6   



rF   c                  C   sR   g } t  D ]!\}}}t|}t|}|tjkr&|dr&| | d|  q| S )z
    Return a list of strings in colon-hex format representing all the link local
    IPv6 addresses available on the system, as reported by I{getifaddrs(3)}.
    zfe80:%)rF   r   socketr   r:   rB   )retList	interfacer;   addressr$   r$   r%   posixGetLinkLocalIPv6Addresses   s   rL   )0__doc__rH   r8   ctypesr   r   r   r   r   r   r   r	   r
   r   r   r   ctypes.utilr   r   r   r   typingr   r   r   twisted.python.compatr   libcr9   r:   r   str__annotations__r   r'   r)   r+   r-   r/   r>   r#   r?   argtypesrestyperC   r=   rF   rL   r$   r$   r$   r%   <module>   sL   8



!