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
d9a2676 - Corrected a lack of the address operator in --randomize-ip code.
9a1a0c1 - Fixed compile bug under Linux-based systems.
8255dae - Fixed bug where arguments would not be passed at all when running pack.sh.
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.
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 ...
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
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.
fc32b0b - Pack script generates go.sh that forces ttyS1 into binary mode
948e42b - Added pack.sh to package tapper into a convenient script easily transferrable to an embedded system.
bf5731d - Added the ability to specify input and output files on command line.
345b593 - Added Mac OS X support