Skip to content
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

Support filtering on Process #13

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion 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/nodauf/go-netstat

go 1.13
11 changes: 5 additions & 6 deletions netstat/netstat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -221,11 +221,10 @@ func (p *procFd) iterFdDir() {
p.p = &Process{p.pid, name}
}
sk.Process = p.p
}
}
}

func extractProcInfo(sktab []SockTabEntry) {
func extractProcInfo(sktab *SockTabEntry) {
const basedir = "/proc"
fi, err := ioutil.ReadDir(basedir)
if err != nil {
Expand Down Expand Up @@ -257,7 +256,7 @@ func doNetstat(path string, fn AcceptFn) ([]SockTabEntry, error) {
if err != nil {
return nil, err
}
extractProcInfo(tabs)
//extractProcInfo(tabs)
return tabs, nil
}

Expand Down