Skip to content

+386 works well for me #20

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/cakturk/go-netstat
module github.com/abakum/go-netstat

go 1.13
go 1.20
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// rm go.mod;go mod init github.com/abakum/go-netstat;go mod tidy
package main

import (
Expand All @@ -6,7 +7,7 @@ import (
"net"
"os"

"github.com/cakturk/go-netstat/netstat"
"github.com/abakum/go-netstat/netstat"
)

var (
Expand Down
16 changes: 16 additions & 0 deletions netstat/netstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions netstat/netstat_linux.go → netstat/netstat_etc.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions netstat/netstat_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// +build amd64
//go:build windows
// +build windows

package netstat

Expand Down Expand Up @@ -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
Expand Down