Skip to content

Commit 2f8f69d

Browse files
committed
simple vpn program with tun/tap driver
1 parent 5891fa2 commit 2f8f69d

File tree

17 files changed

+1723
-0
lines changed

17 files changed

+1723
-0
lines changed

simple-tun/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export PROG := tunnel
2+
SRC_DIR := ./src
3+
export CC := gcc
4+
export CFLAGS := -Werror -Wall -Wextra -DDEBUG -g
5+
6+
.PHONY: all
7+
all:
8+
$(MAKE) -C $(SRC_DIR) all
9+
10+
.PHONY: install
11+
install:
12+
$(MAKE) -C $(SRC_DIR) install
13+
14+
.PHONY: clean
15+
clean:
16+
$(MAKE) -C $(SRC_DIR) clean
17+
18+
.PHONY: cleanall
19+
cleanall:
20+
$(MAKE) -C $(SRC_DIR) cleanall
21+
22+
.PHONY: print_vars
23+
print_vars:
24+
@echo "===print_vars==="
25+
@echo "PROG = $(PROG)"
26+
@echo "SRC_DIR = $(SRC_DIR)"
27+
@echo "CFLAGS = $(CFLAGS)"
28+
@echo "LDFLAGS = $(LDFLAGS)"
29+
$(MAKE) -C $(SRC_DIR) print_vars
30+

simple-tun/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
simple vpn program, it works with tun/tap linux kernel driver
2+
may be this is vpn tunnel over icmp messages

simple-tun/example/a.out

7.96 KB
Binary file not shown.

simple-tun/example/echoserver

10.1 KB
Binary file not shown.

simple-tun/example/echoserver.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <unistd.h>
2+
#include <sys/types.h>
3+
#include <sys/socket.h>
4+
#include <netdb.h>
5+
#include <stdio.h>
6+
#include <string.h>
7+
8+
int main()
9+
{
10+
11+
char str[100];
12+
int listen_fd, comm_fd;
13+
14+
struct sockaddr_in servaddr;
15+
16+
listen_fd = socket(AF_INET, SOCK_STREAM, 0);
17+
18+
bzero( &servaddr, sizeof(servaddr));
19+
20+
servaddr.sin_family = AF_INET;
21+
servaddr.sin_addr.s_addr = htons(INADDR_ANY);
22+
servaddr.sin_port = htons(12345);
23+
24+
bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));
25+
26+
listen(listen_fd, 10);
27+
28+
comm_fd = accept(listen_fd, (struct sockaddr*) NULL, NULL);
29+
30+
while(1)
31+
{
32+
33+
bzero( str, 100);
34+
35+
read(comm_fd,str,100);
36+
37+
printf("Echoing back - %s",str);
38+
39+
write(comm_fd, str, strlen(str)+1);
40+
41+
}
42+
}
14.7 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Send suggestions, bug reports, criticisms to Davide Brini <dave_br@gmx.com>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0.01
2+
----
3+
4+
01/09/2009 Changed the way packets are sent over TCP, now all kinds of frames/packets/protocols are supported.
5+
27/03/2010 Some clean up and reformatting.

simple-tun/example/simpletun/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
simpletun, a (too) simple tunnelling program.
2+
3+
-------
4+
5+
To compile the program, just do
6+
7+
$ gcc simpletun.c -o simpletun
8+
9+
If you have GNU make, you can also exploit implicit targets and do
10+
11+
$ make simpletun
12+
13+
-------
14+
15+
Usage:
16+
simpletun -i <ifacename> [-s|-c <serverIP>] [-p <port>] [-u|-a] [-d]
17+
simpletun -h
18+
19+
-i <ifacename>: Name of interface to use (mandatory)
20+
-s|-c <serverIP>: run in server mode (-s), or specify server address (-c <serverIP>) (mandatory)
21+
-p <port>: port to listen on (if run in server mode) or to connect to (in client mode), default 55555
22+
-u|-a: use TUN (-u, default) or TAP (-a)
23+
-d: outputs debug information while running
24+
-h: prints this help text
25+
26+
-------
27+
28+
Refer to http://backreference.org/2010/03/26/tuntap-interface-tutorial/ for
29+
more information on tun/tap interfaces in Linux in general, and on this
30+
program in particular.
31+
The program must be run at one end as a server, and as client at the other
32+
end. The tun/tap interface must already exist, be up and configured with an IP
33+
address, and owned by the user who runs simpletun. That user must also have
34+
read/write permission on /dev/net/tun. (Alternatively, you can run the
35+
program as root, and configure the transient interfaces manually before
36+
starting to exchange packets. This is not recommended)
37+
38+
Use is straightforward. On one end just run
39+
40+
[server]$ ./simpletun -i tun13 -s
41+
42+
at the other end run
43+
44+
[client]$ ./simpletun -i tun0 -c 10.2.3.4
45+
46+
where 10.2.3.4 is the remote server's IP address, and tun13 and tun0 must be
47+
replaced with the names of the actual tun interfaces used on the computers.
48+
By default it assumes a tun device is being used (use -u to be explicit), and
49+
-a can be used to tell the program that the interface is tap.
50+
By default it uses TCP port 55555, but you can change that by using -p (the
51+
value you use must match on the client and the server, of course). Use -d to
52+
add some debug information. Press ctrl-c on either side to exit (the other end
53+
will exit too).
54+
55+
The program is very limited, so expect to be disappointed.

0 commit comments

Comments
 (0)