{"record":{"id":"76eb15a1e878019b","repo":"ginuerzh/gost","slug":"socks4-d","errorCode":null,"errorMessage":"[socks4] %d","messagePattern":"\\[socks4\\] (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"socks.go","lineNumber":741,"sourceCode":"\tif err := req.Write(conn); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif Debug {\n\t\tlog.Logf(\"[socks4] %s\", req)\n\t}\n\n\treply, err := gosocks4.ReadReply(conn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif Debug {\n\t\tlog.Logf(\"[socks4] %s\", reply)\n\t}\n\n\tif reply.Code != gosocks4.Granted {\n\t\treturn nil, fmt.Errorf(\"[socks4] %d\", reply.Code)\n\t}\n\n\treturn conn, nil\n}\n\ntype socks4aConnector struct{}\n\n// SOCKS4AConnector creates a Connector for SOCKS4A proxy client.\nfunc SOCKS4AConnector() Connector {\n\treturn &socks4aConnector{}\n}\n\nfunc (c *socks4aConnector) Connect(conn net.Conn, address string, options ...ConnectOption) (net.Conn, error) {\n\treturn c.ConnectContext(context.Background(), conn, \"tcp\", address, options...)\n}\n\nfunc (c *socks4aConnector) ConnectContext(ctx context.Context, conn net.Conn, network, address string, options ...ConnectOption) (net.Conn, error) {\n\tswitch network {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/socks.go#L723-L759","documentation":"The SOCKS4 server's reply code was not gosocks4.Granted, so the connect request was refused. The library wraps the numeric reply code into this error, letting the caller distinguish refusal reasons (e.g. rejected, ident failure) per the SOCKS4 spec.","triggerScenarios":"socks4Connector.ConnectContext (tcp-family) sends the SOCKS4 CONNECT request; the reply code != 0x5A (Granted): target refused/unreachable from proxy, proxy rule denies the destination, or identd check failed.","commonSituations":"SOCKS4 proxy ACLs blocking the target host:port; target server down or refusing connections from the proxy's IP; SOCKS4 deployments requiring ident that fail ident verification; using SOCKS4 for destinations that need SOCKS4a hostname support.","solutions":["Decode the reply code (90 granted, 91 rejected/failed, 92 ident-no-connection, 93 ident-mismatch) and check the corresponding condition on the proxy.","Add the destination to the proxy's allow list or fix identd setup (92/93 codes).","Upgrade to the socks4a connector if the target is specified by hostname (DNS must be done by the proxy).","Verify the target is reachable from the proxy host itself."],"exampleFix":"// before\n// SOCKS4 to hostname-based target -> reply 91\nc := SOCKS4Connector(\"socks4://proxy:1080\")\n// after\nc := SOCKS4aConnector(\"socks4a://proxy:1080\") // hostname resolved by proxy","handlingStrategy":"try-catch","validationCode":"host, port, err := net.SplitHostPort(address)\nif err != nil || host == \"\" || port == \"\" {\n\treturn fmt.Errorf(\"socks4 requires an IP literal and port, got %q\", address)\n}\nif net.ParseIP(host) == nil {\n\treturn fmt.Errorf(\"%s is not an IP; use socks4a\", host)\n}","typeGuard":null,"tryCatchPattern":"conn, err := socks4Connector.ConnectContext(ctx, conn, \"tcp\", addr)\nif err != nil {\n\tvar code int\n\tif n, _ := fmt.Sscanf(err.Error(), \"[socks4] %d\", &code); n == 1 {\n\t\tswitch code {\n\t\tcase 91: // request rejected/failed\n\t\tcase 92, 93: // ident problems\n\t\t}\n\t\treturn fmt.Errorf(\"proxy refused (code %d)\", code)\n\t}\n\treturn err\n}","preventionTips":["Use IP literals with SOCKS4; hostnames need socks4a.","Whitelist destinations on the proxy before deploying.","Check identd availability if the proxy enforces ident (codes 92/93).","Test reachability of the target from the proxy host."],"tags":["socks4","connect-refused","proxy","reply-code"],"backgroundTag":"socks-command-refused","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}