diff options
author | kballou <kballou@devnulllabs.io> | 2015-05-05 18:28:20 -0600 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2015-05-07 17:00:54 -0600 |
commit | c0c2f5d481ed447ade83d7e3100aa359d9c6bc81 (patch) | |
tree | 41df83d741b4820f2e6a1d25e033e8ad0dfc512b /goprocnet_test.go | |
parent | 1e72998c4c3829e4ee4053cacf98e8769376e946 (diff) | |
download | goprocnet-c0c2f5d481ed447ade83d7e3100aa359d9c6bc81.tar.gz goprocnet-c0c2f5d481ed447ade83d7e3100aa359d9c6bc81.tar.xz |
Implement netstat like functionality
* Caveat with current implementation: if the current context does not own
the process of a socket, PID lookup (and thus name and exe) will fail.
Diffstat (limited to 'goprocnet_test.go')
-rw-r--r-- | goprocnet_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/goprocnet_test.go b/goprocnet_test.go new file mode 100644 index 0000000..734a22f --- /dev/null +++ b/goprocnet_test.go @@ -0,0 +1,39 @@ +package goprocnet + +import ( + "testing" +) + +func TestTypeToFileMap(t *testing.T) { + result := getFilename("tcp") + if result != "/proc/net/tcp" { + t.Fail() + } + result = getFilename("udp") + if result != "/proc/net/udp" { + t.Fail() + } + result = getFilename("foobar") + if result != "" { + t.Fail() + } +} + +func TestParseIPPort(t *testing.T) { + ip := getIP("00000000") + port := getPort("006F") + if ip != "0.0.0.0" { + t.Fail() + } + if port != "111" { + t.Fail() + } + ip = getIP("0B01010A") + if ip != "10.1.1.11" { + t.Fail() + } + port = getPort("CAEF") + if port != "51951" { + t.Fail() + } +} |