{"record":{"id":"88ceee6de3457f51","repo":"XTLS/Xray-core","slug":"failed-to-determine-if-address-is-local","errorCode":null,"errorMessage":"failed to determine if address is local: ","messagePattern":"failed to determine if address is local: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/net/find_process_darwin.go","lineNumber":55,"sourceCode":"\tdarwinInSockInfoIPv6      = 0x2\n\tdarwinSockInfoIN          = 1\n\tdarwinSockInfoTCP         = 2\n)\n\ntype darwinSocketMatchLevel int\n\nconst (\n\tdarwinSocketNoMatch darwinSocketMatchLevel = iota\n\tdarwinSocketPortMatch\n\tdarwinSocketRemoteMatch\n\tdarwinSocketLocalMatch\n\tdarwinSocketExactMatch\n)\n\nfunc FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort uint16) (PID int, Name string, AbsolutePath string, err error) {\n\tisLocal, err := IsLocal(net.ParseIP(srcIP))\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"failed to determine if address is local: \", err)\n\t}\n\tif !isLocal {\n\t\treturn 0, \"\", \"\", ErrNotLocal\n\t}\n\tif network != \"tcp\" && network != \"udp\" {\n\t\tpanic(\"Unsupported network type for process lookup.\")\n\t}\n\n\tsrcAddr, err := netip.ParseAddr(srcIP)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"invalid source IP address: \", srcIP)\n\t}\n\tsrcAddr = srcAddr.Unmap()\n\n\tvar dstAddr netip.Addr\n\thasDstAddr := false\n\tif destIP != \"\" && destPort != 0 {\n\t\tdstAddr, err = netip.ParseAddr(destIP)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/net/find_process_darwin.go#L37-L73","documentation":"On macOS, FindProcess first checks whether the source IP belongs to this host via IsLocal; that check itself failed and the raw error is wrapped as 'failed to determine if address is local'. Note the source passes err (not a formatted string) directly as an error argument, so the message shows the underlying cause.","triggerScenarios":"IsLocal(net.ParseIP(srcIP)) fails while enumerating local interface addresses (net.Interfaces error) — e.g. permission problems, or srcIP is nil/unparseable so the address never matches any interface and the helper returns an error.","commonSituations":"Process lookup (for routing rules or stats) invoked with an empty or malformed srcIP, or in sandboxed macOS environments where interface enumeration fails.","solutions":["Verify the caller passes a valid, non-empty source IP (from an accepted connection's RemoteAddr).","Check the wrapped error text: an interface-enumeration failure suggests sandbox/permission issues — grant network entitlements or run outside the sandbox.","On macOS, ensure the app has the entitlements needed for sysctl/libproc before relying on process matching.","Guard the call site: skip process lookup when srcIP is empty instead of passing it through."],"exampleFix":"// before\npid, name, path, err := net.FindProcess(network, srcIP, srcPort, destIP, destPort)\n// after: validate inputs first\nif ip := net.ParseIP(srcIP); ip == nil {\n    return // skip process lookup for invalid source\n}\npid, name, path, err := net.FindProcess(network, srcIP, srcPort, destIP, destPort)","handlingStrategy":"validation","validationCode":"// Guard before calling FindProcess:\nif srcIP == \"\" {\n    return errors.New(\"no source IP available; skip process lookup\")\n}\nif ip := net.ParseIP(srcIP); ip == nil {\n    return errors.New(\"source is not an IP literal; skip process lookup\")\n}","typeGuard":null,"tryCatchPattern":"pid, name, path, err := net.FindProcess(network, srcIP, srcPort, destIP, destPort)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to determine if address is local\") {\n        // environment problem (interface enumeration); skip lookup, do not fail the request\n        err = nil\n    }\n}","preventionTips":["Always pass the RemoteAddr IP of an established connection.","Skip lookup on sandboxed macOS contexts where sysctl may fail.","Treat process lookup as best-effort: never fail the proxy request because of it."],"tags":["darwin","macos","process-lookup","platform","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}