Last 12 weeks · 0 commits
4 of 6 standards met
Linked issue Closes #20 Description On Windows, outputs different column counts for TCP vs UDP: TCP: — 5 columns UDP: — 4 columns (no State) The Windows implementation hardcodes , which works for TCP but misses UDP PIDs because returns an empty array for 4-column lines. Fix Added a fallback in : when the initial search from finds no PID and the line has fewer columns than expected, search the last column. This correctly handles UDP lines where the PID is at index 3 instead of 4. The fallback is guarded: Only triggers when (avoiding false matches on very short lines) Only accepts the last column if it's a pure numeric value (), preventing false matches with port numbers in address columns Testing The fix is passive for TCP lines (the primary loop returns the PID before the fallback runs). For UDP lines on Windows, the fallback correctly extracts the PID from the last column.
Problem The Windows implementation hardcodes : This works for TCP lines which have 5 tokens (Proto, Local Address, Foreign Address, State, PID): But UDP is connectionless -there is no State column, so lines have only 4 tokens: scans from onward. With only 4 tokens (indices 0–3), returns and the PID is never found. This is confirmed by Microsoft's docs -the State column only applies to TCP. Libraries like explicitly handle this by reading the last column as PID. Suggested fix Since guarantees PID is always the last field, use that instead of a hardcoded index: Environment v2.0.1 Windows 11, any Windows version
Repository: sindresorhus/pid-port. Description: Get the ID of the process that uses a certain port Stars: 151, Forks: 11. Primary language: JavaScript. Languages: JavaScript (100%). License: MIT. Latest release: v2.1.1 (3mo ago). Open PRs: 0, open issues: 0. Last activity: 3mo ago. Community health: 71%. Top contributors: sindresorhus, Richienb, robhogan, EhabY, gengjiawen, zikaari.