Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
TAPPER - sample code for work with tap devices on linux and os x

Copyright (c) 2009-2013, Ivan Vucica, http://ivan.vucica.net/
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

 * Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above
   copyright notice, this list of conditions and the following
   disclaimer in the documentation and/or other materials
   provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

-
 Purpose

Providing simple code for creating a tap device, outputting onto stdout the
network traffic generated by kernel for the tap device, and writing into
tap device the traffic from stdin for processing by the kernel.

That is: a two way tunnel between stdio and tap network device.

-
 Requirements

Not sure. You obviously need tun driver for networking (to be able to
create tap device) -- if you don't have /dev/net/tun something's wrong.

Under OS X, you need the tun/tap kernel extension: 
  http://tuntaposx.sf.net/

Otherwise, this was made in the era of 2.6.30 kernels on a 2.6.26 kernel,
and with eglibc 2.9 installed (debian release of eglibc 2.9-12).

It was also tested as of 2013 on Debian and OS X Mountain Lion.

-
 Files

tapper files:
* tapper.c - provides the tap device
* README - this file
* Makefile - builds tapper
* testrun.sh - shows how to use twinpipe and netcat to tunnel traffic
  in a simple way
* pack.sh - packs for use in a certain embedded system

nontapper files:
* TINYFREELICENSE - does not apply to tapper. license of twinpipe.sh
* twinpipe.sh - runs two processes and interconnects them via pipes.

twinpipe was obtained from this URL:
 http://bisqwit.iki.fi/source/twinpipe.html

-
 Alternative tutorial with extra info

This is neat and simple code, but perhaps not best and definitely with 
much room for improvement and cleanup. So here's another nice article:
 http://linuxgazette.net/149/melinte.html 
and another one:
 http://waldner.netsons.org/d2-tuntap.php

Recent activity

Ivan Vučica

Ivan Vučica pushed 2 commits to ivucica/Tapper

9a1a0c1 - Fixed compile bug under Linux-based systems.
8255dae - Fixed bug where arguments would not be passed at all when running pack.sh.
Ivan Vučica

Ivan Vučica pushed 2 commits to ivucica/Tapper

dc3d63e - Fixed an assortment of warnings under OS X.
431fa25 - Integrated OS X code into main code. Made use of inet_addr() in place of sscanf()s. Other code cleanup and comment improvements.
Ivan Vučica

Ivan Vučica pushed 1 commit to ivucica/Tapper

a6a1764 - Added support for specifying IP address and netmask on command line. Made randomization optional. pack.sh is now a bit more parametrized, and its go.sh script ...
Ivan Vučica

Ivan Vučica pushed 2 commits to ivucica/Tapper

effbaa6 - Disabled debug output from tapper in go.sh.
5a46bc5 - Fixed bug reopening stdin and stdout when command line arguments are present. Improved pack.sh
Ivan Vučica

Ivan Vučica pushed 3 commits to ivucica/Tapper

57df2e8 - Work on header containing message size as well as accompanying buffering.
aa83176 - Packer now also sets up the connectivity a bit better (e.g. routing, nameserver, etc.), autoruns the 'go.sh' script, and the go script runs tapper in ...
e3a326a - Increased buffer size.
Ivan Vučica

Commits by Ivan Vučica were pushed to ivucica/Tapper

948e42b - Added pack.sh to package tapper into a convenient script easily transferrable to an embedded system.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.