61 #include <sys/types.h> 65 #include <netinet/in.h> 67 #if defined(__linux__) || defined(__FreeBSD__) 68 #include <stdatomic.h> 75 #if defined(WIN32) || defined (WIN64) 77 #define lseek _lseeki64 83 #define PKTBUF_SIZE (16*1024) 84 #define CAPFILE_MAX_SIZE ((size_t)-1) 133 OPT_STRING(
'f',
"outputformat", &
opt_output_format,
"Specifies the output format: <pcap | pcapnano | nt3gd | nt3gdnano>", NULL, 0, 0,
"format"),
134 OPT_STRING(
'n',
"inputformat", &
opt_input_format,
"Specifies the input format when converting a pcap file: <libpcap | ntpcap>", NULL, 0, 0,
"format"),
138 #define NT_2GD_SEGMENT_DUMP_MAGIC 0xFEDEABBA 153 NT_STID_FILE_HEADER0,
155 NT_FILE_HEADER0_COOKIE,
158 {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,
159 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,},
160 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
161 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
166 NT_STID_FILE_HEADER0,
168 NT_FILE_HEADER0_COOKIE,
171 {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,
172 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,},
173 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
174 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
177 #define PCAP_MAGIC 0xa1b2c3d4 178 #define PCAP_SWAPPED_MAGIC 0xd4c3b2a1 179 #define PCAP_MODIFIED_MAGIC 0xa1b2cd34 180 #define PCAP_SWAPPED_MODIFIED_MAGIC 0x34cdb2a1 181 #define PCAP_NSEC_MAGIC 0xa1b23c4d 182 #define PCAP_SWAPPED_NSEC_MAGIC 0x4d3cb2a1 184 #define SWAPLONG(y) \ 185 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) 186 #define SWAPSHORT(y) \ 187 ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) ) 242 for (
int i = 0; i < 78; ++i) {
256 #if defined(WIN32) || defined (WIN64) 276 size_t fSize = 0, dSize = 0;
282 int pcap_swapped = 0;
287 perror(
"Failed to allocate packet buffer of 16k\n");
294 perror(
"Failed to create output file.");
300 #if defined(WIN32) || defined (WIN64) 301 if ((fdin = open(
opt_input_file, _O_RDONLY | _O_BINARY, _S_IREAD)) == -1) {
307 perror(
"Failed to open input file.");
319 (void)lseek(fdin, 0, SEEK_SET);
320 tmp_fSize = lseek(fdin, 0, SEEK_END);
322 fprintf(stderr,
"The cap file is too big.\n");
327 fSize = (size_t)tmp_fSize;
328 lseek(fdin, 0, SEEK_SET);
330 fprintf(stderr,
"Input file too small.\n");
336 if ((pin = (uint8_t*)mmap(NULL, fSize, PROT_READ, MAP_PRIVATE, fdin, 0)) == MAP_FAILED) {
337 perror(
"Failed to mmap input file.\n");
347 if ((((NtFileHeader0_t*)pin)->cookie == NT_FILE_HEADER0_COOKIE) &&
348 (((NtFileHeader0_t*)pin)->structid == NT_STID_FILE_HEADER0)) {
349 printf(
"Input file detected as 3GD capture file.\n");
350 offset=
sizeof(NtFileHeader0_t);
353 printf(
"Input file detected as 3GD capture file with UNIX_NANO timestamp.\n");
357 printf(
"Input file detected as 3GD capture file.\n");
362 fprintf(stderr,
"Input format must only be set when converting a PCAP file.\n");
371 printf(
"Input file detected as \"2GD segment dump\".\n");
376 fprintf(stderr,
"Input format must only be set when converting a PCAP file.\n");
383 switch (((
struct pcap_hdr_s*)pin)->magic_number) {
395 printf(
"Input file detected as \"PCAP-nano\".\n");
398 printf(
"Input file detected as \"PCAP\".\n");
401 fprintf(stderr,
"Input format detected is PCAP. Type of PCAP format must be specified.\n");
418 printf(
"Input file detected as \"PCAP-nano\".\n");
421 printf(
"Input file detected as \"PCAP\".\n");
426 fprintf(stderr,
"Input format detected is PCAP. Type of PCAP format must be specified.\n");
439 const struct NtStd0Descr_s *p1 = (
struct NtStd0Descr_s*)pin;
440 const unsigned SIZE_MAX_PKT = 10000U;
441 const unsigned SIZE_2GD_STD_DESC = 16U;
442 const unsigned SIZE_2GD_EXT_HDR = p1->extensionLength * 8U;
443 const unsigned MAX_STORED_LENGTH =
444 SIZE_MAX_PKT + SIZE_2GD_STD_DESC + SIZE_2GD_EXT_HDR;
446 if ((p1->storedLength <= fSize) && (p1->storedLength <= MAX_STORED_LENGTH)) {
447 if (p1->frameSliced) {
448 if (p1->wireLength < p1->storedLength) {
451 }
else if (p1->storedLength < p1->wireLength) {
454 if (p1->storedLength < fSize) {
455 const struct NtStd0Descr_s *p2 = (
struct NtStd0Descr_s*)((uint8_t*)pin+p1->storedLength);
456 if (p2->storedLength <= MAX_STORED_LENGTH) {
457 if (p2->frameSliced) {
458 if (p2->wireLength < p2->storedLength) {
461 }
else if (p2->storedLength < p2->wireLength) {
472 fprintf(stderr,
"Cannot detect input format.\n");
477 printf(
"Input file detected as \"2GD capture\".\n");
491 printf(
"Outputfile type is PCAP\n");
492 fwrite(&pcapGlobalHdr,
sizeof(pcapGlobalHdr), 1, hof);
495 printf(
"Outputfile type is PCAP NANO\n");
496 fwrite(&pcapGlobalHdrNano,
sizeof(pcapGlobalHdr), 1, hof);
499 printf(
"Outputfile type is NT3GD\n");
503 printf(
"Outputfile type is NT3GD NANO\n");
508 fprintf(stderr,
"Unhandled output format.\n");
516 uint32_t storedLength;
517 void *descr = (
void*)(pin+offset);
519 if (((NtDynDescr_t*)descr)->ntDynDescr) {
520 storedLength = ((NtDynDescr_t*)descr)->capLength;
521 }
else if (((NtStd0Descr_t*)descr)->descriptorType) {
522 storedLength = ((NtStd0Descr_t*)descr)->storedLength;
524 if (pcap_swapped == 1) {
526 storedLength = 16 + ntohl(((
struct ntpcap *)descr)->caplen);
528 storedLength = 16 + (((
struct ntpcap *)descr)->caplen);
532 if ((storedLength == 0) || (pcap && (storedLength == 16))){
533 fprintf(stderr,
"File error. StoredLength == 0 detected.\n");
541 (void)fprintf(stderr,
542 "Warning: Packet at offset %lld is too big (>%d kB) " 543 "and will be skipped.\n",
553 if (pcap_swapped == 1) {
555 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->
caplen));
557 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
560 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
564 fwrite(descr, 16+((
struct ntpcap *)descr)->
caplen, 1, hof);
568 const struct NtStd0Descr_s *
const src = descr;
569 struct NtStd0Descr_s *
const dst = pktBuf;
570 memcpy(dst, src, 16U + src->storedLength);
571 if (src->storedLength >= src->wireLength) {
573 dst->wireLength = (uint16_t)(src->wireLength - 4U);
574 dst->storedLength = src->wireLength;
576 fwrite(dst, 16U + dst->storedLength, 1, hof);
583 if (pcap_swapped == 1) {
585 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->caplen));
587 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
590 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
594 memcpy(pktBuf, descr, 16U + ((
struct ntpcap *)descr)->
caplen);
596 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->caplen, 1, hof);
600 memcpy(pktBuf, descr, 16U + ((
struct ntpcap *)descr)->caplen);
602 if (((
struct ntpcap *)pktBuf)->caplen >= ((
struct ntpcap *)pktBuf)->len) {
603 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
604 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
605 fwrite(pktBuf, 16U+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
608 fwrite(pktBuf, 16U+((
struct ntpcap *)pktBuf)->caplen, 1, hof);
615 if (((NtDynDescr_t*)descr)->ntDynDescr) {
616 NtDynDescr_t *pDyn = (NtDynDescr_t*)descr;
618 ((
struct ntpcap*)pktBuf)->len = (uint32_t)(pDyn->capLength - pDyn->descrLength - 4);
619 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
625 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn1->
timestamp/100000000U);
626 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn1->
timestamp%100000000U)/100U);
628 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn1->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
630 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
638 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn2->
timestamp/100000000U);
639 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn2->
timestamp%100000000U)/100U);
641 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn2->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
643 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
651 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn3->
timestamp/100000000U);
652 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn3->
timestamp%100000000U)/100U);
654 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn3->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
656 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
664 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn4->
timestamp/100000000U);
665 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn4->
timestamp%100000000U)/100U);
667 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn4->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
669 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
675 ((
struct ntpcap*)pktBuf)->len = ((
struct NtStd0Descr_s *)descr)->wireLength-4U;
676 ((
struct ntpcap*)pktBuf)->caplen = (((
struct NtStd0Descr_s *)descr)->storedLength + 16U - (((
struct NtStd0Descr_s *)descr)->extensionLength * 8U));
678 if (((
struct ntpcap*)pktBuf)->caplen > ((
struct ntpcap*)pktBuf)->len) {
679 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
682 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((
struct NtStd0Descr_s *)descr)->timestamp/100000000U);
683 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((((
struct NtStd0Descr_s *)descr)->timestamp%100000000U)/100U);
685 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+(((
struct NtStd0Descr_s *)descr)->extensionLength<<3)+16, ((
struct ntpcap*)pktBuf)->
caplen);
687 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
692 fprintf(stderr,
"Unhandled input format.\n");
704 if (pcap_swapped == 1) {
706 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->
caplen));
708 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
711 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
715 memcpy(pktBuf, descr, 16U+((NtStd0Descr_t *)descr)->storedLength);
717 fwrite(pktBuf, 16U+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
721 if (((NtStd0Descr_t *)descr)->storedLength >= ((NtStd0Descr_t *)descr)->wireLength) {
722 memcpy(pktBuf, descr, 16U+((NtStd0Descr_t *)descr)->storedLength);
723 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
724 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
726 fwrite(pktBuf, 16U+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
729 memcpy(pktBuf, descr, 16U+((NtStd0Descr_t *)descr)->storedLength);
731 fwrite(pktBuf, 16U+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
738 if (pcap_swapped == 1) {
740 memcpy(pktBuf, descr, 16+ntohl(((
struct ntpcap *)descr)->caplen));
742 ((
struct ntpcap *)pktBuf)->len = ntohl(((
struct ntpcap *)pktBuf)->
len);
745 fwrite(pktBuf, 16+((
struct ntpcap *)pktBuf)->
caplen, 1, hof);
749 fwrite(descr, 16U+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
753 if (((NtStd0Descr_t *)descr)->storedLength >= ((NtStd0Descr_t *)descr)->wireLength) {
754 memcpy(pktBuf, descr, 16U+((NtStd0Descr_t *)descr)->storedLength);
755 ((
struct NtStd0Descr_s *)pktBuf)->wireLength = (
unsigned short)(((
struct NtStd0Descr_s *)pktBuf)->wireLength - 4);
756 ((
struct NtStd0Descr_s *)pktBuf)->storedLength = ((
struct NtStd0Descr_s *)pktBuf)->wireLength;
757 fwrite(pktBuf, 16U+((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
760 fwrite(descr, 16U+((NtStd0Descr_t *)descr)->storedLength, 1, hof);
768 if (((NtDynDescr_t*)descr)->ntDynDescr) {
769 NtDynDescr_t *pDyn = (NtDynDescr_t*)descr;
771 ((
struct ntpcap*)pktBuf)->len = (uint32_t)(pDyn->capLength - pDyn->descrLength - 4);
772 ((
struct ntpcap*)pktBuf)->caplen = (uint32_t)((
struct ntpcap*)pktBuf)->
len;
779 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)((pDyn1->
timestamp/100000000U));
780 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn1->
timestamp%100000000U)*10U);
782 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn1->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
784 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
792 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn2->
timestamp/100000000U);
793 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn2->
timestamp%100000000U)*10U);
795 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn2->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
797 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
805 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn3->
timestamp/100000000U);
806 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn3->
timestamp%100000000U)*10U);
808 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn3->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
810 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
818 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(pDyn4->
timestamp/100000000U);
819 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((pDyn4->
timestamp%100000000U)*10U);
821 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+pDyn4->
descrLength, ((
struct ntpcap*)pktBuf)->caplen);
823 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
829 ((
struct ntpcap*)pktBuf)->len = ((NtStd0Descr_t *)descr)->wireLength-(uint32_t)4;
830 ((
struct ntpcap*)pktBuf)->caplen = (uint32_t)(((NtStd0Descr_t *)descr)->storedLength-(((NtStd0Descr_t *)descr)->extensionLength<<3)-16);
833 ((
struct ntpcap*)pktBuf)->caplen = ((
struct ntpcap*)pktBuf)->len;
837 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp/1000000000U);
838 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp%1000000000U);
840 ((
struct ntpcap*)pktBuf)->tv.tv_sec = (uint32_t)(((NtStd0Descr_t *)descr)->timestamp/100000000U);
841 ((
struct ntpcap*)pktBuf)->tv.tv_usec = (uint32_t)((((NtStd0Descr_t *)descr)->timestamp%100000000U)*10U);
844 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+(((NtStd0Descr_t *)descr)->extensionLength<<3)+16, ((
struct ntpcap*)pktBuf)->
caplen);
846 fwrite(pktBuf, 16+((
struct ntpcap*)pktBuf)->
caplen, 1, hof);
851 fprintf(stderr,
"Unhandled input format.\n");
864 *((uint64_t*)pktBuf+0)=0;
865 *((uint64_t*)pktBuf+1)=0;
867 if (pcap_swapped == 1) {
870 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = (((uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_sec))*1000000000)+(uint64_t)ntohl(((
struct ntpcap*)descr)->tv.tv_usec);
872 ((
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));
876 ((
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;
878 ((
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));
884 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = (((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*1000000000)+
885 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec));
887 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*100000000)+
888 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)/10));
892 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*1000000000)+
893 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)*1000));
895 ((
struct NtStd0Descr_s *)pktBuf)->timestamp = ((((uint64_t)((
struct ntpcap*)descr)->tv.tv_sec)*100000000)+
896 (((uint64_t)((
struct ntpcap*)descr)->tv.tv_usec)*100));
900 ((
struct NtStd0Descr_s *)pktBuf)->descriptorType=1;
906 if (pcap_swapped == 1) {
907 caplen = ntohl(((
struct ntpcap*)descr)->caplen);
908 len = ntohl(((
struct ntpcap*)descr)->len);
911 caplen = ((
struct ntpcap*)descr)->caplen;
912 len = ((
struct ntpcap*)descr)->len;
917 ((
struct NtStd0Descr_s *)pktBuf)->frameSliced=1;
918 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((caplen+16U+7U)&~7U);
919 }
else if (len < caplen) {
920 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,
923 fprintf(stderr,
"This could be a Napatech capture file with PCAP headers.\n");
924 (void)fprintf(stderr,
"Try to run the tool again with --inputformat=ntpcap.\n");
930 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((caplen+16U+4U+7U)&~7U);
934 ((
struct NtStd0Descr_s *)pktBuf)->hardSlice=1;
935 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=((10000U+
sizeof(
struct NtStd0Descr_s)+7U)&~7U);
937 ((
struct NtStd0Descr_s *)pktBuf)->wireLength=(uint16_t)(len+4);
938 ((
struct NtStd0Descr_s *)pktBuf)->txCrcOverride=1;
941 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+16, caplen);
944 if (((
struct ntpcap*)descr)->len > ((
struct ntpcap*)descr)->caplen) {
946 ((
struct NtStd0Descr_s *)pktBuf)->frameSliced=1;
947 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)(((
struct ntpcap*)descr)->caplen+16U);
950 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((((
struct ntpcap*)descr)->len+16U+7U)&~7U);
952 if (((
struct ntpcap*)descr)->len > 10000) {
954 ((
struct NtStd0Descr_s *)pktBuf)->hardSlice=1;
955 ((
struct NtStd0Descr_s *)pktBuf)->storedLength=(uint16_t)((10000U+
sizeof(
struct NtStd0Descr_s)+7U)&~7U);
957 ((
struct NtStd0Descr_s *)pktBuf)->wireLength=(uint16_t)(((
struct ntpcap*)descr)->len);
958 ((
struct NtStd0Descr_s *)pktBuf)->txCrcOverride=1;
961 memcpy((uint8_t*)pktBuf+16, (uint8_t*)descr+16, ((
struct ntpcap*)descr)->caplen);
963 fwrite(pktBuf, ((
struct NtStd0Descr_s *)pktBuf)->storedLength, 1, hof);
968 if (((NtDynDescr_t*)descr)->ntDynDescr) {
969 fwrite(descr, ((NtDynDescr_t *)descr)->capLength, 1, hof);
971 fwrite(descr, ((NtStd0Descr_t *)descr)->storedLength, 1, hof);
975 fprintf(stderr,
"Unhandled input format.\n");
982 fprintf(stderr,
"Unhandled output format.\n");
989 offset += storedLength;
994 printf(
"File size: 0x%lX (%ld) offset: 0x%lX (%ld)\n", dSize, dSize, offset, offset);
998 (void)printf(
"Conversion done. Converted %llu packets.\n",
pktNum);
1000 (
void)printf(
"Conversion done. Converted %llu and skipped %llu packets.\n",
1025 int main(
int argc,
const char *argv[])
1061 fprintf(stderr,
"No output format provided.\n");
1065 fprintf(stderr,
"No input file provided.\n");
1070 fprintf(stderr,
"No output file provided.\n");
1075 #if defined(WIN32) || defined (WIN64) 1078 struct sigaction newaction;
1079 memset(&newaction, 0,
sizeof(newaction));
1081 if (sigaction(SIGINT, &newaction, NULL) < 0) {
1082 fprintf(stderr,
"Failed to register SIGINT sigaction.\n");
1087 if ((ApplExitCode =
_Convert()) != 0) {
1088 fprintf(stderr,
">>> Error: Convert failed.\n");
1093 return ApplExitCode;