o
    àý°jT  ã                   @   sX   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 G dd„ deƒZdS )é    N)ÚHeaderÚarray_frombytes)ÚIP6_Address)ÚIP6_Extension_Header)ÚLOGc                   @   sò   e Zd ZdZdZdZd;dd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z dS )<ÚIP6iÝ†  é(   é   Nc                 C   s0   t  | tj¡ |  tj¡ |r|  |¡ d S d S ©N)r   Ú__init__r   ÚHEADER_SIZEÚset_ip_vÚIP_PROTOCOL_VERSIONÚload_header)ÚselfÚbuffer© r   ú/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/impacket/IP6.pyr      s
   ÿzIP6.__init__c                 C   s,   t  | |¡ t|tƒr|  | ¡ ¡ d S d S r
   )r   ÚcontainsÚ
isinstancer   Úset_next_headerÚget_header_type)r   ÚaHeaderr   r   r   r   "   s   
ÿzIP6.containsc                 C   s   t jS r
   )r   r   ©r   r   r   r   Úget_header_size'   s   zIP6.get_header_sizec           
      C   sà   |   ¡ }|  ¡ }|  ¡ }|  ¡ }|  ¡ }|  ¡ }|  ¡ }|  ¡ }dt|ƒ d }	|	dt|ƒ d 7 }	|	dt|ƒ d 7 }	|	dt|ƒ d 7 }	|	dt|ƒ d 7 }	|	dt|ƒ d 7 }	|	d| 	¡  d 7 }	|	d	| 	¡  d 7 }	|	S )
NzProtocol version: Ú
zTraffic class: zFlow label: zPayload length: zNext header: zHop limit: zSource address: zDestination address: )
Úget_ip_vÚget_traffic_classÚget_flow_labelÚget_payload_lengthÚget_next_headerÚget_hop_limitÚ
get_ip_srcÚ
get_ip_dstÚstrÚ	as_string)
r   Úprotocol_versionÚtraffic_classÚ
flow_labelÚpayload_lengthÚnext_headerÚ	hop_limitÚsource_addressÚdestination_addressÚsr   r   r   Ú__str__*   s"   zIP6.__str__c                 C   s¸   |   ¡  ¡ }|  ¡  ¡ }g d¢}|  ¡ }|  ¡ }|  ¡ }t|tƒr4|| ¡ 8 }| ¡ }| ¡ }t|tƒs!t	 	d¡}| 
|¡ | 
|¡ t|t d|¡ƒ | |¡ t|t d|¡ƒ |S )N)r   r   r   ÚBz!L)r"   Úas_bytesr#   r   r    Úchildr   r   r   ÚarrayÚextendr   ÚstructÚpackÚfromlist)r   r,   r-   Úreserved_bytesÚupper_layer_packet_lengthÚupper_layer_protocol_numberr*   Úpseudo_headerr   r   r   Úget_pseudo_header>   s$   

ø




zIP6.get_pseudo_headerc                 C   s   |   d¡d@ d? S )Nr   éð   é   ©Úget_byter   r   r   r   r   [   s   zIP6.get_ip_vc                 C   s$   |   d¡d@ d> |   d¡d@ d? B S )Nr   é   r>   é   r=   r?   r   r   r   r   r   ^   s   $zIP6.get_traffic_classc                 C   s*   |   d¡d@ d> |   d¡d> B |   d¡B S )NrB   rA   é   é   é   é   r?   r   r   r   r   r   a   s   *zIP6.get_flow_labelc                 C   s   |   d¡d> |   d¡B S )Nr>   rE   é   r?   r   r   r   r   r   d   s   zIP6.get_payload_lengthc                 C   ó
   |   d¡S ©Nr	   r?   r   r   r   r   r    g   ó   
zIP6.get_next_headerc                 C   rH   ©Né   r?   r   r   r   r   r!   j   rJ   zIP6.get_hop_limitc                 C   ó   t |  ¡ dd… ƒ}|S ©NrE   é   ©r   Ú	get_bytes©r   Úaddressr   r   r   r"   m   ó   zIP6.get_ip_srcc                 C   rM   ©NrO   r   rP   rR   r   r   r   r#   q   rT   zIP6.get_ip_dstc                 C   s:   |dkrt dƒ‚|  d¡d@ }||d> O }|  d|¡ d S )Nr	   zset_ip_v - version != 6r   rA   r>   )Ú	Exceptionr@   Úset_byte)r   ÚversionÚbr   r   r   r   v   s
   zIP6.set_ip_vc                 C   sX   |   d¡d@ }|   d¡d@ }||d@ d? O }||d@ d> O }|  d|¡ |  d|¡ d S )Nr   r=   rB   rA   r>   ©r@   rW   )r   r'   Úb0Úb1r   r   r   Úset_traffic_classƒ   s   zIP6.set_traffic_classc                 C   sR   |   d¡d@ }||d@ d? O }|  d|¡ |  d|d@ d? ¡ |  d|d	@ ¡ d S )
NrB   r=   i   rC   rD   é ÿ  rE   rF   éÿ   rZ   )r   r(   r\   r   r   r   Úset_flow_labelŒ   s
   zIP6.set_flow_labelc                 C   s(   |   d|d@ d? ¡ |   d|d@ ¡ d S )Nr>   r^   rE   rG   r_   ©rW   )r   r)   r   r   r   Úset_payload_length”   s   zIP6.set_payload_lengthc                 C   ó   |   d|¡ d S rI   ra   )r   r*   r   r   r   r   ™   ó   zIP6.set_next_headerc                 C   rc   rK   ra   )r   r+   r   r   r   Úset_hop_limitœ   rd   zIP6.set_hop_limitc                 C   ó.   t |ƒ}|  ¡ }| ¡ |dd…< |  |¡ d S rN   ©r   rQ   r1   Ú	set_bytes)r   r,   rS   Úbytesr   r   r   Ú
set_ip_srcŸ   ó   zIP6.set_ip_srcc                 C   rf   rU   rg   )r   r-   rS   ri   r   r   r   Ú
set_ip_dst¥   rk   zIP6.set_ip_dstc                 C   ó   t  d¡ |  ¡ S ©Nzdeprecated soon)r   Úwarningr   r   r   r   r   Úget_protocol_version«   ó   
zIP6.get_protocol_versionc                 C   rm   rn   )r   ro   r"   r   r   r   r   Úget_source_address¯   rq   zIP6.get_source_addressc                 C   rm   rn   )r   ro   r#   r   r   r   r   Úget_destination_address³   rq   zIP6.get_destination_addressc                 C   ó   t  d¡ |  |¡ d S rn   )r   ro   r   )r   rX   r   r   r   Úset_protocol_version·   ó   
zIP6.set_protocol_versionc                 C   rt   rn   )r   ro   rj   )r   r,   r   r   r   Úset_source_address»   rv   zIP6.set_source_addressc                 C   rt   rn   )r   ro   rl   )r   r-   r   r   r   Úset_destination_address¿   rv   zIP6.set_destination_addressr
   )!Ú__name__Ú
__module__Ú__qualname__Ú	ethertyper   r   r   r   r   r/   r<   r   r   r   r   r    r!   r"   r#   r   r]   r`   rb   r   re   rj   rl   rp   rr   rs   ru   rw   rx   r   r   r   r   r      s>    
	r   )r5   r3   Úimpacket.ImpactPacketr   r   Úimpacket.IP6_Addressr   Úimpacket.IP6_Extension_Headersr   Úimpacketr   r   r   r   r   r   Ú<module>   s   