Linux Kernel Documentation / networking / tuntap.txt

在计算机网络中,tun与tap是操作系统内核中的虚拟网络设备。不同于普通靠硬件网路板卡实现的设备,这些虚拟的网络设备全部用软件实现,并向运行于操作系统上的软件提供与硬件的网络设备完全相同的 … tunctl(8) - Linux man page Create a point-to-point TUN interface without Ethernet header. Automatically enabled if the desired interface name starts with "tun". -p. Create a TAP type interface with Ethernet header. Automatically selected if the desired interface starts with "tap" or if no interface name is given. -f tun-clone-device Specifies the tun clone device name. Linux Kernel Documentation / networking / tuntap.txt 1. Description TUN/TAP provides packet reception and transmission for user space programs. It can be seen as a simple Point-to-Point or Ethernet device, which, instead of receiving packets from physical media, receives them from user space program and instead of sending packets via physical media

Instead, you open the /dev/net/tun and configure it via ioctl () to "point" to tun0. To show the basic procedure, I will create the TUN interface using the command line tool ip tun tap and then show the C code to read from that TUN device. So to create the tun interface via commands line:

TUN/TAP provides packet reception and transmission for user space programs. It can be seen as a simple Point-to-Point or Ethernet device, which, instead of receiving packets from physical media, receives them from user space program and instead of sending packets via physical media writes them to the user space program.

Using the TUN/TAP driver to create a serial network

I think you are getting the concept wrong or I didnt understand you very well. AFAIK you dont need to do these many things. The concept of the tun tap device is that whatever packets the tun tap interface receives its sent to the userspace program and whatever the userspace program writes to the tun tap device, its sent to the network.