
    zf_                     8    d dl Z d dlZd dlZ G d d          ZdS )    Nc                       e Zd Zej        ddfZej        ej        ej        ej	        ej
        dZddZed             Zd	 ZddZd ZdS )Socket
      )icmptcpudpipraw    Nc                 |   	 t          j        |          | _        n,# t           j        $ r}t	          d|z   dz             d}~ww xY wt
                              |          | _        || _        t          j         t           j	        t           j
        | j                  | _         || _        |r | j         j        |  dS dS )a  Creates a network socket to exchange messages

        :param destination: Destination IP address
        :type destination: str
        :param protocol: Name of the protocol to use
        :type protocol: str
        :param options: Options to set on the socket
        :type options: tuple
        :param source: Source IP to use - implemented in future releases
        :type source: Union[None, str]
        :param buffer_size: Size in bytes of the listening buffer for incoming packets (replies)
        :type buffer_size: intzCannot resolve address "z#", try verify your DNS or host fileN)socketgethostbynamedestinationgaierrorRuntimeErrorr   getprotobynameprotocolbuffer_sizeAF_INETSOCK_RAWsource
setsockopt)selfr   r   optionsr   r   es          T/var/www/ffwdstore.be/apps/py-env/lib/python3.11/site-packages/pythonping/network.py__init__zSocket.__init__   s    	q%3K@@D 	q 	q 	q9KGJooppp	q --h77&mFNFOT]SS 	-"DK"G,,,,	- 	-s    AA  Ac           
         	 t           j        |                                          S # t          $ r\ t          dt	          |           z   dz   t	          t          t           j                                                            z             w xY w)N'z/' is not in the list of supported proto types: )r   PROTO_LOOKUPlowerKeyErrorstrlistkeys)names    r   r   zSocket.getprotobyname*   s    	D&tzz||44 	D 	D 	D3T?-^^ f&9&>&>&@&@!A!ABBC D D D	Ds
   #& A&Bc                     | j         r!| j                            | j         df           | j                            || j        df           dS )zkSends a raw packet on the stream

        :param packet: The raw packet to send
        :type packet: bytesr   N)r   r   bindsendtor   )r   packets     r   sendzSocket.send2   sQ    
 ; 	/Kdk1-...6D$4a#899999       c                    |}|dk    rt          j                    }t          j        | j        gg g |          }t          j                    |z
  }||z  }|d         sdd|fS | j                            | j                  \  }}|||fS dS )a  Listen for incoming packets until timeout

        :param timeout: Time after which stop listening
        :type timeout: Union[int, float]
        :return: The packet, the remote socket, and the time left before timeout
        :rtype: (bytes, tuple, float)r   r.    N)timeperf_counterselectr   recvfromr   )r   timeout	time_leftstart_select
data_readyelapsed_in_selectr,   r   s           r   receivezSocket.receive;   s     	!mm,..L}b"iHHJ $ 1 3 3l B**Ia= *B	))![11$2BCCNFF69,, mr.   c                     	 t          | d          r"| j        r| j                                         d S d S d S # t          $ r t          d          w xY w)Nr   zAttribute error because of failed socket init. Make sure you have the root privilege. This error may also be caused from DNS resolution problems.)hasattrr   closeAttributeError)r   s    r   __del__zSocket.__del__N   s    	atX&& $4; $!!#####$ $ $ $ 	a 	a 	a  "` a a a	as	   08 A)r   r   N)r/   )__name__
__module____qualname__r   SOL_IPDONT_FRAGMENTIPPROTO_ICMPIPPROTO_TCPIPPROTO_UDP
IPPROTO_IPIPPROTO_RAWr"   r   staticmethodr   r-   r;   r@   r   r.   r   r   r      s        ]B*M"/8JSYSe +F4FH HL- - - -> D D \D: : :- - - -&a a a a ar.   r   )r   r4   r2   r   r   r.   r   <module>rL      sf      Na Na Na Na Na Na Na Na Na Nar.   