示例#1
0
文件: packet_arp.c 项目: Paxy/Jpcap
int set_arp(JNIEnv *env,jobject packet,u_char *pointer){
	/** XXX assume Ethernet ARP**/
  struct ether_arp *arp=(struct ether_arp *)pointer;

  arp->arp_hrd=htons(GetShortField(ARPPacket,packet,"hardtype"));
  arp->arp_pro=htons(GetShortField(ARPPacket,packet,"prototype"));
  arp->arp_op=htons(GetShortField(ARPPacket,packet,"operation"));
  arp->arp_hln=(u_char)GetShortField(ARPPacket,packet,"hlen");
  arp->arp_pln=(u_char)GetShortField(ARPPacket,packet,"plen");

  (*env)->GetByteArrayRegion(env,
	  GetObjectField(ARPPacket,packet,"[B","sender_hardaddr"),
	  0,arp->arp_hln,arp->arp_sha);
  (*env)->GetByteArrayRegion(env,
	  GetObjectField(ARPPacket,packet,"[B","sender_protoaddr"),
	  0,arp->arp_pln,arp->arp_spa);
  (*env)->GetByteArrayRegion(env,
	  GetObjectField(ARPPacket,packet,"[B","target_hardaddr"),
	  0,arp->arp_hln,arp->arp_tha);
  (*env)->GetByteArrayRegion(env,
	  GetObjectField(ARPPacket,packet,"[B","target_protoaddr"),
	  0,arp->arp_pln,arp->arp_tpa);

  return sizeof(struct ether_arp);
}
示例#2
0
static int
setFormat(JNIEnv *env, jobject jxil, InstanceState *inst)
{
    jboolean isInstance;
    jobject jStream;

    /*    Debug Message */
    PRINT("XILCapture in setFormat \n");

    jStream = GetObjectField(env, jxil, "stream",
				"Ljavax/media/protocol/SourceStream;");
    if (!jStream) {
	/*    Debug Message */
	PRINT("XILCapture setFormat failed to obtain stream \n");
	return 0;
    }
    isInstance = IsInstanceOf(env, jStream, 
			"com/sun/media/protocol/sunvideo/SunVideoSourceStream");
    if (!isInstance) {
	/*    Debug Message */
	PRINT("XILCapture setFormat stream not valid instance \n");
	return 0;
    }
    if (inst->do_cis == RAW) {
	return formatRaw(env, jxil, inst, jStream);
    } else if (inst->do_cis == JPEG) {
	return formatJpeg(env, jxil, inst, jStream);
    } else {
	return formatMpeg(env, jxil, inst, jStream);
    }
}
示例#3
0
int set_ether(JNIEnv *env,jobject packet,char *pointer){
	packet=GetObjectField(Packet,packet,"Ljpcap/packet/DatalinkPacket;","datalink");
	if(packet!=NULL && IsInstanceOf(packet,EthernetPacket)){
		struct ether_header *ether_hdr=(struct ether_header *)pointer;

		jbyteArray src=GetObjectField(EthernetPacket,packet,"[B","src_mac");
		jbyteArray dst=GetObjectField(EthernetPacket,packet,"[B","dst_mac");

		(*env)->GetByteArrayRegion(env,src,0,6,(char *)&ether_hdr->ether_src);
		(*env)->GetByteArrayRegion(env,dst,0,6,(char *)&ether_hdr->ether_dest);
		ether_hdr->ether_type=htons(GetShortField(EthernetPacket,packet,"frametype"));

  (*env)->ExceptionDescribe(env);
		return sizeof(struct ether_header);
	}
	return 0;
}
示例#4
0
pattern* createCPattern(JNIEnv *env, jobject jpat)
{
	if (jpat == NULL) return NULL;
	pattern* rv = (pattern*) malloc(sizeof(pattern));
	rv->bit_length = GetIntField(env, jpat, "bit_length");
	rv->length = GetIntField(env, jpat, "length");
	rv->r_flag = (char)GetCharField(env, jpat, "r_flag");
	jbyteArray jdata = (jbyteArray)GetObjectField(env, jpat, "bytes", "[B");
	jbyte* jdataArray = (*env)->GetByteArrayElements(env, jdata, NULL);
	rv->bytes = (unsigned char*) malloc((*env)->GetArrayLength(env, jdata));
	memcpy((void*)rv->bytes, (void*)jdataArray, (*env)->GetArrayLength(env, jdata));
	(*env)->ReleaseByteArrayElements(env, jdata, jdataArray, JNI_ABORT);
	jobject nextPat = GetObjectField(env, jpat, "next", "Lsage/SFIRTuner$Pattern;");
	rv->next = NULL;
	if (nextPat != NULL)
		rv->next = createCPattern(env, nextPat);
	return rv;
}
示例#5
0
command* createCCmd(JNIEnv *env, jobject jcmd)
{
	if (jcmd == NULL) return NULL;
	command* rv = (command*) malloc(sizeof(command));
	jstring jname = (jstring) GetObjectField(env, jcmd, "name", "Ljava/lang/String;");
	const char* cname = (*env)->GetStringUTFChars(env, jname, NULL);
	rv->name = (unsigned char*) malloc((*env)->GetStringLength(env, jname) + 1);
	strcpy((char*)rv->name, cname);
	(*env)->ReleaseStringUTFChars(env, jname, cname);
	rv->pattern = NULL;
	jobject currPat = GetObjectField(env, jcmd, "pattern", "Lsage/SFIRTuner$Pattern;");
	if (currPat != NULL)
	{
		rv->pattern = createCPattern(env, currPat);
	}
	jobject nextCmd = GetObjectField(env, jcmd, "next", "Lsage/SFIRTuner$Command;");
	rv->next = NULL;
	if (nextCmd != NULL)
		rv->next = createCCmd(env, nextCmd);
	return rv;
}
示例#6
0
文件: JpcapWriter.c 项目: Paxy/Jpcap
JNIEXPORT void JNICALL
Java_jpcap_JpcapWriter_writePacket(JNIEnv *env,jobject obj,jobject packet){
	jbyteArray header,body;
	int hlen,blen;
	struct pcap_pkthdr hdr;
	char buf[MAX_PACKET_SIZE];

	hdr.ts.tv_sec=(long)GetLongField(Packet,packet,"sec");
	hdr.ts.tv_usec=(long)GetLongField(Packet,packet,"usec");
	hdr.caplen=GetIntField(Packet,packet,"caplen");
	hdr.len=GetIntField(Packet,packet,"len");

	header=GetObjectField(Packet,packet,"[B","header");
	body=GetObjectField(Packet,packet,"[B","data");

	hlen=(*env)->GetArrayLength(env,header);
	blen=(*env)->GetArrayLength(env,body);

	(*env)->GetByteArrayRegion(env,header,0,hlen,buf);
	(*env)->GetByteArrayRegion(env,body,0,blen,(char *)(buf+hlen));

	pcap_dump((u_char *)pdt,&hdr,buf);
}
示例#7
0
remote* createCRemote(JNIEnv *env, jobject jremote)
{
	if (jremote == NULL) return NULL;
	remote* rv = (remote*)malloc(sizeof(remote));
	jstring jname = (jstring) GetObjectField(env, jremote, "name", "Ljava/lang/String;");
	const char* cname = (*env)->GetStringUTFChars(env, jname, NULL);
	rv->name = (unsigned char*) malloc((*env)->GetStringLength(env, jname) + 1);
	strcpy((char*)rv->name, cname);
	(*env)->ReleaseStringUTFChars(env, jname, cname);
	rv->carrier_freq = (unsigned long) GetLongField(env, jremote, "carrier_freq");
	rv->bit_time = (unsigned) GetLongField(env, jremote, "bit_time");
	rv->command = NULL;
	jobject currCmd = GetObjectField(env, jremote, "command", "Lsage/SFIRTuner$Command;");
	if (currCmd != NULL)
	{
		rv->command = createCCmd(env, currCmd);
	}
	jobject nextRemote = GetObjectField(env, jremote, "next", "Lsage/SFIRTuner$Remote;");
	rv->next = NULL;
	if (nextRemote != NULL)
		rv->next = createCRemote(env, nextRemote);
	return rv;
}
示例#8
0
/*
 * Java_java_io_PrintStream.c
 *
 *  Created on: Oct 28, 2011
 *      Author: hammer
 */

#include "jni.h"
#include "heap.h"
#include "console.h"
#include "constantpool.h"
#include "vmids.h"

void JNICALL Java_java_io_PrintStream_outString(JNIEnv *env, jobject this, jstring s) {
	u2 linkId = LINK_ID_java_lang_String_value__C;
	jcharArray charArray = (jcharArray) GetObjectField(s, linkId);

	size_t length = GetArrayLength(charArray);
	size_t i;
	for (i = 0; i < length; i++) {
		consout("%c", GetCharArrayElement(charArray, i));
	}
}

void JNICALL Java_java_io_PrintStream_outStringLf(JNIEnv *env, jobject this, jstring s) {
	Java_java_io_PrintStream_outString(env, this, s);
	consout("\n");
}