ValentinBELYN / icmplib

Easily forge ICMP packets and make your own ping and traceroute.
GNU Lesser General Public License v3.0
276 stars 45 forks source link

setsockopt on ICMPSocket #39

Closed audeoudh closed 2 years ago

audeoudh commented 3 years ago

I have a ICMPSocket. I have to use a .setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"iface") on the underlying socket. What is the recommended way to do that?

  1. s = ICMPv6Socket(); s._sock.setsockopt(...) makes an access to a private attribute.
  2. Subclassing ICMPSocket and add such a functionality is possible and easy; but why is it not done in icmplib itself then? a. Provide a wrapper for each possible option (as _set_ttl and _set_traffic_class) is too heavy as the number of supported options increase b. Provide a proxy method (icmpsocket.setsockopt(...)) that just forwards the call to self._sock.setsockopt(...) is possible, while it adds a function call. c. Change self._sock to a public attribute is another possible solution.
  3. Don't do that at all, icmplib won't support it (which I cannot accept for my personal project—but that is my personal problem then. :wink: )

I would prefer 2.b supported by icmplib.

ValentinBELYN commented 2 years ago

To determine the best approach to take, do you have any other options to pass to the underlying socket? Regarding ICMP, I doubt we have much 😉

audeoudh commented 2 years ago

For now, I don't have any other option to pass.

But some options are applicable even for ICMP. SO_MARK, SO_DONTROUTE, SO_REUSEADDR (not sure), SO_PRIORITY, SO_DEBUG… I did not tested all of them, though.

audeoudh commented 2 years ago

The code base use 2.a for broadcast: the property socket.broadcast is a wrapper for SO_BROADCAST.

audeoudh commented 2 years ago

Not so many options, indeed, fewer than I imagined. 2.a should be consider as an option, IMHO, maybe with lazy implementation (PR accepted when use-case occurs).

ValentinBELYN commented 2 years ago

Hi @audeoudh!

In the latest version of icmplib I added a property (sock) to directly access the underlying socket. This should meet your need.

Sorry for the delay...