warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn.git
Log | Files | Refs | README

commit b37ba4e6d31c1805174b0299c13df5925d6521cc
parent 4d6804ef90f3291394ad614a3951c74337e1b2b1
Author: sin <sin@2f30.org>
Date:   Wed, 23 Mar 2016 12:39:57 +0000

fix tap handling

Diffstat:
stun.8 | 8+++++++-
stun.c | 28+++++++++++++++++++++++-----
2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/stun.8 b/stun.8 @@ -1,4 +1,4 @@ -.Dd Mar 22, 2016 +.Dd Mar 23, 2016 .Dt STUN 8 .Os .Sh NAME @@ -9,11 +9,13 @@ .Op Fl df .Fl s .Op Fl p Ar port +.Op Fl t Ar type .Ar interface .Nm stun .Op Fl df .Fl h Ar host .Op Fl p Ar port +.Op Fl t Ar type .Ar interface .Sh DESCRIPTION .Nm @@ -36,6 +38,10 @@ The default port is 12080. .It Fl h Ar host Connect to specified .Ar host . +.It Fl t Ar type +Select the tunnel device +.Ar type . +The two available device types are 'tun' and 'tap'. The default is 'tun'. .El .Sh AUTHORS .An Dimitris Papastamos Aq Mt sin@2f30.org diff --git a/stun.c b/stun.c @@ -44,10 +44,16 @@ #define HDRLEN 2 #define MTU 1440 +enum { + TUNDEV, + TAPDEV +}; + EVP_CIPHER_CTX enc, dec; char *argv0; char *host; char *port = "12080"; +int devtype = TUNDEV; int debug; int foreground; int sflag; @@ -625,15 +631,15 @@ daemonize(void) void usage(void) { - fprintf(stderr, "usage: stun [-df] -s [-p port] interface\n"); - fprintf(stderr, " stun [-df] -h host [-p port] interface\n"); + fprintf(stderr, "usage: stun [-df] -s [-p port] [-t type] interface\n"); + fprintf(stderr, " stun [-df] -h host [-p port] [-t type] interface\n"); exit(1); } int main(int argc, char *argv[]) { - char *pw; + char *arg, *pw; int devfd; ARGBEGIN { @@ -652,6 +658,15 @@ main(int argc, char *argv[]) case 'p': port = EARGF(usage()); break; + case 't': + arg = EARGF(usage()); + if (!strcmp(arg, "tun")) + devtype = TUNDEV; + else if (!strcmp(arg, "tap")) + devtype = TAPDEV; + else + usage(); + break; default: usage(); } ARGEND @@ -663,16 +678,19 @@ main(int argc, char *argv[]) daemonize(); openlog("stun", LOG_PID | LOG_NDELAY, LOG_DAEMON); - if (strstr(argv[0], "tun")) { + switch (devtype) { + case TUNDEV: devfd = opentun(argv[0]); opendev = opentun; writedev = writetun; readdev = readtun; - } else { + break; + case TAPDEV: devfd = opentap(argv[0]); opendev = opentap; writedev = writetap; readdev = readtap; + break; } pw = getenv("STUNPW");