MCPcopy
hub / github.com/WireGuard/wireguard-go / main

Function main

main.go:60–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60func main() {
61 if len(os.Args) == 2 && os.Args[1] == "--version" {
62 fmt.Printf("wireguard-go v%s\n\nUserspace WireGuard daemon for %s-%s.\nInformation available at https://www.wireguard.com.\nCopyright (C) Jason A. Donenfeld <Jason@zx2c4.com>.\n", Version, runtime.GOOS, runtime.GOARCH)
63 return
64 }
65
66 warning()
67
68 var foreground bool
69 var interfaceName string
70 if len(os.Args) < 2 || len(os.Args) > 3 {
71 printUsage()
72 return
73 }
74
75 switch os.Args[1] {
76
77 case "-f", "--foreground":
78 foreground = true
79 if len(os.Args) != 3 {
80 printUsage()
81 return
82 }
83 interfaceName = os.Args[2]
84
85 default:
86 foreground = false
87 if len(os.Args) != 2 {
88 printUsage()
89 return
90 }
91 interfaceName = os.Args[1]
92 }
93
94 if !foreground {
95 foreground = os.Getenv(ENV_WG_PROCESS_FOREGROUND) == "1"
96 }
97
98 // get log level (default: info)
99
100 logLevel := func() int {
101 switch os.Getenv("LOG_LEVEL") {
102 case "verbose", "debug":
103 return device.LogLevelVerbose
104 case "error":
105 return device.LogLevelError
106 case "silent":
107 return device.LogLevelSilent
108 }
109 return device.LogLevelError
110 }()
111
112 // open TUN device (or use supplied fd)
113
114 tdev, err := func() (tun.Device, error) {
115 tunFdStr := os.Getenv(ENV_WG_TUN_FD)
116 if tunFdStr == "" {
117 return tun.CreateTUN(interfaceName, device.DefaultMTU)

Callers

nothing calls this directly

Calls 15

IpcHandleMethod · 0.95
WaitMethod · 0.95
CloseMethod · 0.95
CreateTUNFunction · 0.92
CreateTUNFromFileFunction · 0.92
UAPIOpenFunction · 0.92
NewDefaultBindFunction · 0.92
UAPIListenFunction · 0.92
warningFunction · 0.85
printUsageFunction · 0.85
NameMethod · 0.65
OpenMethod · 0.65

Tested by

no test coverage detected