summaryrefslogtreecommitdiffhomepage
path: root/main_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-04 17:29:52 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commit6f76edd045e20435689d9e1a3dd221b40b49adc6 (patch)
tree6bd0b68977059e74ece474fa7cfb5d27d971ec84 /main_windows.go
parent3af9aa88a310f7c2b86bae1ebb3ed3843424ce9e (diff)
Import windows scafolding
Diffstat (limited to 'main_windows.go')
-rw-r--r--main_windows.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/main_windows.go b/main_windows.go
new file mode 100644
index 0000000..f6a0b88
--- /dev/null
+++ b/main_windows.go
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package main
+
+import (
+ "fmt"
+ "git.zx2c4.com/wireguard-go/tun"
+ "os"
+ "os/signal"
+)
+
+const (
+ ExitSetupSuccess = 0
+ ExitSetupFailed = 1
+)
+
+func main() {
+
+ if len(os.Args) != 1 {
+ os.Exit(ExitSetupFailed)
+ }
+ //configFile := os.Args[1]
+ interfaceName := "TODO"
+
+ logger := NewLogger(
+ LogLevelDebug,
+ fmt.Sprintf("(%s) ", interfaceName),
+ )
+ logger.Info.Println("Starting wireguard-go version", WireGuardGoVersion)
+ logger.Debug.Println("Debug log enabled")
+
+ tun, err := tun.CreateTUN(interfaceName)
+ if err == nil {
+ realInterfaceName, err2 := tun.Name()
+ if err2 == nil {
+ interfaceName = realInterfaceName
+ }
+ } else {
+ logger.Error.Println("Failed to create TUN device:", err)
+ os.Exit(ExitSetupFailed)
+ }
+
+ device := NewDevice(tun, logger)
+ logger.Info.Println("Device started")
+
+ uapi, err := UAPIListen(interfaceName)
+ if err != nil {
+ logger.Error.Println("Failed to listen on uapi socket:", err)
+ os.Exit(ExitSetupFailed)
+ }
+
+ errs := make(chan error)
+ term := make(chan os.Signal, 1)
+
+ go func() {
+ for {
+ conn, err := uapi.Accept()
+ if err != nil {
+ errs <- err
+ return
+ }
+ go ipcHandle(device, conn)
+ }
+ }()
+ logger.Info.Println("UAPI listener started")
+
+ // wait for program to terminate
+
+ signal.Notify(term, os.Interrupt)
+
+ select {
+ case <-term:
+ case <-errs:
+ case <-device.Wait():
+ }
+
+ // clean up
+
+ uapi.Close()
+ device.Close()
+
+ logger.Info.Println("Shutting down")
+}