From 4e897a6354e5755debf17c7ddd5f93d8d0893c5b Mon Sep 17 00:00:00 2001 From: abakum Date: Mon, 6 Nov 2023 10:16:59 +0300 Subject: [PATCH 1/4] +386 works well for me --- netstat/netstat_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netstat/netstat_windows.go b/netstat/netstat_windows.go index 8e3b289..38a3811 100644 --- a/netstat/netstat_windows.go +++ b/netstat/netstat_windows.go @@ -1,4 +1,4 @@ -// +build amd64 +// +build windows package netstat From 001f10558dcf22b941e86023fcf5d3e2d9ce88e2 Mon Sep 17 00:00:00 2001 From: abakum Date: Mon, 6 Nov 2023 10:59:11 +0300 Subject: [PATCH 2/4] go.mod --- go.mod | 4 ++-- main.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 86c4a3c..a997305 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/cakturk/go-netstat +module github.com/abakum/go-netstat -go 1.13 +go 1.20 diff --git a/main.go b/main.go index 7a0c77c..fc71030 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// rm go.mod;go mod init github.com/abakum/go-netstat;go mod tidy package main import ( @@ -6,7 +7,7 @@ import ( "net" "os" - "github.com/cakturk/go-netstat/netstat" + "github.com/abakum/go-netstat/netstat" ) var ( From c5cf502094c397ef703005023e77aeb5836279b4 Mon Sep 17 00:00:00 2001 From: abakum Date: Sat, 20 Apr 2024 16:38:55 +0300 Subject: [PATCH 3/4] func (s SockTabEntry) String() string --- netstat/netstat.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/netstat/netstat.go b/netstat/netstat.go index 4d95c51..e89c09a 100644 --- a/netstat/netstat.go +++ b/netstat/netstat.go @@ -25,6 +25,22 @@ type SockTabEntry struct { Process *Process } +func (s SockTabEntry) String() string { + l := "" + if s.LocalAddr != nil { + l = s.LocalAddr.String() + } + r := "" + if s.RemoteAddr != nil { + r = s.RemoteAddr.String() + } + p := "" + if s.Process != nil { + p = s.Process.String() + } + return fmt.Sprintf("%s %s %s %s", l, r, s.State, p) +} + // Process holds the PID and process name to which each socket belongs type Process struct { Pid int From 3d2d871e8c62e8ed9892e199ad07fa2cbc10187e Mon Sep 17 00:00:00 2001 From: abakum Date: Fri, 26 Apr 2024 09:19:29 +0300 Subject: [PATCH 4/4] darwin dirty fix --- netstat/{netstat_linux.go => netstat_etc.go} | 3 +++ netstat/netstat_windows.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) rename netstat/{netstat_linux.go => netstat_etc.go} (99%) diff --git a/netstat/netstat_linux.go b/netstat/netstat_etc.go similarity index 99% rename from netstat/netstat_linux.go rename to netstat/netstat_etc.go index 05fb56d..2c8299f 100644 --- a/netstat/netstat_linux.go +++ b/netstat/netstat_etc.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Package netstat provides primitives for getting socket information on a // Linux based operating system. package netstat diff --git a/netstat/netstat_windows.go b/netstat/netstat_windows.go index 38a3811..01dd6d2 100644 --- a/netstat/netstat_windows.go +++ b/netstat/netstat_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package netstat @@ -268,7 +269,7 @@ func rawGetTCPTable2(proc uintptr, tab unsafe.Pointer, size *uint32, order bool) return nil } -func getTCPTable2(proc uintptr, order bool) ([]byte, error) { +func getTCPTable2(proc uintptr, _ bool) ([]byte, error) { var ( size uint32 buf []byte