diff options
author | Christian Pointner <equinox@anytun.org> | 2017-08-12 17:50:09 +0200 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2017-08-12 17:50:09 +0200 |
commit | c951583989b96aaf996b670f2a86334fb105ad37 (patch) | |
tree | a6f5972adb96dd7e25dffcfecf6cd7327c24a96c | |
parent | added basic files (diff) |
basic tun/tap handling
-rw-r--r-- | app/Makefile | 1 | ||||
-rw-r--r-- | app/anygone.go | 22 |
2 files changed, 20 insertions, 3 deletions
diff --git a/app/Makefile b/app/Makefile index 4e7a810..c19ceda 100644 --- a/app/Makefile +++ b/app/Makefile @@ -35,6 +35,7 @@ endif EXECUTEABLE := anygone LIBS := "spreadspace.org/anytun/anygone/satp" \ + "github.com/lab11/go-tuntap/tuntap" \ "github.com/spf13/pflag" all: build diff --git a/app/anygone.go b/app/anygone.go index d611631..3c9de8b 100644 --- a/app/anygone.go +++ b/app/anygone.go @@ -36,6 +36,7 @@ import ( "log" "os" + "github.com/lab11/go-tuntap/tuntap" "github.com/spf13/pflag" ) @@ -45,9 +46,9 @@ var ( ) func init() { - if _, exists := os.LookupEnv("ANYGONE_DEBUG"); exists { - adl.SetOutput(os.Stderr) - } + // if _, exists := os.LookupEnv("ANYGONE_DEBUG"); exists { + adl.SetOutput(os.Stderr) + // } } func printUsage() { @@ -75,4 +76,19 @@ func main() { } al.Println("just started...") + + tund, err := tuntap.Open("anygone%d", tuntap.DevTun, true) + if err != nil { + al.Printf("Error while opening device: %v", err) + os.Exit(1) + } + + var pkt *tuntap.Packet + for { + if pkt, err = tund.ReadPacket(); err != nil { + al.Printf("Error while reading packet from device: %v", err) + os.Exit(1) + } + adl.Printf("got packat: %v", pkt) + } } |