The Linux Channel

비디오 :: Online Course - Linux TUN/TAP virtual network interfaces

Written by: Kiran Kankipati - Published: 25-Jan-2017


Watch Video: 341 Linux TUN TAP virtual network interfaces - VTUN Project Source Code Walk - Ep3

* Click the image above to watch this video on Youtube ↗

Refer:
VTUN Sourceforge.net Project (Virtual Tunnel) - http://vtun.sourceforge.net/
TUN/TAP Wiki - https://en.wikipedia.org/wiki/TUN/TAP
VTUN Setup - official documentation - http://vtun.sourceforge.net/setup.html
VTUN Setup - Linux Journal - https://www.linuxjournal.com/article/6675
-----------
Universal TUN/TAP device driver - Linux Kernel Source Doc - https://elixir.bootlin.com/linux/latest/source/Documentation/networking/tuntap.txt
-----------
Intel DPDK Stack - http://www.dpdk.org

Watch Video: TAP Interface sample access - Linux TUN/TAP virtual network interfaces - Episode2

* Click the image above to watch this video on Youtube ↗

Download this episode my entire kernel module sample code, make file, clean script HERE. And here is the source code for a quick reference.

/* tap_access.c - tap interface demo access
 * The Linux Channel
 * Author: Kiran Kankipati
 * Updated: 25-jan-2017
 */
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <netpacket/packet.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <malloc.h>
#include <net/ethernet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <signal.h>


static int tap_open(char *dev)
{   struct ifreq ifr;
    int fd;

    if ((fd = open("/dev/net/tun", O_RDWR)) < 0) { return -1; }

    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
    if (*dev) strncpy(ifr.ifr_name, dev, IFNAMSIZ);
    if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { goto failed; } 

    strcpy(dev, ifr.ifr_name); return fd;

failed:
    close(fd); return -1;
}


int tapfd;
void signal_handler(int sig) { close(tapfd); exit(1); }

int main()
{	unsigned char buf[2000];
	unsigned char name[20];
	int i;
	int numbytes=0;
	
	
	strcpy(name,"tapint"); tapfd=tap_open(name); 
	if(tapfd<0) { printf("port open error!\n"); return 0; }

signal(SIGHUP,signal_handler);
signal(SIGTERM,signal_handler);
signal(SIGKILL,signal_handler);
signal(SIGSTOP,signal_handler);
signal(SIGINT,signal_handler);

repeat:	
	numbytes=read(tapfd, buf, 2000);
	if(numbytes<=0) { usleep(100); goto repeat;}
	
	printf("\tTAP Data:");
	for (i=0; i<numbytes; i++) printf("%02x:", buf[i]);
	printf("\n\n");
   
	goto repeat;	

	close(tapfd);
	return 0;
}

Watch Video: Linux TUN/TAP virtual network interfaces - Introduction Episode1

* Click the image above to watch this video on Youtube ↗


Suggested Topics:


Linux (user-space), Systems Architecture and Networking :: Video Episodes

 Networking and Q&A ↗
27-Aug-2016


 VRF - Virtual Routing and Forwarding ↗
24-Feb-2018


 Code Snippets ↗
16-Mar-2017


 Online Course - Networking Protocols ↗
04-Jul-2016


 net-tools - Source Code Walk ↗
09-Sep-2017


 Ethtool - Source Code Walk ↗
30-Sep-2017


 Oracle VM VirtualBox ↗
27-Mar-2017


 Online Course - Linux TUN/TAP virtual network interfaces ↗
25-Jan-2017


 Data Visualization and Analytics ↗
07-Apr-2018


 CPU Performance and Benchmarks ↗
13-Mar-2017


 Wireshark Packet Capture ↗
27-Oct-2016


 Online Course - Linux CLI Scripting ↗
04-Jul-2016


 IPUtils - Source Code Walk ↗
21-Aug-2017


 Linux (user-space) RAW Socket Programming ↗
27-Aug-2016


 Systems Architecture ↗
05-Jul-2016


 

Join The Linux Channel :: Facebook Group


추천 주제 :

Win free sponsor giveaway gifts:


Featured Video:
Watch Video: 235 Introducing Multi-dimensional (Multi-universe or Multiverse) Internet Technology

* Click the image above to watch this video on Youtube ↗

Join a class (course):


JOBS :: Software Engineers - Freshers - Off-Campus:


Trending Video:

TUTORIALS :: UDP sample socket code for Systems and Network software developers:


Linux Kernel Programming - Device Drivers:


Research :: Content Delivery Networks (CDN):
CDN Networks


Recommended Video:

The Linux Channel - v8.8 :: Updated: 30-Mar-2018 :: © 2018 :: Author: Kiran Kankipati
Your IP: 54.158.15.97 :: Browser: CCBot/2.0 (http://commoncrawl.org/faq/)