XTLS/Xray-core · error
invalid IP format for :
Error message
invalid IP format for :
What it means
formatLittleEndianString reports that the net.IP passed in produced no usable byte slice: To4() and To16() both returned nil, which for net.IP only happens when the input is nil (or a 4-byte/16-byte-malformed value). The message prints the original addr. The root cause is always an invalid or missing IP upstream — net.ParseIP never errors, it silently returns nil.
Source
Thrown at common/net/find_process_linux.go:94
pid, err := strconv.Atoi(pidStr)
if err != nil {
return 0, "", "", errors.New("failed to parse PID: ", err)
}
return pid, procName, absPath, nil
}
func formatLittleEndianString(addr net.IP, port Port) (string, error) {
ip := addr
var ipBytes []byte
if ip.To4() != nil {
ipBytes = ip.To4()
} else {
ipBytes = ip.To16()
}
if ipBytes == nil {
return "", errors.New("invalid IP format for ", addr, ": ", ip)
}
for i, j := 0, len(ipBytes)-1; i < j; i, j = i+1, j-1 {
ipBytes[i], ipBytes[j] = ipBytes[j], ipBytes[i]
}
portHex := fmt.Sprintf("%04X", uint16(port))
ipHex := strings.ToUpper(hex.EncodeToString(ipBytes))
return fmt.Sprintf("%s:%s", ipHex, portHex), nil
}
func findInodeInFile(filePath, targetHexAddr string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)View on GitHub (pinned to 7d214f8b09)
Solutions
- Validate with net.ParseIP(srcIP) != nil before calling FindProcess
- Normalize addresses upstream: strip CIDR length, zone IDs, and port suffixes
- Fail fast at the boundary where srcIP enters your system rather than deep in process lookup
Example fix
// before
err := routeByProcess(srcIP, srcPort)
// after
ip := net.ParseIP(srcIP)
if ip == nil {
return fmt.Errorf("invalid source IP %q", srcIP)
}
err := routeByProcess(ip.String(), srcPort) Defensive patterns
Strategy: validation
Validate before calling
if net.ParseIP(srcIP) == nil {
return errors.New("invalid source IP: ", srcIP)
} Type guard
func isParsableIp(s string) bool {
return net.ParseIP(s) != nil // nil in = nil out = guaranteed failure later
} Prevention
- net.ParseIP never returns an error — it returns nil; always check for nil
- Reject empty srcIP early: it is the single most common cause of this error
When it happens
Trigger: FindProcess called with srcIP that net.ParseIP cannot parse ('', hostname, '1.2.3.4/24', IPv6 with zone). The nil flows silently until this formatting step.
Common situations: Call sites passing empty metadata strings for direct connections, addresses taken from proxy headers without validation, or IPs with CIDR or zone suffixes.
Related errors
- failed to format address:
- failed to determine if address is local:
- could not search in
- connection for :: not found in
- could not find PID for inode :
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/a86a01c58773fad4.
Report an issue: GitHub.