From 841746528ab8f9986861baaa6372beb5ce522fdf Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 1 Jul 2006 19:28:53 +0000 Subject: [PATCH] fix net_stat to deal w/ sizeof(jint) != sizeof(int) --- bindings/java/src/jni/javasigar.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bindings/java/src/jni/javasigar.c b/bindings/java/src/jni/javasigar.c index 4bd582e7..93478033 100644 --- a/bindings/java/src/jni/javasigar.c +++ b/bindings/java/src/jni/javasigar.c @@ -832,7 +832,7 @@ JNIEXPORT void SIGAR_JNI(NetStat_nstat) jclass cls; jfieldID id; jintArray states; - + jint tcp_states[SIGAR_TCP_UNKNOWN]; dSIGAR_VOID; status = sigar_net_stat_get(sigar, &netstat, flags); @@ -849,9 +849,21 @@ JNIEXPORT void SIGAR_JNI(NetStat_nstat) id = JENV->GetFieldID(env, cls, "tcpOutboundTotal", "I"); JENV->SetIntField(env, obj, id, netstat.tcp_outbound_total); + if (sizeof(tcp_states[0]) == sizeof(netstat.tcp_states[0])) { + memcpy(&tcp_states[0], &netstat.tcp_states[0], + sizeof(netstat.tcp_states)); + } + else { + int i; + for (i=0; iNewIntArray(env, SIGAR_TCP_UNKNOWN); JENV->SetIntArrayRegion(env, states, 0, - SIGAR_TCP_UNKNOWN, netstat.tcp_states); + SIGAR_TCP_UNKNOWN, + tcp_states); id = JENV->GetFieldID(env, cls, "tcpStates", "[I"); JENV->SetObjectField(env, obj, id, states);