I have a tap interface created like this:
ip tuntap add dev tap0 mode tap user myusername
ip link set tap0 up
I then attach to tap0
using python and another program written in C++
Python:
def tapAlloc(tapname, mode):
tap = os.open('/dev/net/tun', mode | os.O_NONBLOCK)
ifr = struct.pack('16sH', tapname, IFF_TAP | IFF_NO_PI)
fcntl.ioctl(tap, TUNSETIFF, ifr)
return tap
(Just for simulation) if I try to attach to tap0 twice:
f1 = tapAlloc('tap0', os.O_RDWR)
f2 = tapAlloc('tap0', os.O_RDWR)
I get the error when I run this for f2
:
fcntl.ioctl(tap, TUNSETIFF, ifr)
IOError: [Errno 16] Device or resource busy
How can I attach to a tap interface from multiple processes ?