-
Notifications
You must be signed in to change notification settings - Fork 66
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
Feat/expose process info #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/cakturk/go-netstat | ||
|
||
go 1.13 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,10 +80,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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. |
||
i, j = i+grpLen, j+grpLen | ||
s = s[8:] | ||
} | ||
|
@@ -186,7 +186,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 { | ||
|
@@ -212,8 +212,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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. You don't need to check for nil there. |
||
return | ||
} | ||
|
@@ -253,8 +255,10 @@ func doNetstat(path string, fn AcceptFn) ([]SockTabEntry, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
if f != nil { | ||
defer f.Close() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, again, the same situation as above. Nil-check is unnecessary here as the |
||
tabs, err := parseSocktab(f, fn) | ||
f.Close() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense, a few people already asked me to export these fields.