replace getNetListenAddress with native function
This commit is contained in:
parent
66fe4fee09
commit
873849d4aa
@ -928,6 +928,22 @@ JNIEXPORT void SIGAR_JNI(NetStat_stat)
|
|||||||
JENV->SetObjectField(env, obj, id, states);
|
JENV->SetObjectField(env, obj, id, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring SIGAR_JNIx(getNetListenAddress)
|
||||||
|
(JNIEnv *env, jobject sigar_obj, jlong port)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
sigar_net_address_t address;
|
||||||
|
dSIGAR(NULL);
|
||||||
|
|
||||||
|
status = sigar_net_listen_address_get(sigar, port, &address);
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
sigar_throw_error(env, jsigar, status);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return jnet_address_to_string(env, sigar, &address);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring SIGAR_JNI(NetConnection_getTypeString)
|
JNIEXPORT jstring SIGAR_JNI(NetConnection_getTypeString)
|
||||||
(JNIEnv *env, jobject obj)
|
(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
|
@ -749,43 +749,10 @@ public class Sigar implements SigarProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the TCP listen address for the given port.
|
* 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.
|
* If there is not a listener on the given port, null will be returned.
|
||||||
*/
|
*/
|
||||||
public String getNetListenAddress(long port)
|
public native String getNetListenAddress(long port)
|
||||||
throws SigarException {
|
throws SigarException;
|
||||||
|
|
||||||
int flags = NetFlags.CONN_SERVER | NetFlags.CONN_TCP;
|
|
||||||
|
|
||||||
NetConnection[] connections =
|
|
||||||
getNetConnectionList(flags);
|
|
||||||
|
|
||||||
for (int i=0; i<connections.length; i++) {
|
|
||||||
NetConnection conn = connections[i];
|
|
||||||
|
|
||||||
if (conn.getState() != NetFlags.TCP_LISTEN) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conn.getLocalPort() == port) {
|
|
||||||
String address =
|
|
||||||
conn.getLocalAddress();
|
|
||||||
|
|
||||||
if (address.equals(NetFlags.ANY_ADDR)) {
|
|
||||||
return NetFlags.LOOPBACK_ADDRESS;
|
|
||||||
}
|
|
||||||
else if (address.equals(NetFlags.ANY_ADDR_V6)) {
|
|
||||||
return NetFlags.LOOPBACK_ADDRESS_V6;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNetListenAddress(String port)
|
public String getNetListenAddress(String port)
|
||||||
throws SigarException {
|
throws SigarException {
|
||||||
|
Loading…
Reference in New Issue
Block a user