-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Do not resolve the interface name globally #3209
Conversation
If you need to create multiple interfaces to create a unit test, you could use virtual CAN interfaces. At least on Linux machines.
If you think that could work for a testcase, I could provide one. |
if L2socket is None: | ||
L2socket = iface.l2listen() | ||
L2socket = resolve_iface(iface or conf.iface).l2listen() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to put this in the isinstance()
s to make sure it always work?
if isinstance(iface, list):
L2socket = resolve_iface(iface[0] or conf.iface).l2listen()
...
elif isinstance(iface, dict):
L2socket = resolve_iface(next(iter(iface.values()) or conf.iface).l2listen()
....
.....
We can also just use TUN/TAPS polybassa, but good call. |
I'd go for diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py
index 7a847a03..130f8700 100644
--- a/scapy/sendrecv.py
+++ b/scapy/sendrecv.py
@@ -1108,22 +1108,22 @@ class AsyncSniffer(object):
quiet=quiet)
)] = offline
if not sniff_sockets or iface is not None:
- if L2socket is None:
- L2socket = resolve_iface(iface or conf.iface).l2listen()
+ _RL2 = lambda i: L2socket or resolve_iface(i).l2listen()
if isinstance(iface, list):
sniff_sockets.update(
- (L2socket(type=ETH_P_ALL, iface=ifname, **karg),
+ (_RL2(ifname)(type=ETH_P_ALL, iface=ifname, **karg),
ifname)
for ifname in iface
)
elif isinstance(iface, dict):
sniff_sockets.update(
- (L2socket(type=ETH_P_ALL, iface=ifname, **karg),
+ (_RL2(ifname)(type=ETH_P_ALL, iface=ifname, **karg),
iflabel)
for ifname, iflabel in six.iteritems(iface)
)
else:
- sniff_sockets[L2socket(type=ETH_P_ALL, iface=iface,
+ sniff_sockets[_RL2(iface)(type=ETH_P_ALL, iface=iface,
**karg)] = iface
# Get select information from the sockets |
I totally missed your PR and took a different approach (#3234). Feel free to use this idea if you want. |
This PR fixes #3191. I do not know how to test it =/