summaryrefslogtreecommitdiff
path: root/tuntap
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-08-13 20:51:52 +0200
committerChristian Pointner <equinox@anytun.org>2017-08-13 20:51:52 +0200
commitb6b71d04e0ce69026a71a101b5de59c0ad7b1c95 (patch)
tree39a9153c0c2290ab15f89f311a9bbadf88138dbf /tuntap
parentmake use of new tuntap device (diff)
revamp command line parser
Diffstat (limited to 'tuntap')
-rw-r--r--tuntap/tuntap.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/tuntap/tuntap.go b/tuntap/tuntap.go
index 3dde53b..27fd2b1 100644
--- a/tuntap/tuntap.go
+++ b/tuntap/tuntap.go
@@ -32,6 +32,7 @@ package tuntap
import (
"fmt"
+ "strings"
extlib "github.com/lab11/go-tuntap/tuntap"
)
@@ -78,3 +79,23 @@ func NewTapDevice(name string) (dev *Device, err error) {
}
return
}
+
+func NewDevice(iftype, name string) (dev *Device, err error) {
+ if iftype == "" {
+ if strings.HasPrefix(name, "tun") {
+ return NewTunDevice(name)
+ }
+ if strings.HasPrefix(name, "tap") {
+ return NewTapDevice(name)
+ }
+ return nil, fmt.Errorf("no device type is set and the given interface name(%s) doesn't start with 'tun' or 'tap'", name)
+ }
+
+ switch strings.ToLower(iftype) {
+ case "tun":
+ return NewTunDevice(name)
+ case "tap":
+ return NewTapDevice(name)
+ }
+ return nil, fmt.Errorf("invalid interface type: %s", iftype)
+}