replace nfs_ping with generic rpc_ping

This commit is contained in:
Doug MacEachern 2006-02-26 23:31:07 +00:00
parent 58435e27ab
commit b3fda3e6c1
6 changed files with 39 additions and 10 deletions

View File

@ -1,3 +1,7 @@
2006-02-26 Doug MacEachern <dougm@hyperic.net>
* Replace sigar_nfs_ping with generic sigar_rpc_ping
2006-02-23 Doug MacEachern <dougm@hyperic.net> 2006-02-23 Doug MacEachern <dougm@hyperic.net>
* Use asm/cpuid instead of /proc/cpuinfo to detect * Use asm/cpuid instead of /proc/cpuinfo to detect

View File

@ -410,8 +410,9 @@ JNIEXPORT jobjectArray SIGAR_JNI(Sigar_getFileSystemListNative)
return fsarray; return fsarray;
} }
JNIEXPORT jboolean SIGAR_JNI(NfsFileSystem_ping) JNIEXPORT jboolean SIGAR_JNI(RPC_ping)
(JNIEnv *env, jclass cls_obj, jstring jhostname) (JNIEnv *env, jclass cls_obj, jstring jhostname,
jint protocol, jlong program, jlong version)
{ {
#ifdef WIN32 #ifdef WIN32
return JNI_FALSE; /*XXX*/ return JNI_FALSE; /*XXX*/
@ -426,7 +427,9 @@ JNIEXPORT jboolean SIGAR_JNI(NfsFileSystem_ping)
hostname = JENV->GetStringUTFChars(env, jhostname, &is_copy); hostname = JENV->GetStringUTFChars(env, jhostname, &is_copy);
retval = (sigar_nfs_ping((char *)hostname) == SIGAR_OK); retval =
(sigar_rpc_ping((char *)hostname,
protocol, program, version) == SIGAR_OK);
if (is_copy) { if (is_copy) {
JENV->ReleaseStringUTFChars(env, jhostname, hostname); JENV->ReleaseStringUTFChars(env, jhostname, hostname);

View File

@ -5,8 +5,6 @@ import java.net.UnknownHostException;
public class NfsFileSystem extends FileSystem { public class NfsFileSystem extends FileSystem {
public static native boolean ping(String hostname);
String hostname = null; String hostname = null;
public String getHostname() { public String getHostname() {
@ -30,7 +28,7 @@ public class NfsFileSystem extends FileSystem {
} }
public boolean ping() { public boolean ping() {
return ping(getHostname()); return RPC.ping(getHostname(), RPC.NFS);
} }
public String getUnreachableMessage() { public String getUnreachableMessage() {
@ -43,6 +41,6 @@ public class NfsFileSystem extends FileSystem {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Sigar.load(); Sigar.load();
System.out.println(NfsFileSystem.ping(args[0])); System.out.println(RPC.ping(args[0], RPC.NFS));
} }
} }

View File

@ -0,0 +1,18 @@
package net.hyperic.sigar;
public class RPC {
public static final int UDP = NetFlags.CONN_UDP;
public static final int TCP = NetFlags.CONN_TCP;
public static final long NFS = 100003;
public static native boolean ping(String hostname,
int protocol,
long program,
long version);
public static boolean ping(String hostname, long program) {
return ping(hostname, UDP, program, 2);
}
}

View File

@ -615,7 +615,10 @@ SIGAR_DECLARE(int) sigar_inet_ntoa(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen); SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen);
SIGAR_DECLARE(int) sigar_nfs_ping(char *hostname); SIGAR_DECLARE(int) sigar_rpc_ping(char *hostname,
int protocol,
unsigned long program,
unsigned long version);
SIGAR_DECLARE(char *) sigar_password_get(const char *prompt); SIGAR_DECLARE(char *) sigar_password_get(const char *prompt);

View File

@ -510,7 +510,10 @@ static int get_sockaddr(struct sockaddr_in *addr, char *host)
return SIGAR_OK; return SIGAR_OK;
} }
SIGAR_DECLARE(int) sigar_nfs_ping(char *host) SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
int protocol,
unsigned long program,
unsigned long version)
{ {
CLIENT *client; CLIENT *client;
struct sockaddr_in addr; struct sockaddr_in addr;
@ -527,7 +530,7 @@ SIGAR_DECLARE(int) sigar_nfs_ping(char *host)
interval.tv_usec = 0; interval.tv_usec = 0;
addr.sin_port = htons(port); addr.sin_port = htons(port);
sock = RPC_ANYSOCK; sock = RPC_ANYSOCK;
client = clntudp_create(&addr, NFS_PROGRAM, NFS_VERSION, client = clntudp_create(&addr, program, version,
interval, &sock); interval, &sock);
if (!client) { if (!client) {
return -1; return -1;