diff options
author | John Thacker <johnthacker@gmail.com> | 2021-12-26 09:58:56 -0500 |
---|---|---|
committer | John Thacker <johnthacker@gmail.com> | 2021-12-26 14:07:37 -0500 |
commit | 0dfc6414e0e3f153392fe31159f54bcb7c704545 (patch) | |
tree | 72a9834e27f1345258a22970a7caa7a30eec4413 /text2pcap.c | |
parent | a3df9fe13f3446f2f4bc50f38ec34b7a3622828f (diff) |
text2pcap: Add Export PDU
Support Export PDU functionality from text2pcap. Related to #16724.
Diffstat (limited to 'text2pcap.c')
-rw-r--r-- | text2pcap.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/text2pcap.c b/text2pcap.c index 4f8bbd32ec..f374ef9c5c 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -147,6 +147,9 @@ static guint16 hdr_data_chunk_sid = 0; static guint16 hdr_data_chunk_ssn = 0; static guint32 hdr_data_chunk_ppid = 0; +/* Export PDU */ +static gboolean hdr_export_pdu = FALSE; + /* ASCII text dump identification */ static gboolean identify_ascii = FALSE; @@ -319,6 +322,11 @@ print_usage (FILE *output) " chunk header with payload protocol identifier ppi.\n" " Example: -S 30,40,34\n" "\n" + " -P <dissector> prepend EXPORTED_PDU header with specifieddissector\n" + " as the payload PROTO_NAME tag.\n" + " Automatically sets link type to Upper PDU Export.\n" + " EXPORTED_PDU payload defaults to \"data\" otherwise.\n" + "\n" "Miscellaneous:\n" " -h display this help and exit.\n" " -v print version information and exit.\n" @@ -369,11 +377,13 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump char* err_info; info->hexdump.offset_type = OFFSET_HEX; + info->payload = "data"; + /* Initialize the version information. */ ws_init_version_info("Text2pcap (Wireshark)", NULL, NULL, NULL); /* Scan CLI parameters */ - while ((c = ws_getopt_long(argc, argv, "aDdhqe:i:l:m:nN:o:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) { + while ((c = ws_getopt_long(argc, argv, "aDdhqe:i:l:m:nN:o:u:P:s:S:t:T:v4:6:", long_options, NULL)) != -1) { switch (c) { case 'h': show_help_header("Generate a capture file from an ASCII hexdump of packets."); @@ -421,6 +431,12 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump break; } + case 'P': + hdr_export_pdu = TRUE; + pcap_link_type = 252; + info->payload = ws_optarg; + break; + case 's': hdr_sctp = TRUE; hdr_data_chunk = FALSE; @@ -656,6 +672,11 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump return INVALID_OPTION; } + if (pcap_link_type != 252 && hdr_export_pdu) { + cmdarg_err("Export PDU (-P) requires WIRESHARK_UPPER_PDU link type (252)"); + return INVALID_OPTION; + } + if (have_hdr_ip_proto && !(hdr_ip || hdr_ipv6)) { /* * If we have an IP protocol to add to the header, but neither an @@ -744,7 +765,9 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump info->encapsulation = wtap_encap_type; info->wdh = wdh; - if (hdr_data_chunk) { + if (hdr_export_pdu) { + info->dummy_header_type = HEADER_EXPORT_PDU; + } else if (hdr_data_chunk) { info->dummy_header_type = HEADER_SCTP_DATA; } else if (hdr_sctp) { info->dummy_header_type = HEADER_SCTP; @@ -781,10 +804,6 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump info->tag = hdr_sctp_tag; info->ppi = hdr_data_chunk_ppid; -#if 0 - info->payload = /* XXX Export PDU not supported by text2pcap yet */ -#endif - info->max_frame_length = max_offset; info->identify_ascii = identify_ascii; |