From 894fe8adae2dab2ada1407f41281e2a389f5f316 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 8 May 2005 18:44:28 +0000 Subject: [PATCH] make outbound info more useful and more like the inbound --- .../src/net/hyperic/sigar/NetPortMap.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/NetPortMap.java b/bindings/java/src/net/hyperic/sigar/NetPortMap.java index 06cf2053..17a918ec 100644 --- a/bindings/java/src/net/hyperic/sigar/NetPortMap.java +++ b/bindings/java/src/net/hyperic/sigar/NetPortMap.java @@ -77,13 +77,12 @@ public class NetPortMap { String ip = conn.getRemoteAddress(); if (addresses == null) { - ip = conn.getLocalAddress(); - String key = - conn.getRemoteAddress() + ":" + conn.getRemotePort(); - addresses = (Map)this.outbound.get(key); + ip = conn.getRemoteAddress(); + port = new Long(conn.getRemotePort()); + addresses = (Map)this.outbound.get(port); if (addresses == null) { addresses = new HashMap(); - this.outbound.put(key, addresses); + this.outbound.put(port, addresses); } } @@ -113,14 +112,8 @@ public class NetPortMap { return this.states; } - public static void main(String[] args) throws Exception { - NetPortMap map = new NetPortMap(); - map.stat(); - - System.out.println("Inbound Connections..."); - Map ports = map.getInboundConnections(); - - for (Iterator it = ports.entrySet().iterator(); + private static void dumpConnections(Map map) { + for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry)it.next(); @@ -128,18 +121,17 @@ public class NetPortMap { Map addresses = (Map)entry.getValue(); System.out.println(port + "=" + addresses); } + } + + public static void main(String[] args) throws Exception { + NetPortMap map = new NetPortMap(); + map.stat(); + + System.out.println("Inbound Connections..."); + dumpConnections(map.getInboundConnections()); System.out.println("\nOutbound Connections..."); - Map outbound = map.getOutboundConnections(); - - for (Iterator it = outbound.entrySet().iterator(); - it.hasNext();) - { - Map.Entry entry = (Map.Entry)it.next(); - String server = (String)entry.getKey(); - Map addresses = (Map)entry.getValue(); - System.out.println(server + "=" + addresses); - } + dumpConnections(map.getOutboundConnections()); System.out.println("\nStates..."); int[] states = map.getStates();