Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setsockopt on ICMPSocket #39

Closed
audeoudh opened this issue Sep 9, 2021 · 5 comments
Closed

setsockopt on ICMPSocket #39

audeoudh opened this issue Sep 9, 2021 · 5 comments

Comments

@audeoudh
Copy link

audeoudh commented Sep 9, 2021

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. 😉 )

I would prefer 2.b supported by icmplib.

@ValentinBELYN
Copy link
Owner

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
Copy link
Author

audeoudh commented Nov 8, 2021

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
Copy link
Author

audeoudh commented Nov 8, 2021

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

@audeoudh
Copy link
Author

audeoudh commented Nov 8, 2021

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
Copy link
Owner

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants