#include <stdio.h>
#include <sys/types.h>
#include <dev/ieee1394/fwiso_ioctl.h>

struct fwiso_header hdr;
unsigned char databuf[4096];

main()
{
	int capsize;
	u_int32_t isoheader;
	int i;

	while(1) {
		if (fread((void *)&hdr, sizeof(hdr), 1, stdin) < 0) {
			exit(1);
		}
		capsize = ntohl(hdr.fh_capture_size);
		isoheader = ntohl(hdr.fh_iso_header);
		printf("ISO hdr %08x: datalen %4d tag %d channel %d tcode %d sy %d\n",
		    isoheader,
		    (isoheader >> 16) & 0x0000ffff, /* len */
		    (isoheader >> 14)& 0x00000003, /* tag */
		    (isoheader >> 8)& 0x0000003f, /* channel */
		    (isoheader >> 4)& 0x0000000f, /* tcode */
		    (isoheader >> 0)& 0x0000000f); /* sy */
		if ((isoheader >> 0)& 0x0000000f) {
			printf("sy positive\n");
		}

		printf("timestamp %08x\n", ntohl(hdr.fh_timestamp));
		printf("captured size %d\n", capsize);

		if (capsize < 0 || capsize > 4096) {
			printf("bad capsize %d\n", capsize);
			exit(1);
		}

		if (fread((void *)databuf, sizeof(unsigned char), capsize - 4, stdin) != capsize - 4) {
			exit(1);
		}

#if 0
		for (i = 0; i < capsize - 4; i+= 4) {
			printf("%02x%02x", databuf[i], databuf[i + 1]);
			printf("%02x%02x\n", databuf[i + 2], databuf[i + 3]);
		}
#endif
	}

}

