summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2015-05-11 13:51:56 -0600
committerkballou <kballou@devnulllabs.io>2015-05-11 16:41:15 -0600
commit47cc3b4d77a189e5ca6de06d7e87b07f0f643fc2 (patch)
tree38dbdc17c7cb0ab33a0a946c138c34453bc4f4ae
parent110ee50fe91cc66ec712febf6430c82bc2a2dfe1 (diff)
downloadgoprocnet-master.tar.gz
goprocnet-master.tar.xz
Change Socket Port Types to `int32`HEADmaster
-rw-r--r--goprocnet.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/goprocnet.go b/goprocnet.go
index 23e933b..9f789df 100644
--- a/goprocnet.go
+++ b/goprocnet.go
@@ -39,13 +39,13 @@ type Socket struct {
Name string
State string
LocalIP string
- LocalPort string
+ LocalPort int32
RemoteIP string
- RemotePort string
+ RemotePort int32
}
func (s Socket) String() string {
- return fmt.Sprintf("%s\t%s\t%s\t%s\t%s:%s\t%s:%s",
+ return fmt.Sprintf("%s\t%s\t%s\t%s\t%s:%d\t%s:%d",
s.PID,
s.UID,
s.Bin,
@@ -139,16 +139,24 @@ func netstat(t string) ([]Socket, error) {
var sockets []Socket
+ mustParse := func(p string) int32 {
+ i, err := strconv.ParseInt(p, 10, 32)
+ if err != nil {
+ log.Panic(err)
+ }
+ return int32(i)
+ }
+
for _, line := range lines {
values := removeInnerSpace(strings.Split(strings.TrimSpace(line), " "))
ipPort := strings.Split(values[1], ":")
localIP := getIP(ipPort[0])
- localPort := getPort(ipPort[1])
+ localPort := mustParse(getPort(ipPort[1]))
remIpPort := strings.Split(values[2], ":")
remoteIP := getIP(remIpPort[0])
- remotePort := getPort(remIpPort[1])
+ remotePort := mustParse(getPort(remIpPort[1]))
state := STATE[values[3]]
uid := values[7]