Skip to content

fix: detect JetBrains running on local ipv6 #11676

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 2 commits into from
Jan 17, 2024
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! fix: detect JetBrains running on local ipv6
  • Loading branch information
code-asher committed Jan 17, 2024
commit 9ca9c3ed5a45fc4f8c70ce3408af582cb2adcf7b
16 changes: 10 additions & 6 deletions agent/agentssh/portinspection_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ func getListeningPortProcessCmdline(port uint32) (string, error) {
acceptFn := func(s *netstat.SockTabEntry) bool {
return s.LocalAddr != nil && uint32(s.LocalAddr.Port) == port
}
tabs, err := netstat.TCPSocks(acceptFn)
tabs4, err4 := netstat.TCPSocks(acceptFn)
tabs6, err6 := netstat.TCP6Socks(acceptFn)

// Only return the error if the other method found nothing.
if (err != nil && len(tabs6) == 0) || (err6 != nil && len(tabs) == 0) {
return "", xerrors.Errorf("inspect port %d: %w", port, errors.Join(err, err6))
// In the common case, we want to check ipv4 listening addresses. If this
// fails, we should return an error. We also need to check ipv6. The
// assumption is, if we have an err4, and 0 ipv6 addresses listed, then we are
// interested in the err4 (and vice versa). So return both errors (at least 1
// is non-nil) if the other list is empty.
if (err4 != nil && len(tabs6) == 0) || (err6 != nil && len(tabs4) == 0) {
return "", xerrors.Errorf("inspect port %d: %w", port, errors.Join(err4, err6))
}

var proc *netstat.Process
if len(tabs) > 0 {
proc = tabs[0].Process
if len(tabs4) > 0 {
proc = tabs4[0].Process
} else if len(tabs6) > 0 {
proc = tabs6[0].Process
}
Expand Down