Merge pull request #13 from nodauf/master

Support filtering on Process
main
James Mills 1 week ago
commit 86dbfcaa19
Signed by: prologic
GPG Key ID: AC4C014F1440EBD6
  1. 2
      go.mod
  2. 11
      netstat/netstat_linux.go

@ -1,3 +1,3 @@
module github.com/cakturk/go-netstat
module github.com/nodauf/go-netstat
go 1.13

@ -153,6 +153,7 @@ func parseSocktab(r io.Reader, accept AcceptFn) ([]SockTabEntry, error) {
}
e.UID = uint32(u)
e.ino = fields[9]
extractProcInfo(&e)
if accept(&e) {
tab = append(tab, e)
}
@ -163,7 +164,7 @@ func parseSocktab(r io.Reader, accept AcceptFn) ([]SockTabEntry, error) {
type procFd struct {
base string
pid int
sktab []SockTabEntry
sktab *SockTabEntry
p *Process
}
@ -200,8 +201,7 @@ func (p *procFd) iterFdDir() {
continue
}
for i := range p.sktab {
sk := &p.sktab[i]
sk := p.sktab
ss := sockPrefix + sk.ino + "]"
if ss != lname {
continue
@ -224,11 +224,10 @@ func (p *procFd) iterFdDir() {
stat.Close()
}
sk.Process = p.p
}
}
}
func extractProcInfo(sktab []SockTabEntry) {
func extractProcInfo(sktab *SockTabEntry) {
const basedir = "/proc"
fi, err := ioutil.ReadDir(basedir)
if err != nil {
@ -263,7 +262,7 @@ func doNetstat(path string, fn AcceptFn) ([]SockTabEntry, error) {
if err != nil {
return nil, err
}
extractProcInfo(tabs)
//extractProcInfo(tabs)
return tabs, nil
}

Loading…
Cancel
Save