Xray-core/common/net/find_process_linux_test.go
Shilmoon 36112cd886
Some checks are pending
Build and Release / check-assets (push) Waiting to run
Build and Release / build (amd64, android, ) (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 (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 (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
Build and Release / build-release-only (386, 7, freebsd) (push) Blocked by required conditions
Build and Release / build-release-only (386, 7, linux) (push) Blocked by required conditions
Build and Release / build-release-only (386, 7, openbsd) (push) Blocked by required conditions
Build and Release / build-release-only (386, 7, windows) (push) Blocked by required conditions
Build and Release / build-release-only (arm, 5, linux) (push) Blocked by required conditions
Build and Release / build-release-only (arm, 6, linux) (push) Blocked by required conditions
Build and Release / build-release-only (arm, 7, freebsd) (push) Blocked by required conditions
Build and Release / build-release-only (arm, 7, linux) (push) Blocked by required conditions
Build and Release / build-release-only (arm, 7, openbsd) (push) Blocked by required conditions
Build and Release / build-release-only (mips, linux) (push) Blocked by required conditions
Build and Release / build-release-only (mips64, linux) (push) Blocked by required conditions
Build and Release / build-release-only (mips64le, linux) (push) Blocked by required conditions
Build and Release / build-release-only (mipsle, linux) (push) Blocked by required conditions
Tests and Checkings / check-assets (push) Waiting to run
Tests and Checkings / check-format-and-proto (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
Routing: Fix process for Linux IPv4-mapped sockets (#7414)
https://github.com/XTLS/Xray-core/pull/7414#issuecomment-6987317102

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 18:13:31 +00:00

50 lines
1.3 KiB
Go

//go:build linux && !android
package net
import (
"errors"
stdnet "net"
"net/netip"
"os"
"syscall"
"testing"
)
func TestFindProcessIPv4Mapped(t *testing.T) {
listener, err := stdnet.Listen("tcp4", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer listener.Close()
peer, err := stdnet.ListenPacket("udp4", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer peer.Close()
// an IPv6 socket that connects to an IPv4 address, as the sockets of Java and .NET are
for _, c := range []struct{ local, remote stdnet.Addr }{
{&stdnet.TCPAddr{IP: stdnet.IPv6zero}, listener.Addr()},
{&stdnet.UDPAddr{IP: stdnet.IPv6zero}, peer.LocalAddr()},
} {
network := c.remote.Network()
conn, err := (&stdnet.Dialer{LocalAddr: c.local}).Dial(network, c.remote.String())
if errors.Is(err, syscall.EAFNOSUPPORT) {
t.Skip("no IPv6 sockets here")
}
if err != nil {
t.Fatal(err)
}
defer conn.Close()
local := netip.MustParseAddrPort(conn.LocalAddr().String())
remote := netip.MustParseAddrPort(c.remote.String())
pid, _, _, err := FindProcess(network, "127.0.0.1", local.Port(), "127.0.0.1", remote.Port())
if err != nil {
t.Errorf("%s: %v", network, err)
} else if pid != os.Getpid() {
t.Errorf("%s: found PID %d, want %d", network, pid, os.Getpid())
}
}
}