// NOTE: only ipv4 jobject X_NewInetAddress(JNIEnv* env, jint address) { CHK_NUL_RET_NUL(env, "env"); CHK_NUL_RET_NUL(jdk_clsInet4Address, "jdk_clsInet4Address"); jobject objInetAddress = env->NewObject(jdk_clsInet4Address, jdk_clsInet4Address_initID); CHK_NUL_RET_NUL(objInetAddress, "objInetAddress"); env->SetIntField(objInetAddress, ia_AddressID, address); return objInetAddress; }
// NOTE: ipv4 only jobject X_NewInetSocketAddress(JNIEnv* env, sockaddr* sockAddr) { CHK_NUL_RET_NUL(env, "env"); CHK_NUL_RET_NUL(sockAddr, "sockAddr"); sockaddr_in* sockAddrIn = (sockaddr_in*) sockAddr; jint address = ntohl(sockAddrIn->sin_addr.s_addr); jint port = ntohs(sockAddrIn->sin_port); jobject objInetAddress = X_NewInetAddress(env, address); CHK_NUL_RET_NUL(objInetAddress, "objInetAddress"); jobject objInetSocketAddress = env->NewObject(jdk_clsInetSocketAddress, jdk_clsInetSocketAddress_initID, objInetAddress, port); CHK_NUL_RET_NUL(objInetSocketAddress, "objInetSocketAddress"); return objInetSocketAddress; }
// NOTE: only ipv4 jobject X_NewInetAddress( // JNIEnv* env, // const jint address // ) { CHK_NUL_RET_NUL(env, "env"); char valArray[4]; valArray[0] = (address & 0xFF000000) >> 24; valArray[1] = (address & 0x00FF0000) >> 16; valArray[2] = (address & 0x0000FF00) >> 8; valArray[3] = (address & 0x000000FF); const jbyteArray objArray = env->NewByteArray(4); env->SetByteArrayRegion(objArray, (jint) 0, (jint) 4, (jbyte*) valArray); const jobject objInetAddress = env->CallStaticObjectMethod( jdk_InetAddress, jdk_InetAddress_getByAddress, objArray); CHK_NUL_RET_NUL(objInetAddress, "objInetAddress"); return objInetAddress; }
// use native 64 bit long parameter jobject X_NewLong(JNIEnv* env, int64_t value) { CHK_NUL_RET_NUL(env, "env"); return env->NewObject(jdk_clsLong, jdk_clsLong_initID, (jlong) value); }
// use native 32 bit int parameter jobject X_NewInteger(JNIEnv *env, int value) { CHK_NUL_RET_NUL(env, "env"); return env->NewObject(jdk_clsInteger, jdk_clsInteger_initID, (jint) value); }
// use native bool parameter jobject X_NewBoolean(JNIEnv *env, bool value) { CHK_NUL_RET_NUL(env, "env"); return env->NewObject(jdk_clsBoolean, jdk_clsBoolean_initID, BOOLEAN(value)); }