Make arrays of 4 octets arrays of 4 guint8.
[metze/wireshark/wip.git] / ui / tap_export_pdu.c
index a151e725671a1bf705b491b514fcad8233d12315..c15c20abe45171df983199c778a9f21d8c534f93 100644 (file)
@@ -5,28 +5,14 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
 
-
-#include "globals.h"
 #include "wiretap/pcap-encap.h"
 #include "wsutil/os_version_info.h"
-#include "ws_version_info.h"
+#include "version_info.h"
 
 #include <epan/tap.h>
 #include <epan/exported_pdu.h>
@@ -43,13 +29,13 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
 {
     const exp_pdu_data_t *exp_pdu_data = (const exp_pdu_data_t *)data;
     exp_pdu_t  *exp_pdu_tap_data = (exp_pdu_t *)tapdata;
-    struct wtap_pkthdr pkthdr;
+    wtap_rec rec;
     int err;
     gchar *err_info;
     int buffer_len;
     guint8 *packet_buf;
 
-    memset(&pkthdr, 0, sizeof(struct wtap_pkthdr));
+    memset(&rec, 0, sizeof rec);
     buffer_len = exp_pdu_data->tvb_captured_length + exp_pdu_data->tlv_buffer_len;
     packet_buf = (guint8 *)g_malloc(buffer_len);
 
@@ -60,24 +46,25 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
     if(exp_pdu_data->tvb_captured_length > 0){
         tvb_memcpy(exp_pdu_data->pdu_tvb, packet_buf+exp_pdu_data->tlv_buffer_len, 0, exp_pdu_data->tvb_captured_length);
     }
-    pkthdr.rec_type  = REC_TYPE_PACKET;
-    pkthdr.ts.secs   = pinfo->abs_ts.secs;
-    pkthdr.ts.nsecs  = pinfo->abs_ts.nsecs;
-    pkthdr.caplen    = buffer_len;
-    pkthdr.len       = exp_pdu_data->tvb_reported_length + exp_pdu_data->tlv_buffer_len;
-
-    pkthdr.pkt_encap = exp_pdu_tap_data->pkt_encap;
-
-    if (pinfo->fd->flags.has_user_comment)
-        pkthdr.opt_comment = g_strdup(epan_get_user_comment(edt->session, pinfo->fd));
-    else if (pinfo->fd->flags.has_phdr_comment)
-        pkthdr.opt_comment = g_strdup(pinfo->phdr->opt_comment);
-
-    pkthdr.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS;
+    rec.rec_type                           = REC_TYPE_PACKET;
+    rec.presence_flags                     = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS;
+    rec.ts.secs                            = pinfo->abs_ts.secs;
+    rec.ts.nsecs                           = pinfo->abs_ts.nsecs;
+    rec.rec_header.packet_header.caplen    = buffer_len;
+    rec.rec_header.packet_header.len       = exp_pdu_data->tvb_reported_length + exp_pdu_data->tlv_buffer_len;
+
+    rec.rec_header.packet_header.pkt_encap = exp_pdu_tap_data->pkt_encap;
+
+    if (pinfo->fd->flags.has_user_comment) {
+        rec.opt_comment = g_strdup(epan_get_user_comment(edt->session, pinfo->fd));
+        rec.has_comment_changed = TRUE;
+    } else if (pinfo->fd->flags.has_phdr_comment) {
+        rec.opt_comment = g_strdup(pinfo->rec->opt_comment);
+    }
 
-    /* XXX: should the pkthdr.pseudo_header be set to the pinfo's pseudo-header? */
+    /* XXX: should the rec.rec_header.packet_header.pseudo_header be set to the pinfo's pseudo-header? */
     /* XXX: report errors! */
-    if (!wtap_dump(exp_pdu_tap_data->wdh, &pkthdr, packet_buf, &err, &err_info)) {
+    if (!wtap_dump(exp_pdu_tap_data->wdh, &rec, packet_buf, &err, &err_info)) {
         switch (err) {
 
         case WTAP_ERR_UNWRITABLE_REC_DATA:
@@ -90,7 +77,7 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
     }
 
     g_free(packet_buf);
-    g_free(pkthdr.opt_comment);
+    g_free(rec.opt_comment);
 
     return FALSE; /* Do not redraw */
 }
@@ -102,22 +89,23 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
     int   err;
 
     /* pcapng defs */
-    wtap_optionblock_t           shb_hdr;
-    GArray                      *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+    wtap_block_t                 shb_hdr;
+    GArray                      *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
     wtapng_iface_descriptions_t *idb_inf;
-    wtap_optionblock_t           int_data;
+    wtap_block_t                 int_data;
     wtapng_if_descr_mandatory_t *int_data_mand;
     GString                     *os_info_str;
     gsize                        opt_len;
+    gchar                       *opt_str;
 
     /* Create data for SHB  */
     os_info_str = g_string_new("");
     get_os_version_info(os_info_str);
 
-    shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION);
+    shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
 
     /* options */
-    wtap_optionblock_set_option_string(shb_hdr, OPT_COMMENT, comment, strlen(comment));
+    wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
     g_free(comment);
 
     /*
@@ -125,34 +113,37 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
      * this section.
      */
     opt_len = os_info_str->len;
-    wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len);
+    opt_str = g_string_free(os_info_str, FALSE);
+    if (opt_str) {
+        wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
+        g_free(opt_str);
+    }
     /*
      * UTF-8 string containing the name of the application used to create
      * this section.
      */
-    wtap_optionblock_set_option_string_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
+    wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
 
     /* Create fake IDB info */
     idb_inf = g_new(wtapng_iface_descriptions_t,1);
-    idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
+    idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
 
     /* create the fake interface data */
-    int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
-    int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data);
+    int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
+    int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
     int_data_mand->wtap_encap      = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
     int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
-    int_data_mand->link_type       = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
-    int_data_mand->snap_len        = WTAP_MAX_PACKET_SIZE;
+    int_data_mand->snap_len        = WTAP_MAX_PACKET_SIZE_STANDARD;
 
-    wtap_optionblock_set_option_string(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
-    wtap_optionblock_set_option_uint8(int_data, OPT_IDB_TSRESOL, 9);
+    wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
+    wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9);
 
     g_array_append_val(idb_inf->interface_data, int_data);
 
     g_array_append_val(shb_hdrs, shb_hdr);
 
     /* Use a random name for the temporary import buffer */
-    exp_pdu_tap_data->wdh = wtap_dump_fdopen_ng(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE, FALSE,
+    exp_pdu_tap_data->wdh = wtap_dump_fdopen_ng(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE,
         shb_hdrs, idb_inf, NULL, &err);
     if (exp_pdu_tap_data->wdh == NULL) {
         g_assert(err != 0);