Skip to content

Commit

Permalink
Support NetworkInterface for tuntap
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Aug 24, 2021
1 parent d3f84ff commit 1de3e84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scapy/layers/tuntap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from scapy.data import ETHER_TYPES, MTU
from scapy.error import warning, log_runtime
from scapy.fields import Field, FlagsField, StrFixedLenField, XShortEnumField
from scapy.interfaces import network_name
from scapy.layers.inet import IP
from scapy.layers.inet6 import IPv46, IPv6
from scapy.layers.l2 import Ether
Expand Down Expand Up @@ -113,7 +114,9 @@ class TunTapInterface(SimpleSocket):

def __init__(self, iface=None, mode_tun=None, default_read_size=MTU,
strip_packet_info=True, *args, **kwargs):
self.iface = bytes_encode(conf.iface if iface is None else iface)
self.iface = bytes_encode(
network_name(conf.iface if iface is None else iface)
)

self.mode_tun = mode_tun
if self.mode_tun is None:
Expand Down
3 changes: 2 additions & 1 deletion test/tuntap.uts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ if not LINUX:

import subprocess

tun0 = TunTapInterface("tun0", strip_packet_info=False)
iface = resolve_iface("tun0") # test TunTapInterface on NetworkInterface
tun0 = TunTapInterface(iface, strip_packet_info=False)

assert subprocess.check_call(["ip", "link", "set", "tun0", "up"]) == 0
assert subprocess.check_call([
Expand Down

0 comments on commit 1de3e84

Please sign in to comment.