Merge pull request #6 from halfcrazy/feat/expose-process-info

Feat/expose process info
main
James Mills 2 months ago
commit 230359eac5
Signed by: prologic
GPG Key ID: AC4C014F1440EBD6
  1. 2
      netstat/netstat.go
  2. 12
      netstat/netstat_linux.go
  3. 2
      netstat/netstat_windows.go

@ -25,7 +25,7 @@ type SockTabEntry struct {
Process *Process
}
// Process holds the PID and process name to which each socket belongs
// Process holds the PID and process Name to which each socket belongs
type Process struct {
Pid int
Name string

@ -79,10 +79,10 @@ func parseIPv6(s string) (net.IP, error) {
for len(s) != 0 {
grp := s[0:8]
u, err := strconv.ParseUint(grp, 16, 32)
binary.LittleEndian.PutUint32(ip[i:j], uint32(u))
if err != nil {
return nil, err
}
binary.LittleEndian.PutUint32(ip[i:j], uint32(u))
i, j = i+grpLen, j+grpLen
s = s[8:]
}
@ -185,7 +185,7 @@ func getProcName(s []byte) string {
}
func (p *procFd) iterFdDir() {
// link name is of the form socket:[5860846]
// link Name is of the form socket:[5860846]
fddir := path.Join(p.base, "/fd")
fi, err := ioutil.ReadDir(fddir)
if err != nil {
@ -211,8 +211,10 @@ func (p *procFd) iterFdDir() {
if err != nil {
return
}
if stat != nil {
defer stat.Close()
}
n, err := stat.Read(buf[:])
stat.Close()
if err != nil {
return
}
@ -252,8 +254,10 @@ func doNetstat(path string, fn AcceptFn) ([]SockTabEntry, error) {
if err != nil {
return nil, err
}
if f != nil {
defer f.Close()
}
tabs, err := parseSocktab(f, fn)
f.Close()
if err != nil {
return nil, err
}

@ -394,7 +394,7 @@ func CreateToolhelp32Snapshot(flags uint32, pid uint32) (ProcessSnapshot, error)
return ret, nil
}
// ProcPIDToName translates PID to a name
// ProcPIDToName translates PID to a Name
func (snp ProcessSnapshot) ProcPIDToName(pid uint32) string {
var processEntry Processentry32
processEntry.Size = uint32(unsafe.Sizeof(processEntry))

Loading…
Cancel
Save