From 3d0dc203d826b5643697617f5f13774cb088a7d1 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 11 Mar 2005 01:48:56 +0000 Subject: [PATCH] map listening tcp ports to connected remote addresses --- .../src/net/hyperic/sigar/NetPortMap.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 bindings/java/src/net/hyperic/sigar/NetPortMap.java diff --git a/bindings/java/src/net/hyperic/sigar/NetPortMap.java b/bindings/java/src/net/hyperic/sigar/NetPortMap.java new file mode 100644 index 00000000..77c65c8e --- /dev/null +++ b/bindings/java/src/net/hyperic/sigar/NetPortMap.java @@ -0,0 +1,71 @@ +package net.hyperic.sigar; + +import java.util.ArrayList; +import java.util.List; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class NetPortMap { + + /** + * Map listening tcp ports to connected remote addresses. + * key == Listening tcp port on the local machine. + * value == List of connected remote addresses. + */ + public static Map getTcpConnections(Sigar sigar) + throws SigarException { + + int flags = + NetFlags.CONN_SERVER | NetFlags.CONN_TCP; + + Map map = new HashMap(); + + NetConnection[] connections = + sigar.getNetConnectionList(flags); + + //first pass, get listening port numbers + for (int i=0; i