XTLS/Xray-core · error

invalid IP address

Error message

invalid IP address

What it means

Thrown by FindProcess on Windows when the source IP passed to the Windows process-lookup API cannot be converted to a netip.Addr. The value returned by net.ParseIP was nil or an invalid slice, so AddrFromSlice fails. This practically means the caller supplied a malformed/unparseable IP string for a connection that should be attributed to a local process.

Source

Thrown at common/net/find_process_windows.go:87

	}
	var class int
	var fn uintptr
	switch network {
	case "tcp":
		fn = getExTCPTable
		class = tcpTablePidConn
	case "udp":
		fn = getExUDPTable
		class = udpTablePid
	default:
		panic("Unsupported network type for process lookup.")
	}
	ip := net.ParseIP(srcIP)
	port := int(srcPort)

	addr, ok := netip.AddrFromSlice(ip)
	if !ok {
		return 0, "", "", errors.New("invalid IP address")
	}
	addr = addr.Unmap()

	family := windows.AF_INET
	if addr.Is6() {
		family = windows.AF_INET6
	}

	buf, err := getTransportTable(fn, family, class)
	if err != nil {
		return 0, "", "", err
	}

	networkType := Network_TCP
	if network == "udp" {
		networkType = Network_UDP
	}
	familyType := AddressFamilyIPv4

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Validate/parse the source address with net.ParseIP or netip.ParseAddr before calling the process lookup and log the raw value on failure
  2. Ensure UDP paths that legitimately have no source IP are skipped instead of looked up
  3. If the address is a domain, do not call FindProcess; it only works with IP literals

Example fix

// before
pid, path, _, err := proc.FindProcess("tcp", srcIPString, srcPort)

// after
ip := net.ParseIP(srcIPString)
if ip == nil {
    return errors.New("invalid source IP: " + srcIPString)
}
pid, path, _, err := proc.FindProcess("tcp", srcIPString, srcPort)
Defensive patterns

Strategy: validation

Validate before calling

if net.ParseIP(srcIP) == nil {
    return fmt.Errorf("skip process lookup: invalid source IP %q", srcIP)
}

Type guard

func isParsableIP(s string) bool { return net.ParseIP(s) != nil }

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid IP address") { /* skip attribution, continue */ } else if err != nil { return err }

Prevention

When it happens

Trigger: Calling the exported FindProcess-like API (network 'tcp' or 'udp', srcIP, srcPort) with a srcIP that net.ParseIP rejects (e.g. empty string, 'abc', '1.2.3', or a 4-in-6 slice of unexpected length). Happens on Windows only, before getTransportTable is invoked.

Common situations: Routing/inbound code passing an address string that was never an IP (a domain), passing an empty source IP for UDP sessions, or IPv6/zoned addresses that failed parsing upstream.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/da896c27f139b561. Report an issue: GitHub.