Changeset 4e5a51f
- Timestamp:
- 02/07/19 14:07:07 (2 years ago)
- Branches:
- develop
- Children:
- 5cdb37d
- Parents:
- 58c226e
- git-author:
- Jacob Van Walraven <jcv9@…> (02/07/19 14:00:51)
- git-committer:
- Jacob Van Walraven <jcv9@…> (02/07/19 14:07:07)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/dagformat.h
ref5ba20 r4e5a51f 107 107 uint16_t type; 108 108 uint16_t len; 109 } dag_sec_t;109 } PACKED dag_sec_t; 110 110 111 111 struct dag_opthdr { 112 112 uint16_t optcode; 113 113 uint16_t optlen; 114 } ;114 } PACKED; 115 115 116 116 #ifdef WIN32 -
lib/format_erf.c
r6f6fcbb r4e5a51f 1075 1075 } 1076 1076 1077 /* An ERF provenance packet can contain multiple sections of the same type per packet, 1078 * Need to think of a way to handle this currently the first found is returned*/ 1077 /* An ERF provenance packet can contain multiple sections of the same type per packet */ 1079 1078 void *erf_get_meta_section(libtrace_packet_t *packet, uint32_t section) { 1080 1079 … … 1096 1095 1097 1096 /* ensure this packet is a meta packet */ 1098 if ((hdr->type & 127) != 27) { return NULL; }1097 if ((hdr->type & 127) != ERF_META_TYPE) { return NULL; } 1099 1098 /* set remaining to size of packet minus header length */ 1100 1099 remaining = ntohs(hdr->rlen) - 24; -
lib/format_pcapng.c
r0cc91ee r4e5a51f 471 471 } 472 472 473 static void pcapng_create_output_sectionheader_packet(libtrace_out_t *libtrace) { 474 /* Create section block */ 475 pcapng_sec_t sechdr; 476 sechdr.blocktype = pcapng_swap32(libtrace, PCAPNG_SECTION_TYPE); 477 sechdr.blocklen = pcapng_swap32(libtrace, 28); 478 sechdr.ordering = pcapng_swap32(libtrace, 0x1A2B3C4D); 479 sechdr.majorversion = pcapng_swap16(libtrace, 1); 480 sechdr.minorversion = 0; 481 sechdr.sectionlen = 0xFFFFFFFFFFFFFFFF; 482 483 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr, sizeof(sechdr)); 484 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr.blocklen, sizeof(sechdr.blocklen)); 485 486 DATAOUT(libtrace)->sechdr_count += 1; 487 } 488 489 static void pcapng_create_output_interface_packet(libtrace_out_t *libtrace, libtrace_linktype_t linktype) { 490 /* Create interface block*/ 491 pcapng_int_t inthdr; 492 inthdr.blocktype = pcapng_swap32(libtrace, PCAPNG_INTERFACE_TYPE); 493 inthdr.blocklen = pcapng_swap32(libtrace, 20); 494 inthdr.linktype = pcapng_swap16(libtrace, libtrace_to_pcap_dlt(linktype)); 495 inthdr.reserved = 0; 496 inthdr.snaplen = 0; 497 498 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr, sizeof(inthdr)); 499 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr.blocklen, sizeof(inthdr.blocklen)); 500 501 /* increment the interface counter */ 502 DATAOUT(libtrace)->nextintid += 1; 503 /* update the last linktype */ 504 DATAOUT(libtrace)->lastdlt = linktype; 505 } 506 473 507 static int pcapng_probe_magic(io_t *io) { 474 508 … … 829 863 } 830 864 case PCAPNG_SIMPLE_PACKET_TYPE: { 865 /* If no section header or interface packets have been received create and 866 * output them. This can occur when discard meta is enabled and the input 867 * format is also pcapng */ 868 if (DATAOUT(libtrace)->sechdr_count == 0) { 869 pcapng_create_output_sectionheader_packet(libtrace); 870 } 831 871 if (DATAOUT(libtrace)->nextintid == 0) { 832 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 833 "Cannot output simple packet before a interface " 834 "block has been output in pcapng_write_packet()\n"); 835 return -1; 872 pcapng_create_output_interface_packet(libtrace, linktype); 836 873 } 837 874 return pcapng_output_simple_packet(libtrace, packet); … … 841 878 } 842 879 case PCAPNG_INTERFACE_STATS_TYPE: { 843 if (DATAOUT(libtrace)->nextintid == 0) { 844 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 845 "Cannot output a interface statistics block before a " 846 "interface block has been output in pcapng_write_packet()\n"); 847 return -1; 848 } 880 /* If no section header or interface packets have been received create and 881 * output them. This can occur when discard meta is enabled and the input 882 * format is also pcapng */ 883 if (DATAOUT(libtrace)->sechdr_count == 0) { 884 pcapng_create_output_sectionheader_packet(libtrace); 885 } 886 if (DATAOUT(libtrace)->nextintid == 0) { 887 pcapng_create_output_interface_packet(libtrace, linktype); 888 } 849 889 return pcapng_output_interfacestats_packet(libtrace, packet); 850 890 } 851 891 case PCAPNG_ENHANCED_PACKET_TYPE: { 852 if (DATAOUT(libtrace)->nextintid == 0) { 853 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 854 "Cannot output enhanced packet before a interface " 855 "block has been output in pcapng_write_packet()\n"); 856 return -1; 857 } 892 /* If no section header or interface packets have been received create and 893 * output them. This can occur when discard meta is enabled and the input 894 * format is also pcapng */ 895 if (DATAOUT(libtrace)->sechdr_count == 0) { 896 pcapng_create_output_sectionheader_packet(libtrace); 897 } 898 if (DATAOUT(libtrace)->nextintid == 0) { 899 pcapng_create_output_interface_packet(libtrace, linktype); 900 } 858 901 return pcapng_output_enhanced_packet(libtrace, packet); 859 902 } … … 870 913 default: { 871 914 872 /* create section header if not already*/915 /* create and output section header if none have occured yet */ 873 916 if (DATAOUT(libtrace)->sechdr_count == 0) { 874 /* Create section block */ 875 pcapng_sec_t sechdr; 876 sechdr.blocktype = pcapng_swap32(libtrace, PCAPNG_SECTION_TYPE); 877 sechdr.blocklen = pcapng_swap32(libtrace, 28); 878 sechdr.ordering = pcapng_swap32(libtrace, 0x1A2B3C4D); 879 sechdr.majorversion = pcapng_swap16(libtrace, 1); 880 sechdr.minorversion = 0; 881 sechdr.sectionlen = 0xFFFFFFFFFFFFFFFF; 882 883 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr, sizeof(sechdr)); 884 wandio_wwrite(DATAOUT(libtrace)->file, &sechdr.blocklen, sizeof(sechdr.blocklen)); 885 886 DATAOUT(libtrace)->sechdr_count += 1; 917 pcapng_create_output_sectionheader_packet(libtrace); 887 918 } 888 919 889 /* create interface header if not already or if the linktype has changed */ 920 /* create and output interface header if not already or if the 921 * linktype has changed */ 890 922 if (DATAOUT(libtrace)->nextintid == 0 891 923 || DATAOUT(libtrace)->lastdlt != linktype) { 892 /* Create interface block*/ 893 pcapng_int_t inthdr; 894 inthdr.blocktype = pcapng_swap32(libtrace, PCAPNG_INTERFACE_TYPE); 895 inthdr.blocklen = pcapng_swap32(libtrace, 20); 896 inthdr.linktype = pcapng_swap16(libtrace, libtrace_to_pcap_dlt(linktype)); 897 inthdr.reserved = 0; 898 inthdr.snaplen = 0; 899 900 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr, sizeof(inthdr)); 901 wandio_wwrite(DATAOUT(libtrace)->file, &inthdr.blocklen, sizeof(inthdr.blocklen)); 902 903 /* increment the interface counter */ 904 DATAOUT(libtrace)->nextintid += 1; 905 /* update the last linktype */ 906 DATAOUT(libtrace)->lastdlt = linktype; 924 925 pcapng_create_output_interface_packet(libtrace, linktype); 907 926 } 908 927 … … 1581 1600 /* Section Header */ 1582 1601 case PCAPNG_SECTION_TYPE: 1583 /* Section header is required to make pcapng valid 1584 * so we cannot exclude when option discard_meta is set */ 1602 /* Section header packets are required for PCAPNG so even if discard_meta 1603 * option is set it still needs to be processed. Not setting gotpacket will 1604 * prevent triggering the meta callback */ 1585 1605 err = pcapng_read_section(libtrace, packet, flags); 1586 gotpacket = 1; 1606 if (!DATA(libtrace)->discard_meta) { 1607 gotpacket = 1; 1608 } 1587 1609 1588 1610 break; … … 1590 1612 /* Interface Header */ 1591 1613 case PCAPNG_INTERFACE_TYPE: 1592 /* Section interface is required to make pcapng valid 1593 * so we cannot exclude when option discard_meta is set */ 1614 /* Same applies here for Interface packets */ 1594 1615 err = pcapng_read_interface(libtrace, packet, to_read, flags); 1595 gotpacket = 1; 1616 if (!DATA(libtrace)->discard_meta) { 1617 gotpacket = 1; 1618 } 1596 1619 break; 1597 1620 -
lib/format_pcapng.h
r0cc91ee r4e5a51f 109 109 uint16_t minorversion; 110 110 uint64_t sectionlen; 111 } pcapng_sec_t;111 } PACKED pcapng_sec_t; 112 112 113 113 typedef struct pcapng_interface_header_t { … … 117 117 uint16_t reserved; 118 118 uint32_t snaplen; 119 } pcapng_int_t;119 } PACKED pcapng_int_t; 120 120 121 121 typedef struct pcapng_nrb_header_t { 122 122 uint32_t blocktype; 123 123 uint32_t blocklen; 124 } pcapng_nrb_t;124 } PACKED pcapng_nrb_t; 125 125 126 126 typedef struct pcapng_enhanced_packet_t { … … 132 132 uint32_t caplen; 133 133 uint32_t wlen; 134 } pcapng_epkt_t;134 } PACKED pcapng_epkt_t; 135 135 136 136 typedef struct pcapng_simple_packet_t { … … 138 138 uint32_t blocklen; 139 139 uint32_t wlen; 140 } pcapng_spkt_t;140 } PACKED pcapng_spkt_t; 141 141 142 142 typedef struct pcapng_old_packet_t { … … 149 149 uint32_t caplen; 150 150 uint32_t wlen; 151 } pcapng_opkt_t;151 } PACKED pcapng_opkt_t; 152 152 153 153 typedef struct pcapng_stats_header_t { … … 157 157 uint32_t timestamp_high; 158 158 uint32_t timestamp_low; 159 } pcapng_stats_t;159 } PACKED pcapng_stats_t; 160 160 161 161 typedef struct pcapng_decryption_secrets_header_t { … … 164 164 uint32_t secrets_type; 165 165 uint32_t secrets_len; 166 } pcapng_secrets_t;166 } PACKED pcapng_secrets_t; 167 167 168 168 typedef struct pcapng_custom_header_t { … … 170 170 uint32_t blocklen; 171 171 uint32_t pen; 172 } pcapng_custom_t;172 } PACKED pcapng_custom_t; 173 173 174 174 typedef struct pcapng_interface_t pcapng_interface_t; … … 228 228 uint16_t optcode; 229 229 uint16_t optlen; 230 } ;230 } PACKED; 231 231 232 232 struct pcapng_custom_optheader { … … 234 234 uint16_t optlen; 235 235 uint32_t pen; 236 } ;236 } PACKED; 237 237 struct pcapng_nrb_record { 238 238 uint16_t recordtype; 239 239 uint16_t recordlen; 240 } ;240 } PACKED; 241 241 struct pcapng_peeker { 242 242 uint32_t blocktype; 243 243 uint32_t blocklen; 244 } ;244 } PACKED; 245 245 246 246 typedef struct pcapng_peeker pcapng_hdr_t; -
libpacketdump/link_21.c
r4c88365 r4e5a51f 5 5 6 6 #include <arpa/inet.h> 7 #include <inttypes.h> 7 8 8 9 DLLEXPORT void decode(int link_type UNUSED, const char *packet UNUSED, unsigned len UNUSED) { … … 18 19 (char *)meta->items[i].data); 19 20 } else if (meta->items[i].datatype == TRACE_META_UINT8) { 20 printf(" %s: % u\n",21 printf(" %s: %" PRIu8 "\n", 21 22 meta->items[i].option_name, 22 23 *(uint8_t *)meta->items[i].data); 23 24 } else if (meta->items[i].datatype == TRACE_META_UINT32) { 24 printf(" %s: % u\n",25 printf(" %s: %" PRIu32 "\n", 25 26 meta->items[i].option_name, 26 27 *(uint32_t *)meta->items[i].data); 27 28 } else if (meta->items[i].datatype == TRACE_META_UINT64) { 28 printf(" %s: % lu\n",29 printf(" %s: %" PRIu64 "\n", 29 30 meta->items[i].option_name, 30 31 *(uint64_t *)meta->items[i].data); … … 45 46 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 46 47 } else { 47 printf(" Unknown Option ID % u(output RAW): ", meta->items[i].option);48 printf(" Unknown Option ID %" PRIu16 " (output RAW): ", meta->items[i].option); 48 49 int k; 49 50 unsigned char *curr = (unsigned char *)meta->items[i].data; -
libpacketdump/link_23.c
r0486a72 r4e5a51f 9 9 #include <stdlib.h> 10 10 #include <string.h> 11 12 #define INET4_ADDRSTRLEN 16 13 #define INET6_ADDRSTRLEN 46 11 #include <netinet/in.h> 12 #include <inttypes.h> 14 13 15 14 DLLEXPORT void decode(int link_type UNUSED,const char *packet UNUSED,unsigned len UNUSED) { … … 81 80 break; 82 81 case(PCAPNG_META_IF_SPEED): 83 printf(" if_speed: % lu\n",82 printf(" if_speed: %" PRIu64 "\n", 84 83 *(uint64_t *)r->items[i].data); 85 84 break; 86 85 case(PCAPNG_META_IF_TSRESOL): 87 printf(" if_tsresol: % u\n",86 printf(" if_tsresol: %" PRIu8 "\n", 88 87 *(uint8_t *)r->items[i].data); 89 88 break; … … 92 91 break; 93 92 case(PCAPNG_META_IF_FILTER): 94 printf(" if_filter: % u",93 printf(" if_filter: %" PRIu8 "", 95 94 *(uint8_t *)r->items[i].data); 96 95 printf(" %s\n", … … 102 101 break; 103 102 case(PCAPNG_META_IF_FCSLEN): 104 printf(" if_fcslen: % u\n",103 printf(" if_fcslen: %" PRIu8 "\n", 105 104 *(uint8_t *)r->items[i].data); 106 105 break; 107 106 case(PCAPNG_META_IF_TSOFFSET): 108 printf(" if_tsoffset: % lu\n",107 printf(" if_tsoffset: %" PRIu64 "\n", 109 108 *(uint64_t *)r->items[i].data); 110 109 break; … … 166 165 case(PCAPNG_META_ISB_STARTTIME): 167 166 /* Need to split into 4 octets */ 168 printf(" isb_starttime: % lu\n",167 printf(" isb_starttime: %" PRIu64 "\n", 169 168 *(uint64_t *)r->items[i].data); 170 169 break; 171 170 case(PCAPNG_META_ISB_ENDTIME): 172 printf(" isb_endtime: % lu\n",171 printf(" isb_endtime: %" PRIu64 "\n", 173 172 *(uint64_t *)r->items[i].data); 174 173 break; 175 174 case(PCAPNG_META_ISB_IFRECV): 176 printf(" isb_ifrecv: % lu\n",175 printf(" isb_ifrecv: %" PRIu64 "\n", 177 176 *(uint64_t *)r->items[i].data); 178 177 break; 179 178 case(PCAPNG_META_ISB_IFDROP): 180 printf(" isb_ifdrop: % lu\n",179 printf(" isb_ifdrop: %" PRIu64 "\n", 181 180 *(uint64_t *)r->items[i].data); 182 181 break; 183 182 case(PCAPNG_META_ISB_FILTERACCEPT): 184 printf(" isb_filteraccept: % lu\n",183 printf(" isb_filteraccept: %" PRIu64 "\n", 185 184 *(uint64_t *)r->items[i].data); 186 185 break; 187 186 case(PCAPNG_META_ISB_OSDROP): 188 printf(" isb_osdrop: % lu\n",187 printf(" isb_osdrop: %" PRIu64 "\n", 189 188 *(uint64_t *)r->items[i].data); 190 189 break; 191 190 case(PCAPNG_META_ISB_USRDELIV): 192 printf(" isb_usrdeliv: % lu\n",191 printf(" isb_usrdeliv: %" PRIu64 "\n", 193 192 *(uint64_t *)r->items[i].data); 194 193 break; … … 207 206 /* print the custom data */ 208 207 for (i=0; i<r->num; i++) { 209 printf(" Private Enterprise Number (PEN): % u\n",208 printf(" Private Enterprise Number (PEN): %" PRIu32 "\n", 210 209 *(uint32_t *)r->items[i].data); 211 210 printf(" Data: ");
Note: See TracChangeset
for help on using the changeset viewer.