示例#1
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setShort0
 * Signature: (JZIS)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setShort0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index, jshort jval) {
	
	u_int16_t *mem = (u_int16_t *)toPtr(address + index);
	
	*(mem) = ENDIAN16_GET(big, jval);
}
/*
 * Class:     org_jnetpcap_packet_JScannerReference
 * Method:    disposeNative
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_packet_JScannerReference_disposeNative
(JNIEnv *env, jobject obj, jlong size) {

	jlong pt = env->GetLongField(obj, jmemoryRefAddressFID);
	scanner_t *scanner = (scanner_t *)toPtr(pt);
	if (scanner == NULL) {
		return;
	}

	env->DeleteGlobalRef(scanner->sc_jscan);
	scanner->sc_jscan = NULL;

	if (scanner->sc_subheader != NULL) {
		free(scanner->sc_subheader);
		scanner->sc_subheader = NULL;
	}

	for (int i = 0; i < MAX_ID_COUNT; i ++) {
		if (scanner->sc_java_header_scanners[i] != NULL) {
			env->DeleteGlobalRef(scanner->sc_java_header_scanners[i]);
			scanner->sc_java_header_scanners[i] = NULL;
		}
	}

	/*
	 * Same as super.dispose(): call from JScannerReference.dispose for
	 * JMemoryReference.super.dispose.
	 */
//	Java_org_jnetpcap_nio_JMemoryReference_disposeNative0(env, obj, pt, size);
}
示例#3
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setUByte0
 * Signature: (JII)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setUByte0
(JNIEnv *env, jclass clazz, jlong address, jint index, jint jval) {
	
	jbyte *mem = (jbyte *)toPtr(address + index);
	
	*(mem) = (jbyte) jval;
}
示例#4
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setUInt0
 * Signature: (JZIJ)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setUInt0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index, jlong jval) {
	
	u_int32_t *mem = (u_int32_t *)toPtr(address + index);
	
	register jint temp = (jint) jval;
	
	*(mem) = ENDIAN32_GET(big, temp);
}
示例#5
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setByteArray0
 * Signature: (JI[BI)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setByteArray0
  (JNIEnv *env, jclass clazz, jlong address, jint index, jbyteArray jarray, jint jarraySize) {
	
	jbyte *mem = (jbyte *)toPtr(address + index);
	
	env->GetByteArrayRegion(jarray, 0, jarraySize, (mem));
	
	return;
}
示例#6
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setUShort0
 * Signature: (JZII)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setUShort0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index, jint jval) {
	
	uint16_t *mem = (uint16_t *)toPtr(address + index);
	
	register jshort temp = (jshort) jval;
	
	*(mem) = ENDIAN16_GET(big, temp);
}
示例#7
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setLong0
 * Signature: (JZIJ)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setLong0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index, jlong jval) {
	
	address += index;

	uint64_t *mem = (uint64_t *)toPtr(address);
	
	*(mem) = ENDIAN64_GET(big, jval);
}
示例#8
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    getByteArray0
 * Signature: (JI[BIII)[B
 */
JNIEXPORT jbyteArray JNICALL Java_org_jnetpcap_nio_JBuffer_getByteArray0
  (JNIEnv *env, jclass clazz, jlong address, jint index, jbyteArray jarray,
		  jint jarraySize, jint offset, jint length) {
	
	jbyte *mem = (jbyte *)toPtr(address + index);
	
	env->SetByteArrayRegion(jarray, offset, length, mem);
	
	return jarray;
}
示例#9
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    getUShort0
 * Signature: (JZI)I
 */
JNIEXPORT jint JNICALL Java_org_jnetpcap_nio_JBuffer_getUShort0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index) {
	
	u_int16_t *mem = (u_int16_t *)toPtr(address + index);

	/*
	 * For efficiency of the endian byte swapping, convert to an atom and use
	 * a CPU register if possible during conversion.
	 */
	register u_int16_t data = *(mem);
	
	return (jint) ENDIAN16_GET(big, data);
}
示例#10
0
pcap_t *getPcap(JNIEnv *env, jobject obj) {
	jlong pt = env->GetLongField(obj, pcapPhysicalFID);

	if (pt == 0) {
		throwException(env, PCAP_CLOSED_EXCEPTION, NULL);

		return NULL;
	}

	pcap_t *p = (pcap_t *) toPtr(pt);

	return p;
}
示例#11
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    getUByte0
 * Signature: (JI)I
 */
JNIEXPORT jint JNICALL Java_org_jnetpcap_nio_JBuffer_getUByte0
(JNIEnv *env, jclass clazz, jlong address, jint index) {
	
	jbyte *mem = (jbyte *)toPtr(address + index);

	/*
	 * For efficiency of the endian byte swapping, convert to an atom and use
	 * a CPU register if possible during conversion.
	 */
	register u_int8_t data = (u_int8_t)*(mem);
	
	return (jint) data;

}
示例#12
0
bpf_program *getBpfProgram(JNIEnv *env, jobject obj) {
	
	jlong pt = env->GetLongField(obj, bpfProgramPhysicalFID);

	if (pt == 0) {
		throwException(env, ILLEGAL_STATE_EXCEPTION,
				"BpfProgram is NULL, not possible (bpf_program).");

		return NULL;
	}

	bpf_program *p = (bpf_program *) toPtr(pt);

	return p;
}
示例#13
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    setFloat0
 * Signature: (JZIF)V
 */
JNIEXPORT void JNICALL Java_org_jnetpcap_nio_JBuffer_setFloat0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index, jfloat jval) {
	
	u_int32_t *mem = (u_int32_t *)toPtr(address + index);
	
	/*
	 * For efficiency of the endian byte swapping, convert to an atom and use
	 * a CPU register if possible during conversion.
	 */
	u_int32_t data = *(u_int32_t *)(&jval);

	/*
	 * We can't just typecast u_int32 to a float. The float has to be read
	 * out of memory using a float pointer.
	 */
	*(mem) = ENDIAN32_GET(big, data);
}
示例#14
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    getDouble0
 * Signature: (JZI)D
 */
JNIEXPORT jdouble JNICALL Java_org_jnetpcap_nio_JBuffer_getDouble0
(JNIEnv *env, jclass clazz, jlong address, jboolean big, jint index) {
	
	u_int64_t *mem = (u_int64_t *)toPtr(address + index);

	/*
	 * For efficiency of the endian byte swapping, convert to an atom and use
	 * a CPU register if possible during conversion.
	 */
	 u_int64_t data = *(mem);
	 
	/*
	 * We can't just typecast u_int64 to a double. The double has to be read
	 * out of memory using a double pointer.
	 */
	data = ENDIAN64_GET(big, data);
	return *((jdouble *)&data);
}
示例#15
0
/*
 * Class:     org_jnetpcap_nio_JBuffer
 * Method:    getByte0
 * Signature: (JI)B
 */
JNIEXPORT jbyte JNICALL Java_org_jnetpcap_nio_JBuffer_getByte0
  (JNIEnv *env, jclass clazz, jlong address, jint index) {
	return *((jbyte *)toPtr(address + index));
}
示例#16
0
/*
 * Function: getPcapDumper
 * Description: retrieves the peering structure by looking up its address within
 *              the java object.
 * Return: ptr to the structure or null on exception
 */
pcap_dumper_t *getPcapDumper(JNIEnv *env, jobject obj) {

	jlong physical = env->GetLongField(obj, pcapDumperPhysicalFID);

	return (pcap_dumper_t *)toPtr(physical);
}