
    h                         d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ ddlZdd
lmZmZmZ g dZd Z	 	 	 ddZdee         fdZ dS )z-
Functions common to different architectures
    N)conf)MTUARPHDR_ETHERARPHRD_TO_DLT)Scapy_Exceptionwarning)network_nameresolve_ifaceNetworkInterface)bpf_program)	inet_pton)decode_locale_str)ListOptionalUnion)UP	BROADCASTDEBUGLOOPBACKPOINTTOPOINT
NOTRAILERSRUNNINGNOARPPROMISCALLMULTIMASTERSLAVE	MULTICASTPORTSEL	AUTOMEDIADYNAMICLOWER_UPDORMANTECHOc                 p    t          |           } | j        sdS t          t          j        | j                  S )z(Return the raw IPv4 address of interfaces       )r
   ipr   socketAF_INET)iffs    U/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/arch/common.pyget_if_raw_addrr+   6   s4     

C6 {V^SV,,,    Fc                    	 ddl m}m}m}m}m} n# t          $ r t          d          w xY wddlm	}	 t                      }
 |	|                     d                    }|sx|s't          j        st          d          t          j        }	 t          |          j        }t#          j        |          }n# t&          $ r Y nw xY w|st          j        rt*          }|( |t,          |t          j        |
          |dd	          }n|r |	|          } |	t1          |                              d                    } ||t,          |d|          }t3          t5          |                              d
                    }|rt          |           ||t          j        |
          |dd	          } ||           |d	k    rt          d| d|d          |
S )zAsks libpcap to parse the filter, then build the matching
    BPF bytecode.

    :param iface: if provided, use the interface to compile
    :param linktype: if provided, use the linktype to compile
    r   )PCAP_ERRBUF_SIZEpcap_open_livepcap_compilepcap_compile_nopcap
pcap_closez1libpcap is not available. Cannot compile filter !)create_string_bufferutf8z(Please provide an interface or linktype!N       z$Failed to compile filter expression z ())scapy.libs.winpcapyr.   r/   r0   r1   r2   OSErrorImportErrorctypesr3   r   encoder   ifacer   r
   typer   get	Exceptionuse_bpfr   r   byrefr	   r   	bytearraystrip)
filter_expr>   linktypepromiscr.   r/   r0   r1   r2   r3   bpf
bpf_filterarphdreterriface_bpcaperrors                     r*   compile_filterrQ   B   s   
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
  
 
 
?
 
 	

 ,+++++
--C%%j&7&7&?&?@@J $ 	: %>   JE	!%((-E$(//HH 	 	 	D	  	$DL 	$#H!!6<,,j!R
 
 
 ""#344&&|E':':'A'A&'I'IJJ~S'1c
 
 ")C.."6"6w"?"?@@ 	!%.. l&,s##ZB
 
 	
4
byyo=GZZM
 
 	
 Js    +(B5 5
CCreturnc                      	 t          dd          5 } t          j        d|                                           cddd           S # 1 swxY w Y   dS # t          $ r t          d           g cY S w xY w)z0Return the nameservers configured by the OS
    z/etc/resolv.confrznameserver\s+([^\s]+)Nz(Could not retrieve the OS's nameserver !)openrefindallreadFileNotFoundErrorr   )fds    r*   read_nameserversr[      s    $c** 	Cb:6		BB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C   :;;;			s3   A 'AA A

A A
A A10A1)NNF)!__doc__r<   rV   r'   scapy.configr   
scapy.datar   r   r   scapy.errorr   r   scapy.interfacesr	   r
   r   scapy.libs.structuresr   scapy.pton_ntopr   scapy.utilsr   scapytypingr   r   r   
_iff_flagsr+   rQ   strr[    r,   r*   <module>ri      sr     				        7 7 7 7 7 7 7 7 7 7 0 0 0 0 0 0 0 0 J J J J J J J J J J - - - - - - % % % % % % ) ) ) ) ) )            
.- - -   A A A AP$s)      r,   