{"record":{"id":"f8c36caee13a62a7","repo":"ginuerzh/gost","slug":"s-v-f8c36c","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tuntap_windows.go","lineNumber":37,"sourceCode":"\tifce, err := water.New(water.Config{\n\t\tDeviceType: water.TUN,\n\t\tPlatformSpecificParams: water.PlatformSpecificParams{\n\t\t\tComponentID:   \"tap0901\",\n\t\t\tInterfaceName: cfg.Name,\n\t\t\tNetwork:       cfg.Addr,\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn\n\t}\n\n\tcmd := fmt.Sprintf(\"netsh interface ip set address name=\\\"%s\\\" \"+\n\t\t\"source=static addr=%s mask=%s gateway=none\",\n\t\tifce.Name(), ip.String(), ipMask(ipNet.Mask))\n\tlog.Log(\"[tun]\", cmd)\n\targs := strings.Split(cmd, \" \")\n\tif er := exec.Command(args[0], args[1:]...).Run(); er != nil {\n\t\terr = fmt.Errorf(\"%s: %v\", cmd, er)\n\t\treturn\n\t}\n\n\tif err = addTunRoutes(ifce.Name(), cfg.Gateway, cfg.Routes...); err != nil {\n\t\treturn\n\t}\n\n\titf, err = net.InterfaceByName(ifce.Name())\n\tif err != nil {\n\t\treturn\n\t}\n\n\tconn = &tunTapConn{\n\t\tifce: ifce,\n\t\taddr: &net.IPAddr{IP: ip},\n\t}\n\treturn\n}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/tuntap_windows.go#L19-L55","documentation":"On Windows, createTun assigns the TUN interface address via `netsh interface ip set address ... source=static addr=<ip> mask=<mask> gateway=none`; a non-zero exit is wrapped with the command. netsh failures usually mean the interface name is wrong, privileges are missing, or the IP/mask is invalid.","triggerScenarios":"createTun on Windows when the Wintun/TAP interface name changed or was removed before netsh ran, the process is not elevated, or ip.String()/ipMask produced an invalid pair.","commonSituations":"Running in a non-admin shell (netsh needs elevation); antivirus or the VPN driver renaming/removing the interface concurrently; malformed subnet mask from ipMask.","solutions":["Run the program as Administrator (elevated terminal or manifest requiring admin)","Verify the interface name in the wrapped command still exists (`netsh interface show interface`)","Check addr/mask values: ensure cfg.Addr parses to a valid IPv4 and the mask is a dotted-decimal netmask","Retry after confirming no other software (VPN client, device manager) removed the adapter"],"exampleFix":"// before\nc:\\> app.exe // non-elevated -> netsh fails: The requested operation requires elevation\n// after\nc:\\> run as Administrator: elevated prompt -> app.exe","handlingStrategy":"validation","validationCode":"func checkWindowsTunPreconditions(cfg tun.Config) error {\n    ip := net.ParseIP(strings.SplitN(cfg.Addr, \"/\", 2)[0])\n    if ip == nil || ip.To4() == nil {\n        return fmt.Errorf(\"invalid IPv4 addr %q\", cfg.Addr)\n    }\n    if !isAdmin() {\n        return errors.New(\"must run elevated as Administrator\")\n    }\n    return nil\n}\n\nfunc isAdmin() bool {\n    _, err := exec.LookPath(\"netsh\")\n    return err == nil && isElevated() // isElevated: check via windows token APIs or `net session` exit code\n}","typeGuard":"func netshAvailable() bool { _, err := exec.LookPath(\"netsh\"); return err == nil }","tryCatchPattern":"ifce, err := tun.CreateTun(cfg)\nif err != nil && strings.Contains(err.Error(), \"netsh\") {\n    if strings.Contains(err.Error(), \"elevation\") || strings.Contains(err.Error(), \"denied\") {\n        return fmt.Errorf(\"restart process as Administrator: %w\", err)\n    }\n    return fmt.Errorf(\"netsh failed — check adapter exists: %w\", err)\n}","preventionTips":["Always run elevated on Windows for interface configuration","Verify the TUN adapter exists before calling createTun (netsh interface show interface)","Validate Addr is IPv4 and let ipMask derive the mask","Watch for VPN/AV software renaming or removing adapters mid-run"],"tags":["netsh","windows","tuntap","privileges"],"backgroundTag":"command-execution-failed","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}