mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-06-28 04:03:07 +00:00
Some checks are pending
Build and Release for Windows 7 / check-assets (push) Waiting to run
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Blocked by required conditions
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Blocked by required conditions
Build and Release / check-assets (push) Waiting to run
Build and Release / build (386, freebsd, ) (push) Blocked by required conditions
Build and Release / build (386, linux, ) (push) Blocked by required conditions
Build and Release / build (386, openbsd, ) (push) Blocked by required conditions
Build and Release / build (386, windows, ) (push) Blocked by required conditions
Build and Release / build (amd64, android, android-amd64) (push) Blocked by required conditions
Build and Release / build (amd64, darwin, ) (push) Blocked by required conditions
Build and Release / build (amd64, freebsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, linux, ) (push) Blocked by required conditions
Build and Release / build (amd64, openbsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, windows, ) (push) Blocked by required conditions
Build and Release / build (arm, 5, linux) (push) Blocked by required conditions
Build and Release / build (arm, 6, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, freebsd) (push) Blocked by required conditions
Build and Release / build (arm, 7, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, android) (push) Blocked by required conditions
Build and Release / build (arm64, darwin) (push) Blocked by required conditions
Build and Release / build (arm64, freebsd) (push) Blocked by required conditions
Build and Release / build (arm64, linux) (push) Blocked by required conditions
Build and Release / build (arm64, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, windows) (push) Blocked by required conditions
Build and Release / build (loong64, linux) (push) Blocked by required conditions
Build and Release / build (mips, linux) (push) Blocked by required conditions
Build and Release / build (mips64, linux) (push) Blocked by required conditions
Build and Release / build (mips64le, linux) (push) Blocked by required conditions
Build and Release / build (mipsle, linux) (push) Blocked by required conditions
Build and Release / build (ppc64, linux) (push) Blocked by required conditions
Build and Release / build (ppc64le, linux) (push) Blocked by required conditions
Build and Release / build (riscv64, linux) (push) Blocked by required conditions
Build and Release / build (s390x, linux) (push) Blocked by required conditions
Tests and Checkings / check-assets (push) Waiting to run
Tests and Checkings / check-proto (push) Waiting to run
Tests and Checkings / check-format (push) Waiting to run
Tests and Checkings / test (macos-latest) (push) Blocked by required conditions
Tests and Checkings / test (ubuntu-latest) (push) Blocked by required conditions
Tests and Checkings / test (windows-latest) (push) Blocked by required conditions
https://github.com/XTLS/Xray-core/pull/6057#issuecomment-4364819830 And https://github.com/XTLS/Xray-core/pull/6149#issuecomment-4546876261
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package utils
|
|
|
|
import (
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
// ResolveSocketPath applies platform-specific transformations to a Unix
|
|
// socket path, matching the listen-side behaviour in
|
|
// transport/internet/system_listener.go.
|
|
//
|
|
// For abstract sockets (prefix @) on Linux/Android:
|
|
// - single @ — used as-is (lock-free abstract socket)
|
|
// - double @@ — stripped to single @ and padded to
|
|
// syscall.RawSockaddrUnix{}.Path length (HAProxy compat)
|
|
//
|
|
// Filesystem paths and abstract sockets on other platforms are returned
|
|
// unchanged.
|
|
func ResolveSocketPath(path string) string {
|
|
if len(path) == 0 || path[0] != '@' {
|
|
return path
|
|
}
|
|
if runtime.GOOS != "linux" && runtime.GOOS != "android" {
|
|
return path
|
|
}
|
|
if len(path) > 1 && path[1] == '@' {
|
|
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path))
|
|
copy(fullAddr, path[1:])
|
|
return string(fullAddr)
|
|
}
|
|
return path
|
|
}
|
|
|
|
// SplitHTTPUnixURL splits a target into an HTTP URL and an optional Unix
|
|
// socket path. For regular http(s) URLs the input is returned unchanged
|
|
// with an empty socketPath. For Unix sockets the format is:
|
|
//
|
|
// /path/to/socket.sock[:/http/path]
|
|
// @abstract[:/http/path]
|
|
// @@padded[:/http/path]
|
|
//
|
|
// The :/ separator delimits the socket path from the HTTP request path.
|
|
// If omitted, "/" is used.
|
|
func SplitHTTPUnixURL(raw string) (httpURL, socketPath string) {
|
|
if len(raw) == 0 || (!filepath.IsAbs(raw) && raw[0] != '@') {
|
|
return raw, ""
|
|
}
|
|
if idx := strings.Index(raw, ":/"); idx >= 0 {
|
|
return "http://localhost" + raw[idx+1:], raw[:idx]
|
|
}
|
|
return "http://localhost/", raw
|
|
}
|