Esempio n. 1
0
void filename_create_new(
    void)
{
    if (pFile) {
        fclose(pFile);
    }
    pFile = NULL;
    filename_create(&Capture_Filename[0]);
    write_global_header(&Capture_Filename[0]);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int d;
	int ret = 0;

	FILE *pcap;
	if(argc<2)
	{
		printf(	"Usage:coa_syncsniff channel pcap-file [RFPI]\n");
		exit(-1);	
	}

	d=open(DEV, O_RDONLY);
	if (d<0)
	{
		printf("couldn't open(\"%s\"): %s\n", DEV, strerror(errno));
		exit(1);
	}

        pcap=fopen(argv[2],"wb");
        if(!pcap)
        {
		printf("Cant open pcap file for write...\n");
		exit(1);
	}

	/* optionally accept RFPI as 3rd argument on commandline */
	if(argc>2)
	{
		sscanf(argv[3], "%hhx %hhx %hhx %hhx %hhx", &RFPI[0], &RFPI[1], &RFPI[2], &RFPI[3], &RFPI[4]);
		printf("RFPI: %02x %02x %02x %02x %02x\n", RFPI[0], RFPI[1], RFPI[2], RFPI[3], RFPI[4]);
	}


	//set sync sniff mode
	uint16_t val;
	val = COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SYNC;
	if(ioctl(d,COA_IOCTL_MODE, &val)){printf("couldn't ioctl()\n");exit(1);}

	//set rfpi to sync with
	if(ioctl(d,COA_IOCTL_SETRFPI, RFPI)){printf("couldn't ioctl()\n");exit(1);}

	//set channel
	uint32_t chn=atoi(argv[1]);
	printf("set channel %u\n",chn);
	if(ioctl(d,COA_IOCTL_CHAN,&chn)){printf("couldn't set channel\n");exit(1);}


	write_global_header(pcap);

	//sniff-loop
        while (0xDEC + 't')
	{
		struct sniffed_packet buf;
	        while (sizeof(struct sniffed_packet) == (ret = read(d, &buf, (sizeof(struct sniffed_packet)))))
		{
	        	unsigned char packet[100];
			packet[12]=0x23;
			packet[13]=0x23;
			packet[14]=0x00;		//decttype (receive)
			packet[15]=buf.channel;		//channel
			packet[16]=0;
			packet[17]=buf.slot;		//slot
			packet[18]=0;
			packet[19]=buf.rssi;
			memcpy(packet+20,buf.data,53);

			write_record(
				pcap,
				buf.timestamp.tv_sec,
				buf.timestamp.tv_nsec/1000,
				73,
				packet);
		}
	}





	return ret;
}