Skip to content

feat: add endpoint to get listening ports in agent #4260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! Merge branch 'main' into dean/listening-ports
  • Loading branch information
deansheather committed Oct 6, 2022
commit 0960944e1d69a5de9caa3192d5425dbe42c0262d
8 changes: 8 additions & 0 deletions agent/ports_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort,
return nil, xerrors.Errorf("scan listening ports: %w", err)
}

seen := make(map[uint16]struct{}, len(tabs))
ports := []codersdk.ListeningPort{}
for _, tab := range tabs {
if tab.LocalAddr == nil || tab.LocalAddr.Port < uint16(codersdk.MinimumListeningPort) {
continue
}

// Don't include ports that we've already seen. This can happen on
// Windows, and maybe on Linux if you're using a shared listener socket.
if _, ok := seen[tab.LocalAddr.Port]; ok {
continue
}
seen[tab.LocalAddr.Port] = struct{}{}

procName := ""
if tab.Process != nil {
procName = tab.Process.Name
Expand Down