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