From 041ab0034f46e05e5e9b6d49ef7b1151dd623447 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 28 Feb 2006 19:24:04 +0000 Subject: [PATCH] add getNetListenAddress method --- .../java/src/net/hyperic/sigar/Sigar.java | 40 +++++++++++++++++++ .../src/net/hyperic/sigar/SigarProxy.java | 6 +++ .../net/hyperic/sigar/test/TestNetStat.java | 13 ++++++ 3 files changed, 59 insertions(+) diff --git a/bindings/java/src/net/hyperic/sigar/Sigar.java b/bindings/java/src/net/hyperic/sigar/Sigar.java index 0b14e4a6..78e1f885 100644 --- a/bindings/java/src/net/hyperic/sigar/Sigar.java +++ b/bindings/java/src/net/hyperic/sigar/Sigar.java @@ -637,6 +637,46 @@ public class Sigar implements SigarProxy { public native NetConnection[] getNetConnectionList(int flags) throws SigarException; + /** + * Get the TCP listen address for the given port. + * If the port is not bound to a specific address, + * the loopback address will be returned. + * If there is not a listener on the given port, null will be returned. + */ + public String getNetListenAddress(long port) + throws SigarException { + + int flags = NetFlags.CONN_SERVER | NetFlags.CONN_TCP; + + NetConnection[] connections = + getNetConnectionList(flags); + + for (int i=0; i