1 Documentation on setup and use of EtherTap.
3 Contact Jay Schulist <Jay.Schulist@spacs.k12.wi.us> if you
4 have questions or need futher assistance.
9 Ethertap provides packet reception and transmission for user
10 space programs. It can be viewed as a simple Ethernet device,
11 which instead of receiving packets from a network wire, it receives
14 Ethertap can be used for anything from AppleTalk to IPX to even
15 building bridging tunnels. It also has many other general purpose
18 Ethertap also can do ARP for you, although this is not enabled by
24 First you will have to enable Ethertap in the kernel configuration.
25 Then you will need to create any number of ethertap device files,
26 /dev/tap0->/dev/tap15. This is done by the following command.
28 mknod /dev/tap* c 36 16 ( 17 18 19 20 for tap1,2,3,4...)
30 ** Replace * with the proper tap device number you need. **
32 Now with your kernel that has ethertap enabled, you will need
33 to ifconfig /dev/tap* 192.168.1.1 (replace 192.168.1.1 with the
34 proper IP number for your situation.)
36 If you want your Ethertap device to ARP for you would ifconfig
37 the interface like this: ifconfig tap* 192.168.1.1 arp
39 Remember that you need to have a corresponding /dev/tap* file
40 for each tap* device you need to ifconfig.
42 Now Ethertap should be ready to use.
44 Diagram of how Ethertap works. (Courtesy of Alan Cox)
45 ====================================================
47 This is for a tunnel, but you should be able to
50 1.2.3.4 will be the router to the outside world
52 2.0.0.1 our box (appletalk side)
53 2.0.0.* a pile of macintoys
56 [1.2.3.4]-------------1.2.3.5[Our Box]2.0.0.1---------> macs
58 The routing on our box would be
60 ifconfig eth0 1.2.3.5 netmask 255.255.255.0 up
61 route add default gw 1.2.3.4
62 ifconfig tap0 2.0.0.1 netmask 255.255.255.0 up arp
63 (route add 2.0.0.0 netmask 255.255.255.0)
65 C code for a Simple program using an EtherTap device
66 ====================================================
68 This code is just excerpts from a real program, so some parts are missing
69 but the important stuff is below.
73 int TapDevice, eth_pkt_len = 0;
74 unsigned char full_pkt_len[MAX_PKT_LEN];
76 TapDevice = open("/dev/tap0", O_RDWR);
79 perror("Error opening device");
83 write(TapDevice, full_packet, eth_pkt_len);