Closed audeoudh closed 2 years ago
Hi @audeoudh 👋
Wow! Thank you for taking the time to detail your request.
I'll see how to implement this for the next release.
I'll see how to implement this for the next release.
Just replace this line https://github.com/ValentinBELYN/icmplib/blob/40e951c1fb9723a13153034e829afb7b3d0fb13e/icmplib/sockets.py#L272 with this line
self._sock.sendto(packet,socket.getaddrinfo(request.destination, port=None, family=socket.AF_INET if self._IP_VERSION == 4 else socket.AF_INET6, type=socket.SOCK_DGRAM)[0][4])
I've tested it and it looks like everything works
host = ping('fe80::d250:99ff:fe28:7d19%em1' ,count=10, interval=0.2, privileged=False)
(host.address ,host.avg_rtt ,host.is_alive ,host.jitter ,host.max_rtt ,host.min_rtt ,host.packet_loss ,host.packets_received ,host.packets_sent)
('fe80::d250:99ff:fe28:7d19%em1', 0.355, True, 0.17, 0.751, 0.139, 0.0, 10, 10)
host = ping('localhost' ,count=10, interval=0.2, privileged=False)
(host.address ,host.avg_rtt ,host.is_alive ,host.jitter ,host.max_rtt ,host.min_rtt ,host.packet_loss ,host.packets_received ,host.packets_sent)
('127.0.0.1', 0.462, True, 0.093, 0.604, 0.386, 0.0, 10, 10)
Hi @sunwire,
Sorry for the delay.
It is not so simple. I'm trying to avoid putting any code related to IPv6 in the ICMPSocket
class. The ideal would be to place this code in the ICMPv6Socket
class. However, this class does not have its own send
method. I have to find a solution not to duplicate the code.
The PR #38 does not add IPv6-specific code to ICMPSocket
class. It forwards the self._sock.family
and self._sock.type
attributes to getaddrinfo
. It works for both versions.
I added tests to make sure that things works well with these modifications. Do you have a specific test bench to run to ensure all is working well?
Hi @audeoudh, sorry for the delay...
Thank you for your PR! I have integrated some of your work in the version 3.0.2 of icmplib. Otherwise, there are no unit tests at the moment, at least on GitHub. I have to improve them before committing them.
Current implementation does not support zone index of IPv6 addresses (
...%if
part to designate interface). Here, I try to pingfe80:aaaa:bbbb:cccc:dddd%wlo1
, which clearly exists (it is my own interface's address on wifi).Using the standard
ping
command, no problem:Using
icmplib
:Basically,
s.send
forward the request's destination tosocket.socket.sendto
, in a tuple (address, port/identifier). There, the…%wlo1
part is not allowed:One may use
socket.getaddrinfo
to get the correct tuple to forward (here, "3" is the number of my wlo1 interface):