{"record":{"id":"eac0c5c830636260","repo":"ginuerzh/gost","slug":"s-v","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tuntap_darwin.go","lineNumber":41,"sourceCode":"\tif err != nil {\n\t\treturn\n\t}\n\n\tmtu := cfg.MTU\n\tif mtu <= 0 {\n\t\tmtu = DefaultMTU\n\t}\n\n\tpeer := cfg.Peer\n\tif peer == \"\" {\n\t\tpeer = ip.String()\n\t}\n\tcmd := fmt.Sprintf(\"ifconfig %s inet %s %s mtu %d up\",\n\t\tifce.Name(), cfg.Addr, peer, mtu)\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.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":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/tuntap_darwin.go#L23-L59","documentation":"On macOS, createTun configures the newly created TUN interface by shelling out to ifconfig ('ifconfig <ifc> inet <addr> <peer> mtu <mtu> up'). If exec.Command(...).Run() fails, the error is wrapped as '<full command>: <underlying error>' and returned from createTun, aborting TUN creation.","triggerScenarios":"Starting a TUN-based service on macOS where the ifconfig command fails — typically because the process lacks root privileges, the interface vanished, or the address/peer arguments are invalid.","commonSituations":"Running the app without sudo (macOS TUN setup requires root); missing or invalid tun.address/tun.netmask/peer config; ifconfig not present or PATH issues; OS denying utun operations.","solutions":["Run the process with elevated privileges (sudo) so ifconfig can configure the interface","Validate cfg.Addr/peer values and the ifce.Name() returned by the TUN device open","Run the failing ifconfig command manually to see the raw error","Check that the utun device was created successfully before configuration"],"exampleFix":"// before\n$ ./gost -L 'tun://...'   # fails: ifconfig ... : operation not permitted\n// after\n$ sudo ./gost -L 'tun://...'","handlingStrategy":"try-catch","validationCode":"// check privileges before attempting TUN setup\nif os.Geteuid() != 0 {\n    return errors.New(\"creating a TUN interface on macOS requires root\")\n}","typeGuard":null,"tryCatchPattern":"ifce, err := createTun(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"ifconfig\") {\n        return fmt.Errorf(\"tun setup failed (are you root?): %w\", err)\n    }\n    return err\n}","preventionTips":["Run macOS TUN services with sudo/root","Validate tun address/peer/mtu config values before startup","Test the generated ifconfig command manually when it fails","Ensure the utun device opens successfully before configuration"],"tags":["tun","macos","ifconfig","privileges"],"backgroundTag":"tun-interface-setup-failed","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}