I pasted the relevant code below so we can reference its mystery hex
number.
The tun tap block in grc takes code from the tun tap example to open a
tun tap file descriptor. The file descriptor is fed into a file
descriptor source and sink. From the outside of the tun tap block, we
see the input to the file descriptor sink and the output of the file
descriptor source.
GRC will try to exec ifconfig on the tun tap device name, if an ip
address is specified. You can manually run ifconfig as well. I dont
think this is the problem.
Should this work in linux? Maybe.
Should this work in mac os? Possibilities are even worse: those hard
coded hex values, they probably have header file constants that change
numeric value from linux to freebsd.
This could be helpful:
http://alex.king.net.nz/tuntap.html
Relevant Code from 0.70:
#######################################################################################
TUN/TAP
#######################################################################################
IFF_TUN = 0x0001 # tunnel IP packets
IFF_TAP = 0x0002 # tunnel ethernet frames
IFF_NO_PI = 0x1000 # don’t pass extra packet info
IFF_ONE_QUEUE = 0x2000 # beats me 
DEFAULT_TUN_DEVICE = ‘/dev/net/tun’
DEFAULT_VIRTUAL_DEVICE = ‘tun%d’
DEFAULT_IP_ADDR = ‘10.0.0.1’
def open_tun_interface(tun_device_filename=DEFAULT_TUN_DEVICE,
virtual_device_filename=DEFAULT_VIRTUAL_DEVICE):
“”“!
Open a virtual ethernet interface via the Tun/Tap framework.
An alternative function can be found: “from eunuchs.tuntap import
opentuntap”
@param tun_device_filename the path to the tun device
@param virtual_device_filename the name of the virtual device (to be
created)
@return a file descriptor to rw the device, name of the virtual device
(created)
“””
from fcntl import ioctl
mode = IFF_TAP | IFF_NO_PI
TUNSETIFF = 0x400454ca
tun_fd = os.open(tun_device_filename, os.O_RDWR)
ifs = ioctl(tun_fd, TUNSETIFF, struct.pack(“16sH”,
virtual_device_filename, mode))
ifname = ifs[:16].strip(“\x00”)
return tun_fd, ifname
class TunTapHelper(gr.hier_block2):
“”“Make the tun tap hier2 block.”“”
def init(self, item_size, tun_fd):
“”“!
TunTapHelper constructor.
@param item_size the size in bytes of the IO data stream
@param tun_fd the file descriptor for the virtual device
“””
#create hier block
gr.hier_block2.init(
self, ‘tun_tap’,
gr.io_signature(1, 1, item_size),
gr.io_signature(1, 1, item_size)
)
#I/O blocks
sink = gr.file_descriptor_sink(item_size, tun_fd)
source = gr.file_descriptor_source(item_size, tun_fd)
#connect
self.connect(self, sink)
self.connect(source, self)
def TunTap(sb):
gr.file_descriptor_sink, gr.file_descriptor_source #uses
type = Enum(all_choices, 1)
sb.add_input_socket(‘in’, Variable(type))
sb.add_output_socket(‘out’, Variable(type))
sb.add_param(‘Type’, type, False, type=True)
sb.add_param(‘Tun Device’, String(DEFAULT_TUN_DEVICE))
sb.add_param(‘Virtual Device’, String(DEFAULT_VIRTUAL_DEVICE))
sb.add_param(‘IP Address’, String(DEFAULT_IP_ADDR))
sb.set_docs(‘’’
Foward data between gnuradio and a virtual ethernet interface.
Tun Device: File path to the tun device.
Virtual Device: Desired name for the virtual ethernet device.
“%d” will give the device a number starting at zero.
IP Address: IP address for the virtual device, leave blank and device
will not be configured.
‘’')
def make(fg, type, tun, virt, ip_addr):
item_size = type.parse().get_num_bytes()
tun_fd, ifname = open_tun_interface(tun.parse(), virt.parse())
#try to set the ip address
ip_addr = ip_addr.parse()
if ip_addr: os.system(‘ifconfig %s %s’%(ifname, ip_addr))
return TunTapHelper(item_size, tun_fd)
return sb, make