62 #include <sys/types.h> 66 #include <netinet/in.h> 74 #define lseek _lseeki64 77 #define PKTBUF_SIZE (16*1024) 78 #define CAPFILE_MAX_SIZE ((size_t)-1) 94 static const char*
progname =
"capfileconvert";
128 OPT_STRING(
'f',
"outputformat", &
opt_output_format,
"Specifies the output format: <pcap | pcapnano | nt3gd | nt3gdnano>", NULL, 0, 0,
"format"),
129 OPT_STRING(
'n',
"inputformat", &
opt_input_format,
"Specifies the input format when converting a pcap file: <libpcap | ntpcap>", NULL, 0, 0,
"format"),
133 #define NT_2GD_SEGMENT_DUMP_MAGIC 0xFEDEABBA 148 NT_STID_FILE_HEADER0,
150 NT_FILE_HEADER0_COOKIE,
153 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
154 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
155 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
156 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
161 NT_STID_FILE_HEADER0,
163 NT_FILE_HEADER0_COOKIE,
166 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
167 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
168 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
169 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
172 #define PCAP_MAGIC 0xa1b2c3d4 173 #define PCAP_SWAPPED_MAGIC 0xd4c3b2a1 174 #define PCAP_MODIFIED_MAGIC 0xa1b2cd34 175 #define PCAP_SWAPPED_MODIFIED_MAGIC 0x34cdb2a1 176 #define PCAP_NSEC_MAGIC 0xa1b23c4d 177 #define PCAP_SWAPPED_NSEC_MAGIC 0x4d3cb2a1 179 #define SWAPLONG(y) \ 180 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) 181 #define SWAPSHORT(y) \ 182 ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) ) 237 for (
int i = 0;
i < 78; ++
i) {
262 size_t fSize = 0, dSize = 0;
268 int pcap_swapped = 0;
273 perror(
"Failed to allocate packet buffer of 16k\n");
280 perror(
"Failed to create output file.");
287 if ((fdin = open(
opt_input_file, _O_RDONLY | _O_BINARY, _S_IREAD)) == -1) {
293 perror(
"Failed to open input file.");
305 (void)lseek(fdin, 0, SEEK_SET);
306 tmp_fSize = lseek(fdin, 0, SEEK_END);
308 fprintf(stderr,
"The cap file is too big.\n");
313 fSize = (size_t)tmp_fSize;
314 lseek(fdin, 0, SEEK_SET);
316 fprintf(stderr,
"Input file too small.\n");
322 if ((pin = (uint8_t*)mmap(NULL, fSize, PROT_READ, MAP_PRIVATE, fdin, 0)) == MAP_FAILED) {
323 perror(
"Failed to mmap input file.\n");
333 if ((((NtFileHeader0_t*)pin)->cookie == NT_FILE_HEADER0_COOKIE) &&
334 (((NtFileHeader0_t*)pin)->structid == NT_STID_FILE_HEADER0)) {
335 printf(
"Input file detected as 3GD capture file.\n");
336 offset=
sizeof(NtFileHeader0_t);
339 printf(
"Input file detected as 3GD capture file with UNIX_NANO timestamp.\n");
343 printf(
"Input file detected as 3GD capture file.\n");
348 fprintf(stderr,
"Input format must only be set when converting a PCAP file.\n");
357 printf(
"Input file detected as \"2GD segment dump\".\n");
362 fprintf(stderr,
"Input format must only be set when converting a PCAP file.\n");
369 switch (((
struct pcap_hdr_s*)pin)->magic_number) {
381 printf(
"Input file detected as \"PCAP-nano\".\n");
384 printf(
"Input file detected as \"PCAP\".\n");
387 fprintf(stderr,
"Input format detected is PCAP. Type of PCAP format must be specified.\n");
404 printf(
"Input file detected as \"PCAP-nano\".\n");
407 printf(
"Input file detected as \"PCAP\".\n");
412 fprintf(stderr,
"Input format detected is PCAP. Type of PCAP format must be specified.\n");
425 const struct NtStd0Descr_s *p1 = (
struct NtStd0Descr_s*)pin;
426 const unsigned SIZE_MAX_PKT = 10000U;
427 const unsigned SIZE_2GD_STD_DESC = 16U;
428 const unsigned SIZE_2GD_EXT_HDR = p1->extensionLength * 8U;
429 const unsigned MAX_STORED_LENGTH =
430 SIZE_MAX_PKT + SIZE_2GD_STD_DESC + SIZE_2GD_EXT_HDR;
432 if ((p1->storedLength <= fSize) && (p1->storedLength <= MAX_STORED_LENGTH)) {
433 if (p1->frameSliced) {
434 if (p1->wireLength < p1->storedLength) {
437 }
else if (p1->storedLength < p1->wireLength) {
440 if (p1->storedLength < fSize) {
441 const struct NtStd0Descr_s *p2 = (
struct NtStd0Descr_s*)((uint8_t*)pin+p1->storedLength);
442 if (p2->storedLength <= MAX_STORED_LENGTH) {
443 if (p2->frameSliced) {
444 if (p2->wireLength < p2->storedLength) {
447 }
else if (p2->storedLength < p2->wireLength) {
458 fprintf(stderr,
"Cannot detect input format.\n");
463 printf(
"Input file detected as \"2GD capture\".\n");
477 printf(
"Outputfile type is PCAP\n");
478 fwrite(&pcapGlobalHdr,
sizeof(pcapGlobalHdr), 1, hof);
481 printf(
"Outputfile type is PCAP NANO\n");
482 fwrite(&pcapGlobalHdrNano,
sizeof(pcapGlobalHdr), 1, hof);
485 printf(
"Outputfile type is NT3GD\n");
489 printf(
"Outputfile type is NT3GD NANO\n");
494 fprintf(stderr,
"Unhandled output format.\n");
502 uint32_t storedLength;
503 void *descr = (
void*)(pin+offset);
505 if (((NtDynDescr_t*)descr)->ntDynDescr) {
506 storedLength = ((NtDynDescr_t*)descr)->capLength;
507 }
else if (((NtStd0Descr_t*)descr)->descriptorType) {
508 storedLength = ((NtStd0Descr_t*)descr)->storedLength;
510 if (pcap_swapped == 1) {
512 storedLength = 16 + ntohl(((
struct ntpcap *)descr)->caplen);
514 storedLength = 16 + (((
struct ntpcap *)descr)->caplen);
518 if ((storedLength == 0) || (pcap && (storedLength == 16))){
519 fprintf(stderr,
"File error. StoredLength == 0 detected.\n");
527 (void)fprintf(stderr,
528 "Warning: Packet at offset %lld is too big (>%d kB) " 529 "and will be skipped.\n",
539 if (pcap_swapped == 1) {
541 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->
caplen));
543 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
546 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
550 fwrite(descr, 16+((
struct ntpcap *)descr)->
caplen, 1, hof);
554 const struct NtStd0Descr_s *
const src = descr;
555 struct NtStd0Descr_s *
const dst = pktBuf;
556 memcpy(dst, src, 16U + src->storedLength);
557 if (src->storedLength >= src->wireLength) {
559 dst->wireLength = (uint16_t)(src->wireLength - 4U);
560 dst->storedLength = src->wireLength;
562 fwrite(dst, 16U + dst->storedLength, 1, hof);
569 if (pcap_swapped == 1) {
571 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->caplen));
573 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
576 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
580 memcpy(pktBuf, descr, 16U + ((
struct ntpcap *)descr)->
caplen);
582 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->caplen, 1, hof);
586 memcpy(pktBuf, descr, 16U + ((
struct ntpcap *)descr)->caplen);
588 if (((
struct ntpcap *)pktBuf)->caplen >= ((
struct ntpcap *)pktBuf)->len) {
589 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
590 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
591 fwrite(pktBuf, 16+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
594 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->caplen, 1, hof);
601 if (((NtDynDescr_t*)descr)->ntDynDescr) {
602 NtDynDescr_t *pDyn = (NtDynDescr_t*)descr;
604 ((
struct ntpcap*)pktBuf)->len = pDyn->capLength - pDyn->descrLength - 4;
605 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
611 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn1->
timestamp/100000000);
612 ((
struct ntpcap*)pktBuf)->tv.tv_usec = ((uint32_t)(pDyn1->
timestamp%100000000)/100);
614 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn1->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
616 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
624 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn2->
timestamp/100000000);
625 ((
struct ntpcap*)pktBuf)->tv.tv_usec = ((uint32_t)(pDyn2->
timestamp%100000000)/100);
627 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn2->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
629 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
637 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn3->
timestamp/100000000);
638 ((
struct ntpcap*)pktBuf)->tv.tv_usec = ((uint32_t)(pDyn3->
timestamp%100000000)/100);
640 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn3->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
642 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
650 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn4->
timestamp/100000000);
651 ((
struct ntpcap*)pktBuf)->tv.tv_usec = ((uint32_t)(pDyn4->
timestamp%100000000)/100);
653 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn4->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
655 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
661 ((
struct ntpcap*)pktBuf)->len = ((
struct NtStd0Descr_s *)descr)->wireLength-4;
662 ((
struct ntpcap*)pktBuf)->caplen = (((
struct NtStd0Descr_s *)descr)->storedLength-(((
struct NtStd0Descr_s *)descr)->extensionLength<<3)-16);
664 if (((
struct ntpcap*)pktBuf)->caplen > ((
struct ntpcap*)pktBuf)->len) {
665 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
668 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((
struct NtStd0Descr_s *)descr)->timestamp/100000000);
669 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((((
struct NtStd0Descr_s *)descr)->timestamp%100000000)/100);
671 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+(((
struct NtStd0Descr_s *)descr)->extensionLength<<3)+16, ((
struct ntpcap*)pktBuf)->
caplen);
673 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
678 fprintf(stderr,
"Unhandled input format.\n");
690 if (pcap_swapped == 1) {
692 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->
caplen));
694 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
697 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
701 memcpy(pktBuf, descr, 16+((NtStd0Descr_t *)descr)->storedLength);
703 fwrite(pktBuf, 16+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
707 if (((NtStd0Descr_t *)descr)->storedLength >= ((NtStd0Descr_t *)descr)->wireLength) {
708 memcpy(pktBuf, descr, 16+((NtStd0Descr_t *)descr)->storedLength);
709 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
710 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
712 fwrite(pktBuf, 16+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
715 memcpy(pktBuf, descr, 16+((NtStd0Descr_t *)descr)->storedLength);
717 fwrite(pktBuf, 16+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
724 if (pcap_swapped == 1) {
726 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->caplen));
728 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
731 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
735 fwrite(descr, 16+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
739 if (((NtStd0Descr_t *)descr)->storedLength >= ((NtStd0Descr_t *)descr)->wireLength) {
740 memcpy(pktBuf, descr, 16+((NtStd0Descr_t *)descr)->storedLength);
741 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
742 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
743 fwrite(pktBuf, 16+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
746 fwrite(descr, 16+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
754 if (((NtDynDescr_t*)descr)->ntDynDescr) {
755 NtDynDescr_t *pDyn = (NtDynDescr_t*)descr;
757 ((
struct ntpcap*)pktBuf)->len = pDyn->capLength - pDyn->descrLength - 4;
758 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
765 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn1->
timestamp/100000000);
766 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn1->
timestamp%100000000)*10);
768 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn1->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
770 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
778 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn2->
timestamp/100000000);
779 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn2->
timestamp%100000000)*10);
781 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn2->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
783 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
791 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn3->
timestamp/100000000);
792 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn3->
timestamp%100000000)*10);
794 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn3->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
796 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
804 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn4->
timestamp/100000000);
805 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn4->
timestamp%100000000)*10);
807 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn4->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
809 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
815 ((
struct ntpcap*)pktBuf)->len = ((NtStd0Descr_t *)descr)->wireLength-4;
816 ((
struct ntpcap*)pktBuf)->caplen = (((NtStd0Descr_t *)descr)->storedLength-(((NtStd0Descr_t *)descr)->extensionLength<<3)-16);
819 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
823 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp/1000000000);
824 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp%1000000000);
826 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp/100000000);
827 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((((NtStd0Descr_t *)descr)->timestamp%100000000)*10);
830 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+(((NtStd0Descr_t *)descr)->extensionLength<<3)+16, ((
struct ntpcap*)pktBuf)->
caplen);
832 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
837 fprintf(stderr,
"Unhandled input format.\n");
850 *((uint64_t*)pktBuf+0)=0;
851 *((uint64_t*)pktBuf+1)=0;
853 if (pcap_swapped == 1) {
856 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = (((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_sec))*1000000000)+(uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_usec);
858 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_sec))*100000000)+(((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_usec))/10));
862 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = (((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_sec))*1000000000)+(uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_usec)*1000;
864 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_sec))*100000000)+(((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_usec))*100));
870 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = (((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*1000000000)+
871 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec));
873 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*100000000)+
874 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)/10));
878 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*1000000000)+
879 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)*1000));
881 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*100000000)+
882 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)*100));
886 ((
struct NtStd0Descr_s *)pktBuf)->descriptorType=1;
892 if (pcap_swapped == 1) {
893 caplen = ntohl(((
struct ntpcap*)descr)->caplen);
894 len = ntohl(((
struct ntpcap*)descr)->len);
897 caplen = ((
struct ntpcap*)descr)->caplen;
898 len = ((
struct ntpcap*)descr)->len;
903 ((
struct NtStd0Descr_s *)pktBuf)->frameSliced=1;
904 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((caplen+16+7)&~7);
905 }
else if (len < caplen) {
906 fprintf(stderr,
"Error in Packet at offset %lld. Stored length %d must not be larger than the wire length %d.\n", (
unsigned long long)offset,
909 fprintf(stderr,
"This could be a Napatech capture file with PCAP headers.\n");
910 (void)fprintf(stderr,
"Try to run the tool again with --inputformat=ntpcap.\n");
916 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((caplen+16+4+7)&~7);
920 ((
struct NtStd0Descr_s *)pktBuf)->hardSlice=1;
921 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=((10000+
sizeof(
struct NtStd0Descr_s)+7)&~7);
923 ((
struct NtStd0Descr_s *)pktBuf)->wireLength=(uint16_t)(len+4);
924 ((
struct NtStd0Descr_s *)pktBuf)->txCrcOverride=1;
927 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+16, caplen);
930 if (((
struct ntpcap*)descr)->len > ((
struct ntpcap*)descr)->caplen) {
932 ((
struct NtStd0Descr_s *)pktBuf)->frameSliced=1;
933 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)(((
struct ntpcap*)descr)->caplen+16);
936 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((((
struct ntpcap*)descr)->len+16+7)&~7);
938 if (((
struct ntpcap*)descr)->len > 10000) {
940 ((
struct NtStd0Descr_s *)pktBuf)->hardSlice=1;
941 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=((10000+
sizeof(
struct NtStd0Descr_s)+7)&~7);
943 ((
struct NtStd0Descr_s *)pktBuf)->wireLength=(uint16_t)(((
struct ntpcap*)descr)->len);
944 ((
struct NtStd0Descr_s *)pktBuf)->txCrcOverride=1;
947 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+16, ((
struct ntpcap*)descr)->caplen);
949 fwrite(pktBuf, ((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
954 if (((NtDynDescr_t*)descr)->ntDynDescr) {
955 fwrite(descr, ((NtDynDescr_t *)descr)->capLength, 1, hof);
957 fwrite(descr, ((NtStd0Descr_t *)descr)->storedLength, 1, hof);
961 fprintf(stderr,
"Unhandled input format.\n");
968 fprintf(stderr,
"Unhandled output format.\n");
975 offset += storedLength;
980 printf(
"File size: 0x%lX (%ld) offset: 0x%lX (%ld)\n", dSize, dSize, offset, offset);
984 (void)printf(
"Conversion done. Converted %llu packets.\n",
pktNum);
986 (
void)printf(
"Conversion done. Converted %llu and skipped %llu packets.\n",
1011 int main(
int argc,
const char *argv[])
1047 fprintf(stderr,
"No output format provided.\n");
1051 fprintf(stderr,
"No input file provided.\n");
1056 fprintf(stderr,
"No output file provided.\n");
1060 struct sigaction newaction;
1061 memset(&newaction, 0,
sizeof(newaction));
1063 if (sigaction(SIGINT, &newaction, NULL) < 0) {
1064 fprintf(stderr,
"Failed to register SIGINT sigaction.\n");
1069 if ((ApplExitCode =
_Convert()) != 0) {
1070 fprintf(stderr,
">>> Error: Convert failed.\n");
1075 return ApplExitCode;