I have been using Cooja in Instant Contiki v2.7. I have added the global and pcap header in the write_to_serial()
function in tunslip6.c . Later these packets are sent to the named pipe /tmp/myfifo
(which will be the interface for wireshark). And then to display it in wireshark. But when the wireshark is opened (wireshark -k -i /tmp/myfifo), it gives the prompt
" Frame 1 too long (-16711680 bytes) "
Below is the code snippet of write_to_serial()
.
if(verbose>2) {
if (timestamp) stamptime();
printf("Packet from TUN of length %d - write SLIP\n", len);
if (verbose>4) {
#if WIRESHARK_IMPORT_FORMAT
printf("0000");
for(i = 0; i < len; i++) {
printf(" %02x",p[i]);
}
mkfifo(myfifo,0777);
fd=open(myfifo,O_WRONLY);
//add global header only once and packet header
if(gb==0) //gb globally declared ; int gb=0
{
header.magic = 0xa1b2c3d4;
header.version_major = 2;
header.version_minor = 4;
header.thiszone =0;
header.sigfigs = 0;
header.snaplen = 65535;
header.linktype = 113;
bufg[0]=header.magic ;
bufg[1]=header.version_major ;
bufg[2]=header.version_minor ;
bufg[3]=header.thiszone ;
bufg[4]=header.sigfigs ;
bufg[5]=header.snaplen ;
bufg[6]=header.linktype;
// pcap packet header
gettimeofday(&time,0);
pcap_header.ts.tv_sec = time.tv_sec;
pcap_header.ts.tv_usec = time.tv_usec;
pcap_header.caplen = len;
pcap_header.len = len;
bufp[0]=pcap_header.ts.tv_sec ;
bufp[1]=pcap_header.ts.tv_usec ;
bufp[2]=pcap_header.caplen ;
bufp[3]=pcap_header.len ;
if (((write(fd,bufg,7))&&(write(fd,bufp,4))&&(write(fd,p,len)))< 0)
fputs("write() of bytes failed!\n", stderr);
else
printf("\nSuccessfully wrote bytes ");
gb++;
}
else if(gb>0)
{
gettimeofday(&time,0);
pcap_header.ts.tv_sec = time.tv_sec;
pcap_header.ts.tv_usec = time.tv_usec;
pcap_header.caplen = len;
pcap_header.len = len;
bufp[0]=pcap_header.ts.tv_sec ;
bufp[1]=pcap_header.ts.tv_usec ;
bufp[2]=pcap_header.caplen ;
bufp[3]=pcap_header.len ;
if (((write(fd,bufp,4))&&(write(fd,p,len)))< 0)
fputs("write() of bytes failed!\n", stderr);
else
printf("Successfully wrote bytes\n");
}
#endif
The value printed by the pointer p is
Packet from TUN of length 48 - write SLIP
0000 60 00 00 00 00 08 3a ff fe 80 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ff 02 00 00 00 00 00 00 00 00 00 00 00 00 00 02 85 00 7d 36 00 00 00 00
And the fifo is dumped with the values:
0000000 a1b2c3d4 92000002 60567aeb 00000000
0000020 feff3a08 00000080 00000000 00000000
0000040 ff010000 00000002 00000000 00000000
0000060 85020000 00367d00 93000000 60567aeb
0000100 00000000 feff3a08 00000080 00000000
0000120 00000000 ff010000 00000002 00000000
0000140 00000000 85020000 00367d00 97000000
0000160 60567aeb 00000000 feff3a08 00000080
0000200 00000000 00000000 ff010000 00000002
0000220 00000000 00000000 85020000 00367d00
What should be done inorder to rectify this error?