diff --git a/netstat/netstat.go b/netstat/netstat.go index a5c0e69..4d95c51 100644 --- a/netstat/netstat.go +++ b/netstat/netstat.go @@ -27,12 +27,12 @@ type SockTabEntry struct { // Process holds the PID and process name to which each socket belongs type Process struct { - pid int - name string + Pid int + Name string } func (p *Process) String() string { - return fmt.Sprintf("%d/%s", p.pid, p.name) + return fmt.Sprintf("%d/%s", p.Pid, p.Name) } // SkState type represents socket connection state diff --git a/netstat/netstat_linux.go b/netstat/netstat_linux.go index 43ab3f5..35e0cd7 100644 --- a/netstat/netstat_linux.go +++ b/netstat/netstat_linux.go @@ -213,13 +213,13 @@ func (p *procFd) iterFdDir() { return } n, err := stat.Read(buf[:]) - stat.Close() if err != nil { return } z := bytes.SplitN(buf[:n], []byte(" "), 3) name := getProcName(z[1]) p.p = &Process{p.pid, name} + stat.Close() } sk.Process = p.p } @@ -250,11 +250,11 @@ func extractProcInfo(sktab []SockTabEntry) { // doNetstat - collect information about network port status func doNetstat(path string, fn AcceptFn) ([]SockTabEntry, error) { f, err := os.Open(path) + defer f.Close() if err != nil { return nil, err } tabs, err := parseSocktab(f, fn) - f.Close() if err != nil { return nil, err } diff --git a/netstat/netstat_windows.go b/netstat/netstat_windows.go index cffeedc..8e3b289 100644 --- a/netstat/netstat_windows.go +++ b/netstat/netstat_windows.go @@ -123,8 +123,8 @@ func (pid WinPid) Process(snp ProcessSnapshot) *Process { return nil } return &Process{ - pid: int(pid), - name: snp.ProcPIDToName(uint32(pid)), + Pid: int(pid), + Name: snp.ProcPIDToName(uint32(pid)), } }